0

我正在 python 3.3 上制作基于文本的游戏。这是我的代码的开始:

while True:

  print ("You must answer all questions in block capitals")
  print ("Welcome to maze runner")
  print ("To learn about the controls press C")
  print ("To learn the about the different types T")
  print ("To play press START")
  run = input ()
  #Controls
  if run == "C":
     print ("To attack press H")
     print ("To walk forward press W")
     print ("To turn left press A")
     print ("To turn right press D")
     print ("To turn around press S")
     print ("To block press B")
     print ("To open stats press Q")
     print ("To open this screen press C")
     print ("To close this screen press C")
  #Types
  if run == "T":
    print ("Soldier. Press S for more info")
    print ("Archer. Press A for more info")
    print ("Mage. Press M for more info")
    print ("Changeling. Press C for more info")
    print ("Rouge. Press R for more info")
    print ("Press M to go to main menu")
    type_info = input()
    if type_info == "M":
       break
    #Solider info
    if type_info == "S":
       print ("Soldier: Good at close combat")
       print ("         Weak at long range combat")
       print ("         Average speed")
       print ("         Average blocker")
       print ("Press M to go to main menu")
       return_to_menu = input()
       if return_to_menu == "M":
          break      
    #Archer info
    if type_info == "A":
       print ("Archer: Weak at close combat")
       print ("        Good at long range combat")
       print ("        Good speed")
       print ("        Average blocker")
       print ("Press M to go to main menu")
    #Mage info
    if type_info == "M":
       print ("Mage: Weak at close combat")
 print ("      Good at long range combat")
       print ("      Average speed")
 print ("      Good blocker")
       print ("Press M to go to main menu")
    #Changeling info
    if type_info == "C":
       print ("Changling: Average at close combat")
       print ("           Average at long range combat")
       print ("           Average speed")
       print ("           Average blocker")
       print ("Press M to go to main menu")
    #Rouge info
    if type_info == "R":
       print ("Rouge:  Average at close combat")
       print ("        Average at long range combat")
       print ("        Good speed")
       print ("        Good blocker")
       print ("Press M to go to main menu")

我将下面的代码添加到一些代码中。知道当我运行它时,我收到一个错误,说不经常使用制表符空间并突出显示行尾说:

  print ("Mage: Weak at close combat")

为什么行后没有空格

4

3 回答 3

2

当我运行它时,我得到:

...        print ("Mage: Weak at close combat")
...  print ("      Good at long range combat")
  File "<stdin>", line 51
    print ("      Good at long range combat")
                                            ^
IndentationError: unindent does not match any outer indentation level

检查“擅长远程战斗”行 - 它似乎有一个制表符而不是空格。

于 2013-10-12T13:37:25.983 回答
1

您可以将上述所有代码放在一个while True:循环中,break当您不想返回主菜单时,可以将其置于循环之外。

while True:
    # your code here
    return_to_menu = input()
    if return_to_menu != 'M':
        break

在旁注中,我可能会使用else ifs. 它们要快一点,因为当其中一个条件匹配时,不会评估if...else if块中的其他条件。

于 2013-10-12T10:06:59.870 回答
0
print ("Soldier. Press S for more info")
print ("Archer. Press A for more info")
print ("Mage. Press M for more info")
print ("Changeling. Press C for more info")
print ("Rouge. Press R for more info")
print ("Press M to go to main menu")

所以 M 既代表 Mage 又代表 Menu。哎呀。

于 2015-06-08T10:23:47.513 回答