网站公告
点击问题反馈。微信登陆的用户请及时在个人中心设置登陆密码,并且牢记自己的用户名。
头像上传问题点击此处

Ghost Game v0.4 - Endless Game

热度 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:

  1.    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:  

  1. game_over = False

  2. while not game_over:

  3.  while feeling_brave:

  4.     ...

  5.  expected_input = False

  6.  while expected_input == False:

  7.    play = input('Do you want to play again? y/n')

  8.    if play == 'n' or play == 'no':

  9.      game_over = True

  10.      expected_input = True

  11.      print('Bye!')

  12.      break

  13.    if play == 'y' or play =='yes':

  14.      feeling_brave = True

  15.      score = 0

  16.      expected_input = True

  17.    else:

  18.      print('please enter yes or no.')

  19.      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


路过

鲜花

握手

雷人

facelist

您需要登录后才可以评论 登录 | 新会员加入

评论 (1 个评论) 发表评论

  • hidden ccn_82

    2017-4-10 23:43

    微信:414673243
    邀请你加入[color=Red]大V店[/color],买东西返佣金,卖东西能赚钱,让你轻松月入三五千
       回复