python - return to base class -
i have code in base module:
class start_game(object): def __init__(self): print "you landed on planet , see 3 rooms." print "you need choose 1 room enter" self.door=raw_input("pick number of door (1,2 or 3)>>>") try: assert(int(self.door)>0 , 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()
this way want run basement module entering 3 number. basement module is:
from end import * class basement(object): def __init__(self): print"you enterd dark room , makes noise" def play(self): choice=raw_input("do want continue?y/n") if choice=='y': end().play() else: start_game()???
my question how can return start_game class , start game fron beggining?
i may misunderstanding, perhaps need add following base module:
if __name__ == '__main__': start_game()
and run base module python: python my_module.py
the if __name__ == '__main__':
true when running module. when true creates game.
although, others have said, way using classes unusual.
Comments
Post a Comment