我的基本模块中有代码:
class start_Game(object):
def __init__(self):
print "You landed on planet and see three rooms."
print "You need to choose one room to enter"
self.door=raw_input("Pick number of door (1,2 or 3)>>>")
try:
assert(int(self.door)>0 and int(self.door)<=3)
self.password=('%d%d%d')%(randint(1,9),randint(1,9),randint(1,9))
print self.password
self.ROOMs={'1':Medical_room,'2':Library,'3':basement,'4':End}
while True:
# break
room=self.ROOMs[self.door]
# print room()
if self.door=='1':
self.door=room().play(self.password)
else:
self.door=room().play()
这样我想运行地下室模块输入3号码。我的地下室模块是:
from End import *
class basement(object):
def __init__(self):
print"You enterd dark room and something makes noise"
def play(self):
choice=raw_input("Do you want to continue?y/n")
if choice=='y':
End().play()
else:
start_Game()???
我的问题是如何返回start_game类并从开始开始我的游戏?
答案 0 :(得分:0)
我可能会产生误解,但您可能只需要将以下内容添加到基本模块中:
if __name__ == '__main__':
start_Game()
然后使用python:python my_module.py
if __name__ == '__main__':
仅在运行模块时才为真。当它成立时它会创造游戏。
尽管正如其他人所说,你使用这些课程的方式并不常见。