01 猜單詞遊戲

1、本人設計源碼

import random
words = ['hello', 'candy', 'fill' , 'out', 'need', 'tell', 'myself' 'that', 'old']
lens = len(words)

score = 100
bad = 10
good = 20
print("""
    歡迎來到猜單詞遊戲!
    規則:您的初始積分爲100,打錯扣10分,答對加20分。
""")
iscontinue = True
while iscontinue:
    print('您的積分爲 %d, 請猜單詞:' % score)
    a = random.choice(words)
    w = list(a)
    while a ==  ''.join(w):
        random.shuffle(w)
    print(''.join(w))
    ok = True
    while ok:
        spec = input('請輸入您猜測的單詞:\n')
        if spec == a:
            score += good
            s = input('恭喜你猜對了!您的積分爲 %d, 是否要繼續呢?(Y/N)\n' % score)
            if s in list('Yy'):
                ok = False
                iscontinue = True
            else:
                ok = False
                iscontinue = False
        else:
            if score - bad:
                score -= bad
                print('Sorry, 您猜錯了哦! 您的積分爲 %d.' % score)
                ok = True
            else:
                print('抱歉您的積分已不足,系統自動退出遊戲!該單詞爲:%s.' % a)
                ok = iscontinue = False
                break
print('拜拜哦,歡迎下次再來哦!!您最終的積分是 %d.' % score)
    
    

歡迎來到猜單詞遊戲!
規則:您的初始積分爲100,打錯扣10分,答對加20分。

您的積分爲 100, 請猜單詞:
lod
請輸入您猜測的單詞:
dol
Sorry, 您猜錯了哦! 您的積分爲 90.
請輸入您猜測的單詞:
old
恭喜你猜對了!您的積分爲 110, 是否要繼續呢?(Y/N)
y
您的積分爲 110, 請猜單詞:
flil
請輸入您猜測的單詞:
fill
恭喜你猜對了!您的積分爲 130, 是否要繼續呢?(Y/N)
N
拜拜哦,歡迎下次再來哦!!您最終的積分是 130.

2、改進:

1、登錄界面,創建密碼賬戶到數據庫

2、增加更多輸入錯誤提示

3、分離生成單詞模塊、判斷模塊

4、選擇不同等級進行遊戲

5、玩家可以充錢

6、玩家可以相互對戰

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章