1 # object classes - classes for game interactive objects
7 # base class for all objects
9 # initialization routine
10 def __init__ (self
, row
, col
, text
, image
= None, can_pickup
= True):
15 self
.can_pickup
= can_pickup
17 # override this for interaction, i.e. when character walks into the item
19 # always return True if the object is interacted with
20 # return False to make the object block the player from
24 # use the object on another object
25 def use (self
, otherobject
):
29 class HealthPotion (GameObject
):
31 def __init__ (self
, row
, col
, image
):
32 text
= "health potion"
33 GameObject
.__init
__ (self
, row
, col
, text
, image
, True)
35 # no interaction with this object
40 def use (self
, butaba
):
42 if butaba
.health
> butaba
.MAXHEALTH
:
43 butaba
.health
= butaba
.MAXHEALTH
45 class Chest (GameObject
):
46 def __init__ (self
, row
, col
, text
, image
, key_id
, locked
= False, items
= []):
50 GameObject
.__init
__ (self
, row
, col
, text
, image
, False)
52 # no interaction with this object. Also solid so return False
57 # try to use the key passed to it
59 # if chest is locked try to unlock it
60 if self
.locked
is True:
61 # if the item is a key
62 if isinstance (key
, Key
):
63 # if the key fits the lock
65 if key
.key_id
== self
.key_id
:
69 # return None if not a key or key did not fit
74 class Key (GameObject
):
75 def __init__ (self
, row
, col
, text
, image
, key_id
):
77 GameObject
.__init
__ (self
, row
, col
, text
, image
, True)
79 # no interaction with this object
81 # key is not a solid object so return True
84 # using the key - this is relegated to the locked item for
85 # convenience, so key does nothing by defaults
86 def use (self
, lockitem
):