X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=gameobjects.py;fp=gameobjects.py;h=e64dc91c374d437ffb7ad1259621ea89990be83d;hp=6cb93f087dd54045393acc971a5e04e5e0067ee2;hb=f4b468331db23412a3d8195e8ca2650093411697;hpb=4b6e952b476861c8979dc395781964099285a4c6 diff --git a/gameobjects.py b/gameobjects.py index 6cb93f0..e64dc91 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -38,7 +38,38 @@ class HealthPotion (GameObject): # using the potion def use (self, butaba): - pass + butaba.health += 25 + if butaba.health > butaba.MAXHEALTH: + butaba.health = butaba.MAXHEALTH + +class Chest (GameObject): + def __init__ (self, row, col, text, image, key_id, locked = False, items = []): + self.key_id = key_id + self.locked = locked + self.items = items + GameObject.__init__ (self, row, col, text, image, False) + + # no interaction with this object. Also solid so return False + def interact (self): + # object is solid + return False + + # try to use the key passed to it + def use (self, key): + # if chest is locked try to unlock it + if self.locked is True: + # if the item is a key + if isinstance (key, Key): + # if the key fits the lock + # unlock the chest + if key.key_id == self.key_id: + self.locked = False + # return the key + return key + # return None if not a key or key did not fit + return None + else: + return self.locked class Key (GameObject): def __init__ (self, row, col, text, image, key_id): @@ -50,11 +81,7 @@ class Key (GameObject): # key is not a solid object so return True return True - # using the key + # using the key - this is relegated to the locked item for + # convenience, so key does nothing by defaults def use (self, lockitem): - if type (lockitem) == Chest or type (lockitem) == Door: - if self.key_id == lockitem.key_id: - if lockitem.unlocked is False: - lockitem.unlocked = True - else: - lockitem.unlocked = True + pass