# object classes - classes for game interactive objects
-import pygame
-import os.path
-
-import utility
# base class for all objects
class GameObject:
# initialization routine
- def __init__ (self, row, col, text, image = None, can_pickup = True):
+ def __init__ (self, row, col, text, image = None, can_pickup = True, use_str = "Use"):
self.row = row
self.col = col
self.image = image
self.text = text
self.can_pickup = can_pickup
+ self.use_str = use_str
# override this for interaction, i.e. when character walks into the item
def interact (self):
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):
+ text = "gold coins"
+ self.value = value
+ GameObject.__init__ (self, row, col, text, image, False, "Take")
+
+ # no interaction with this object
+ def interact (self):
+ return True
+
+ # use the object on Butaba - add to his gold
+ def use (self, butaba):
+ butaba.gold += self.value
+
class HealthPotion (GameObject):
# initialize
def __init__ (self, row, col, image):
text = "health potion"
- GameObject.__init__ (self, row, col, text, image, True)
+ GameObject.__init__ (self, row, col, text, image, True, "Drink")
# no interaction with this object
def interact (self):
# 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, objects = []):
+ self.key_id = key_id
+ self.locked = locked
+ self.objects = objects
+ GameObject.__init__ (self, row, col, text, image, False, "Open")
+
+ # 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):
# 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