Mercurial > pyntnclick
changeset 191:278774b31d3c
CloneableItems.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Wed, 25 Aug 2010 21:32:38 +0200 |
parents | 30f2308c1efc |
children | b1f4262139e7 |
files | gamelib/scenes/mess.py gamelib/state.py |
diffstat | 2 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/scenes/mess.py Wed Aug 25 20:09:19 2010 +0200 +++ b/gamelib/scenes/mess.py Wed Aug 25 21:32:38 2010 +0200 @@ -2,7 +2,7 @@ from random import choice -from gamelib.state import Scene, Item, Thing, InteractImage, InteractNoImage, Result +from gamelib.state import Scene, Item, CloneableItem, Thing, InteractImage, InteractNoImage, Result from gamelib.cursor import CursorSprite @@ -26,31 +26,33 @@ self.add_thing(ToMap()) -class EmptyCan(Item): +class EmptyCan(CloneableItem): "After emptying the full can." INVENTORY_IMAGE = "empty_can.png" CURSOR = CursorSprite('empty_can_cursor.png', 20, 30) -class FullCan(Item): + +class FullCan(CloneableItem): "Found on the shelf." INVENTORY_IMAGE = "full_can.png" CURSOR = CursorSprite('full_can_cursor.png', 20, 30) - def interact_with_titanium_leg(self, tool, state): + def interact_with_titanium_leg(self, item, state): dented = DentedCan("dented_can") + state.add_item(dented) state.replace_inventory_item(self, dented) return Result("You club the can with the femur. The can gets dented, but doesn't open.") -class DentedCan(FullCan): +class DentedCan(CloneableItem): "A can banged on with the femur" INVENTORY_IMAGE = "dented_can.png" CURSOR = CursorSprite('dented_can_cursor.png', 20, 30) - def interact_with_titanium_leg(self, tool, inventory): + def interact_with_titanium_leg(self, item, state): return Result("You club the can with the femur. The dents shift around, but it still doesn't open.") @@ -84,7 +86,9 @@ } def interact_without(self): - self.state.add_inventory_item('full_can') + can = FullCan("full_can") + self.state.add_item(can) + self.state.add_inventory_item(can.name) if not self.data['taken_one']: self.set_data('taken_one', True) return Result("Best before along time in the past. Better not eat these.")
--- a/gamelib/state.py Wed Aug 25 20:09:19 2010 +0200 +++ b/gamelib/state.py Wed Aug 25 21:32:38 2010 +0200 @@ -572,3 +572,11 @@ def interact_default(self, tool, state): return Result("That doesn't do anything useful") + +class CloneableItem(Item): + _counter = 0 + + def __init__(self, name): + my_count = CloneableItem._counter + CloneableItem._counter += 1 + super(CloneableItem, self).__init__("%s.%s" % (name, my_count))