热度 1 已有 122 次阅读 2017-4-10 21:56 个人分类:Python的天空 系统分类:其他 python
PS: 欢迎感兴趣想交流的家长和小朋友加入我们的微信群
After we finished version 0.3, I really like to play it, but when I have met a ghost and I want to play again I have to click run again, I am to lazy to click run again, so my dad said we should make it better by asking the player if you want to play again or not, if the player said yes, then it will start over, and if no then the game is over.
First I thought about letting the player type things to the computer, so I used this line of code:
play = input('Do you want to play again? y/n')
When we got the answer from the player and it is n for not, then we are going to make game over true to end the game. But if the player said yes then it will be much harder. After we made some changes we end up with these:
game_over = False
while not game_over:
while feeling_brave:
...
expected_input = False
while expected_input == False:
play = input('Do you want to play again? y/n')
if play == 'n' or play == 'no':
game_over = True
expected_input = True
print('Bye!')
break
if play == 'y' or play =='yes':
feeling_brave = True
score = 0
expected_input = True
else:
print('please enter yes or no.')
expected_input = False
Here are some problems we need to change:
When the player said no, we forgot to change game_over to True, and that makes the game still going.
Also when the player said no, we forgot to use the code word "break". If we didn't use that, it will run until line 19 and which makes the expected input false, and that makes it goes back to line 7 and it will ask the player "do you want to play again?" once more. You actually can use the coding word "elif" instead of "break", which means "else if".
When the player said yes, we didn't reset their score to 0, and that will make the player's score become more and more and more until they end this.
Here is the link to the whole version 0.4
https://repl.it/GLu4/2