【问题标题】:Creating a game in python [closed]用python创建游戏[关闭]
【发布时间】:2012-11-05 00:44:12
【问题描述】:

我想知道如何在游戏中创建一个while循环,在玩家玩过一次游戏后,用户会询问他们是否想再玩一次。如果用户输入yes,游戏会重新开始,但如果他们说不,那么游戏就结束了。

我想要一些例子,如果你可以使用 while true boolean 方法来解释,因为我很难理解。

【问题讨论】:

  • 恐怕 SO 不是为您编写代码的网站。尝试一下,遇到问题的地方再问。

标签: python python-2.7 python-3.x while-loop


【解决方案1】:

似乎您最大的问题是如何使用while 循环并在循环内接受输入。

看看While Loops in Python。将提供有关其工作原理的基本见解。

要解决您的问题,请分析以下代码。这应该可以让你开始。

print "Type 3 to continue, anything else to quit."
someInput = raw_input()

while someInput == '3':
    print "Thank you for the 3. Very kind of you."
    print "Type 3 to continue, anything else to quit."
    someInput = raw_input()

print "That's not 3, so I'm quitting now."

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    看这个课程An Introduction to Interactive Programming in Python:

    如果我参加这门课,我会学到什么最酷的东西?

    您将能够使用 Python 构建自己的游戏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-29
      • 2011-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2012-11-10
      • 1970-01-01
      相关资源
      最近更新 更多