我正在学习python(2.7),正在制作一个简单的文本迷宫游戏,在不同的文件上有多个级别:
try: #this one works perfectly, it runs the file until it quits with quit()
execfile("....Lockdown.py")
except SystemExit:
print "Next Level"
try: #this one doesn't work even though it is almost perfectly identical with Lockdown
execfile("....Lockdown2.py")
except SystemExit:
print "Next Level"
#other levels
当它运行Lockdown2.py时
Traceback (most recent call last):
File LockdownGame.py ...
#-> until execfile("....Lockdown2.py")
File "...Lockdown2.py", line 708, in available #available is another function
decide(raw_input("Where do you decide to head? "))
ValueError: I/O operation on closed file
Lockdown2(和Lockdown)是这样工作的
#the building of the maze
def available(): #checks where the user can walk
#looks through the entire maze to look at where the user is standing, where his back is and if there are walls in that direction
#makes sure the user isn't facing
print "You can walk %s." % (can_walk[0]) #cutting out how it tells this
decide(raw_input("What direction do you decide to head? "))
def decide(dec):
if dec == "left": #and the other three directions,
#edits the maze and their surrounding to their new location
else:
print "(Write your option as it's written)"
decide(raw_input("What direction do you decide to head? "))
available()
它在放置raw_input
之后崩溃,即使它实际上是与locdown相同的代码,并且在此之前的打印中,或者当这个原始输入处于locdown时,它不会出错。你知道吗
将quit()改为系统出口(),它将在启动锁定2之前完全关闭锁定
相关问题 更多 >
编程相关推荐