X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=gameobjects.py;h=bc73faded6907dd15119fab016bc8e3ccb577cb4;hp=2edbc5b1c86a11ddb16853c926b191013e35741c;hb=93544bdd97d65c88d0bc4b3f74f43f9689fb3918;hpb=4d50728c1454554fef2ad4841345d0c28101702d diff --git a/gameobjects.py b/gameobjects.py index 2edbc5b..bc73fad 100644 --- a/gameobjects.py +++ b/gameobjects.py @@ -22,6 +22,45 @@ class GameObject: def use (self, otherobject): pass +# class for well +class Well (GameObject): + def __init__ (self, row, col, image=None, liquid = "water"): + self.liquid = liquid + text = "Well" + GameObject.__init__ (self, row, col, text, image, False, "Draw %s" % liquid) + + def interact (self): + return False + + def use (self, otherobject): + # if the object is a bucket, fill it + if isinstance (otherobject, Bucket) is True: + # but only if it is empty + if otherobject.liquid is None: + otherobject.liquid = self.liquid + + +# class for buckets +class Bucket (GameObject): + def __init__ (self, row, col, image=None, liquid = None): + self.liquid = liquid + text = "Bucket" + if liquid is not None: + text = text + " containing %s" % liquid + GameObject.__init__ (self, row, col, text, image, True, "Empty it") + + def interact (self): + return True + + def use (self, otherobject): + # if the other object is a bucket, transfer its + # contents to the other bucket + if isinstance (otherobject, Bucket): + otherobject.liquid = self.liquid + # empty the bucket of its contents + self.liquid = None + self.text = "Bucket" + class GoldCoins (GameObject): # initialize def __init__ (self, row, col, image, value): @@ -51,8 +90,8 @@ class HealthPotion (GameObject): # using the potion def use (self, butaba): butaba.health += 25 - if butaba.health > butaba.MAXHEALTH: - butaba.health = butaba.MAXHEALTH + if butaba.health > constants.MAXHEALTH: + butaba.health = constants.MAXHEALTH class Chest (GameObject): def __init__ (self, row, col, text, image, key_id, locked = False, objects = []):