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
):
28 class GoldCoins (GameObject
):
30 def __init__ (self
, row
, col
, image
, value
):
33 GameObject
.__init
__ (self
, row
, col
, text
, image
, False)
35 # no interaction with this object
39 # use the object on Butaba - add to his gold
40 def use (self
, butaba
):
41 butaba
.gold
+= self
.value
44 class HealthPotion (GameObject
):
46 def __init__ (self
, row
, col
, image
):
47 text
= "health potion"
48 GameObject
.__init
__ (self
, row
, col
, text
, image
, True)
50 # no interaction with this object
55 def use (self
, butaba
):
57 if butaba
.health
> butaba
.MAXHEALTH
:
58 butaba
.health
= butaba
.MAXHEALTH
60 class Chest (GameObject
):
61 def __init__ (self
, row
, col
, text
, image
, key_id
, locked
= False, objects
= []):
64 self
.objects
= objects
65 GameObject
.__init
__ (self
, row
, col
, text
, image
, False)
67 # no interaction with this object. Also solid so return False
72 # try to use the key passed to it
74 # if chest is locked try to unlock it
75 if self
.locked
is True:
76 # if the item is a key
77 if isinstance (key
, Key
):
78 # if the key fits the lock
80 if key
.key_id
== self
.key_id
:
84 # return None if not a key or key did not fit
89 class Key (GameObject
):
90 def __init__ (self
, row
, col
, text
, image
, key_id
):
92 GameObject
.__init
__ (self
, row
, col
, text
, image
, True)
94 # no interaction with this object
96 # key is not a solid object so return True
99 # using the key - this is relegated to the locked item for
100 # convenience, so key does nothing by defaults
101 def use (self
, lockitem
):