class - python multiple instantiation and passing values -
class - python multiple instantiation and passing values -
newbie question. can help me understand happening below?
this larn python hard way ex43 - http://learnpythonthehardway.org/book/ex43.html
how class engine know first 'scene' in list class map? hand off occur?
i unsure on how the engine , map class communicate. see instantiated @ bottom, possible have instantiated object (a_map) have object instantiated 1 time again (by a_game)?
example:
a_map = map('1') a_game = engine(a_map)
here total code.
class engine(object): def __init__(self, scene_map): self.scene_map = scene_map def play(self): current_scene = self.scene_map.opening_scene() last_scene = self.scene_map.next_scene('2') while current_scene != last_scene: next_scene_name = current_scene.enter() current_scene = self.scene_map.next_scene(next_scene_name) class fristlevel(object): def enter(self): pass class secondlevel(object): def enter(self): pass class map(object): scenes = {'1' : fristlevel(), '2' : secondlevel()} def __init__(self, start_scene): self.start_scene = start_scene def next_scene(self, scene_name): pass def opening_scene(self): pass a_map = map('1') a_game = engine(a_map) a_game.play()
i'm not sure question is, i'll seek break downwards code little. . .
a_map = map('1')
this creates new instance of map
, stores in name a_map
.
a_game = engine(a_map)
this creates new instance of engine
, stores in name a_game
. note input argument a_map
. in case, map
instance gets passed engine.__init__
, stored scene_map
attribute. in illustration above, if write:
a_game.scene_map a_map
the result true
because both names same map
instance.
python class instantiation
Comments
Post a Comment