现在我的游戏工作正常,但我仍想继续。我想要一个积分评分系统。我希望玩家如果他们赢了1次还剩1次,如果他们有2次则剩10次,如果他们拥有全部3次,那么他们将得到5分。但是我不希望如果他们再次玩,分数就会被重置。我只是想要它说当你退出游戏时你已经取得了分数。我试图以许多不同的方式做到这一点,但我似乎可以得到它的工作,它重新设置每次再次播放乐谱的分数。我在下面列出了我的基本游戏代码,请尝试和帮助。任何其他本游戏的推荐都非常受欢迎。将评分系统添加到猜谜游戏中,包括再次玩游戏
**我的歉意我不知道我之前是否清楚这一点。我不想被存储在得分后的节目就关上,直到当被问及再次播放**
#imports required modules
import random
#correct number variable created
num = 0
#generates number at random
comp_num = random.randint(1,10)
print('I\'m thinking of a number guess what it is...\n')
#main game code
def main():
#generates number at random
comp_num = random.randint(1,10)
#set num as a global variable
global num
#lives created
lives = 3
while lives >= 1:
#player guesses
guess = int(input('Guess: '))
if comp_num == guess:
#if correct says well done
print('\nWell Done! You guessed Correctly!\n')
break
elif comp_num >= guess:
#if guess is too low tells player
#one live taken for incorrect guess
lives = lives -1
print('\nToo low!\n')
#player is told how many lives they have left
print('You guessed incorrectly. You have',lives,'live(s) remaining.\n')
if lives == 0:
#if player guesses incorrectly they get told the correct awnser
print('The number I was thinking of was...',comp_num,'!\n')
elif comp_num <= guess:
#if guess is too high tells player
#one live taken for incorrect guess
lives = lives -1
print('\nToo high!\n')
#player is told how many lives they have left
print('You guessed incorrectly. You have',lives,'live(s) remaining.\n')
if lives == 0:
#if player guesses incorrectly they get told the correct awnser
print('The number I was thinking of was...',comp_num,'!\n')
def end():
#asks player if they want to play again
play_again = input('Would you like to play again?[Y/N] ')
while play_again.lower() == 'y':
#if they do game resets and plays again
if play_again.lower() == 'y':
comp_num = random.randint(1,10)
print('\nI\'m thinking of a number guess what it is...\n')
main()
play_again = input('Would you like to play again?[Y/N] ')
if play_again.lower() == 'n':
break
if play_again.lower() == 'n':
#if they don't game ends
input('Ok, Press enter to exit')
exit()
#calls main section of game
main()
#calls end of game to give option of playing again and reseting game
end()
我建议点存储在一个文件,读取和写入比分到文件,每当你进入和退出程序。 – Ehsan 2014-11-22 10:28:28