1
我正在使用Python进行文本冒险。我对面向对象编程的概念(以及一般编程)很陌生,所以我不完全确定哪里出了问题。那么,到目前为止我所做的是两种方法;一个处理用户输入的内容,一个指示游戏中会发生什么,使用其他方法来定义我将来创建的房间。但我有一个问题,就是我无法运行它来测试程序!当我运行它时,没有提示用户输入 - 程序刚结束而没有返回任何错误。没有太多的代码,所以也许你可以帮助我确定问题!我敢肯定在那里我真的很明显忘记了...Python问题中的文本冒险
class Main(object):
def handle_events(self, userinput, cmd):
self.userinput = userinput
self.cmd = cmd
userinput = raw_input('> ')
cmd = {'use' : use,'quit' : quit, 'help' : help}
if userinput[0] not in cmd:
print "Invalid command. Check [help] for assistance."
def main(self, handle_events):
print '''You are in a dark room filled with
strange and ominous objects.
After some feeling around, you think
you can make out a light switch.'''
self.userinput
if userinput[1] == 'switch':
print "You flicked the switch!"
Main().main
您可能需要阅读[Python教程](http://docs.python.org/2/tutorial/)。 – chepner 2013-05-09 03:51:03