Mercurial > pyntnclick
changeset 67:6b0f7364f3bf
Inventory-related game state.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 23 Aug 2010 20:18:29 +0200 |
parents | 05346a412b55 |
children | 158a13a48d48 |
files | gamelib/scenes/cryo.py gamelib/tests/game_logic_utils.py gamelib/tests/test_scene_interactions_cryo.py |
diffstat | 3 files changed, 38 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/scenes/cryo.py Mon Aug 23 19:50:45 2010 +0200 +++ b/gamelib/scenes/cryo.py Mon Aug 23 20:18:29 2010 +0200 @@ -35,7 +35,22 @@ class CryoUnitAlpha(Thing): - pass + "Cryo unit containing titanium leg." + + FOLDER = "cryo" + IMAGE = "cryo_unit_alpha" + + INITIAL_DATA = { + 'contains_titanium_leg': True, + } + + def interact_without(self): + self.message("The corpse in this cryo unit has a prosthetic leg made out of titanium. You take it.") + self.state.add_inventory_item('titanium_leg') + self.set_data('contains_titanium_leg', False) + + def is_interactive(self): + return self.get_data('contains_titanium_leg') class CryoRoomDoor(Thing): @@ -68,6 +83,7 @@ def open_door(self): self.set_data('open', True) self.state.scenes['bridge'].set_data('accessible', True) + self.state.remove_inventory_item('titanium_leg') def get_description(self): if self.get_data('open'):
--- a/gamelib/tests/game_logic_utils.py Mon Aug 23 19:50:45 2010 +0200 +++ b/gamelib/tests/game_logic_utils.py Mon Aug 23 20:18:29 2010 +0200 @@ -36,8 +36,11 @@ gizmo = gizmo.things[thing] self.assertEquals(value, gizmo.get_data(key)) - def interact_thing(self, thing_name, item_name=None): - item = None - if item_name is not None: - item = self.state.items[item_name] - self.state.scenes[self.CURRENT_SCENE].things[thing_name].interact(item) + def assert_inventory_item(self, item, in_inventory=True): + self.assertEquals(in_inventory, self.state.items[item] in self.state.inventory) + + def interact_thing(self, thing, item=None): + item_obj = None + if item is not None: + item_obj = self.state.items[item] + self.state.scenes[self.CURRENT_SCENE].things[thing].interact(item_obj)
--- a/gamelib/tests/test_scene_interactions_cryo.py Mon Aug 23 19:50:45 2010 +0200 +++ b/gamelib/tests/test_scene_interactions_cryo.py Mon Aug 23 20:18:29 2010 +0200 @@ -21,6 +21,7 @@ def test_cryo_door_closed_titanium_leg(self): "The door is closed and we touch it with the titanium leg. It opens." + self.state.add_inventory_item('titanium_leg') self.assert_game_data('accessible', True) self.assert_game_data('accessible', False, scene='bridge') self.assert_game_data('open', False, 'cryo.door') @@ -30,6 +31,7 @@ self.assert_game_data('accessible', True) self.assert_game_data('accessible', True, scene='bridge') self.assert_game_data('open', True, 'cryo.door') + self.assert_inventory_item('titanium_leg', False) def test_cryo_door_open_hand(self): "The door is open and we touch it with the hand. No change." @@ -54,3 +56,14 @@ self.assert_game_data('accessible', True) self.assert_game_data('accessible', True, scene='bridge') self.assert_game_data('open', True, 'cryo.door') + + def test_cryo_unit_alpha_full_hand(self): + "The cryo unit has the leg in it and we touch it. We get the leg." + + self.assert_game_data('contains_titanium_leg', True, 'cryo.unit.1') + self.assert_inventory_item('titanium_leg', False) + + self.interact_thing('cryo.unit.1') + + self.assert_game_data('contains_titanium_leg', False, 'cryo.unit.1') + self.assert_inventory_item('titanium_leg', True)