Python代码行在我的游戏中不起作用

时间:2015-04-25 15:08:00

标签: python debugging command raw-input adventure

因此我的Python游戏中的这行代码无效:

direction=raw_input("What would you like to do?\n")

它应该让玩家输入命令:North,South,East,West,Look,Search,Commands或Inventory。它正在提出这个:

  

Traceback(最近一次调用最后一次):     文件“/ Users / khalilismail / Desktop / COMPUTING / Text-based Games / DragonQuest.py”,第173行,in       direction = raw_input(“你想做什么?\ n”)   EOFError:读取行时的EOF

请帮忙

以下是围绕此代码的堆栈: 而游戏==开启:

while place==town:

    direction=raw_input("What would you like to do?\n")

    if direction=="west":
        if "iron ore" and "wood" and "3 Gold Pieces" in items:
            print "The blacksmith greets you, and you tell him that you have the items and money he requires, you also give him the saw to make up for some of the difference, he then forges you a battleaxe and wishes you luck on the rest of your quest"
            items.remove ("saw")
            items.remove ("3 Gold Pieces")
            items.remove ("iron ore")
            items.remove ("wood")
            items.append ("battleaxe")

1 个答案:

答案 0 :(得分:0)

正如评论中所建议的,一些编辑不支持输入(包括Atom)。以下是您可以克服的一些选项:

  1. 通过在调试时对其进行硬编码来设置方向变量(不要忘记在调试后将其删除)
  2. 更改编辑器(请记住,Sublime也有同样的问题,但这有一个解决方法 - Sublime Text 2 console input;但是,在通过命令行运行代码时,Notepad ++没有此问题。)
  3. 您也可以尝试从raw_input字符串中删除换行符'\ n',以测试它是否有效。

相关问题