# HG changeset patch # User Jeremy Thurgood # Date 1282562870 -7200 # Node ID 2e2f6ff547801f88cf1bd89118a1ff0ce2641f32 # Parent 0abd45c58bd3e0c532b96a787dd386fd3188dde5 Part of the cryo door puzzle. diff -r 0abd45c58bd3 -r 2e2f6ff54780 gamelib/scenes/bridge.py --- a/gamelib/scenes/bridge.py Mon Aug 23 13:23:38 2010 +0200 +++ b/gamelib/scenes/bridge.py Mon Aug 23 13:27:50 2010 +0200 @@ -9,7 +9,7 @@ BACKGROUND = None # TODO INITIAL_DATA = { - 'accessible': True, + 'accessible': False, } diff -r 0abd45c58bd3 -r 2e2f6ff54780 gamelib/scenes/cryo.py --- a/gamelib/scenes/cryo.py Mon Aug 23 13:23:38 2010 +0200 +++ b/gamelib/scenes/cryo.py Mon Aug 23 13:27:50 2010 +0200 @@ -44,9 +44,19 @@ FOLDER = "cryo" IMAGE = "cryo_door_closed" + INITIAL_DATA = { + 'open': False, + } + + def interact(self, item): + if self.get_data('open'): + print "Door open" + return + Thing.interact(self, item) + def interact_with_titanium_leg(self, item): self.message("You wedge the titanium leg into the chain and twist. With a satisfying *snap*, the chain breaks and the door opens.") - self.scene.remove_thing(self) + self.open_door() def interact_without(self): self.message("It moves slightly and then stops. A chain on the other side is preventing it from opening completely.") @@ -58,5 +68,9 @@ "The door resists. Try something else, perhaps?", ])) + def open_door(self): + self.set_data('open', True) + self.state.scenes['bridge'].set_data('accessible', True) + SCENES = [Cryo] diff -r 0abd45c58bd3 -r 2e2f6ff54780 gamelib/scenes/engine.py --- a/gamelib/scenes/engine.py Mon Aug 23 13:23:38 2010 +0200 +++ b/gamelib/scenes/engine.py Mon Aug 23 13:27:50 2010 +0200 @@ -9,7 +9,7 @@ BACKGROUND = None # TODO INITIAL_DATA = { - 'accessible': True, + 'accessible': False, } diff -r 0abd45c58bd3 -r 2e2f6ff54780 gamelib/scenes/machine.py --- a/gamelib/scenes/machine.py Mon Aug 23 13:23:38 2010 +0200 +++ b/gamelib/scenes/machine.py Mon Aug 23 13:27:50 2010 +0200 @@ -9,7 +9,7 @@ BACKGROUND = None # TODO INITIAL_DATA = { - 'accessible': True, + 'accessible': False, } diff -r 0abd45c58bd3 -r 2e2f6ff54780 gamelib/scenes/mess.py --- a/gamelib/scenes/mess.py Mon Aug 23 13:23:38 2010 +0200 +++ b/gamelib/scenes/mess.py Mon Aug 23 13:27:50 2010 +0200 @@ -9,7 +9,7 @@ BACKGROUND = None # TODO INITIAL_DATA = { - 'accessible': True, + 'accessible': False, } diff -r 0abd45c58bd3 -r 2e2f6ff54780 gamelib/state.py --- a/gamelib/state.py Mon Aug 23 13:23:38 2010 +0200 +++ b/gamelib/state.py Mon Aug 23 13:27:50 2010 +0200 @@ -63,7 +63,24 @@ print msg -class Scene(object): +class StatefulGizmo(object): + + # initial data (optional, defaults to none) + INITIAL_DATA = None + + def __init__(self): + self.data = {} + if self.INITIAL_DATA: + self.data.update(self.INITIAL_DATA) + + def set_data(self, key, value): + self.data[key] = value + + def get_data(self, key): + return self.data.get(key, None) + + +class Scene(StatefulGizmo): """Base class for scenes.""" # sub-folder to look for resources in @@ -75,10 +92,8 @@ # name of scene (optional, defaults to folder) NAME = None - # initial scene data (optional, defaults to none) - INITIAL_DATA = None - def __init__(self, state): + StatefulGizmo.__init__(self) # scene name self.name = self.NAME if self.NAME is not None else self.FOLDER # link back to state object @@ -86,9 +101,6 @@ # map of thing names -> Thing objects self.things = {} self._background = get_image(self.FOLDER, self.BACKGROUND) - self.data = {} - if self.INITIAL_DATA: - self.data.update(self.INITIAL_DATA) def add_item(self, item): self.state.add_item(item) @@ -112,7 +124,7 @@ self.draw_things(surface) -class Thing(object): +class Thing(StatefulGizmo): """Base class for things in a scene that you can interact with.""" # sub-folder to look for resources in @@ -122,6 +134,7 @@ IMAGE = None def __init__(self, name, rect): + StatefulGizmo.__init__(self) self.name = name # area within scene that triggers calls to interact self.rect = rect