1 # object classes - classes for game interactive objects
3 # base class for all objects
5 # initialization routine
6 def __init__ (self
, row
, col
, text
, image
= None, can_pickup
= True, use_str
= "Use"):
11 self
.can_pickup
= can_pickup
12 self
.use_str
= use_str
14 # override this for interaction, i.e. when character walks into the item
16 # always return True if the object is interacted with
17 # return False to make the object block the player from
21 # use the object on another object
22 def use (self
, otherobject
):
26 class Well (GameObject
):
27 def __init__ (self
, row
, col
, image
=None, liquid
= "water"):
30 GameObject
.__init
__ (self
, row
, col
, text
, image
, False, "Draw %s" % liquid
)
35 def use (self
, otherobject
):
36 # if the object is a bucket, fill it
37 if isinstance (otherobject
, Bucket
) is True:
38 # but only if it is empty
39 if otherobject
.liquid
is None:
40 otherobject
.liquid
= self
.liquid
44 class Bucket (GameObject
):
45 def __init__ (self
, row
, col
, image
=None, liquid
= None):
48 if liquid
is not None:
49 text
= text
+ " containing %s" % liquid
50 GameObject
.__init
__ (self
, row
, col
, text
, image
, True, "Empty it")
55 def use (self
, otherobject
):
56 # if the other object is a bucket, transfer its
57 # contents to the other bucket
58 if isinstance (otherobject
, Bucket
):
59 otherobject
.liquid
= self
.liquid
60 # empty the bucket of its contents
64 class GoldCoins (GameObject
):
66 def __init__ (self
, row
, col
, image
, value
):
69 GameObject
.__init
__ (self
, row
, col
, text
, image
, False, "Take")
71 # no interaction with this object
75 # use the object on Butaba - add to his gold
76 def use (self
, butaba
):
77 butaba
.gold
+= self
.value
80 class HealthPotion (GameObject
):
82 def __init__ (self
, row
, col
, image
):
83 text
= "health potion"
84 GameObject
.__init
__ (self
, row
, col
, text
, image
, True, "Drink")
86 # no interaction with this object
91 def use (self
, butaba
):
93 if butaba
.health
> constants
.MAXHEALTH
:
94 butaba
.health
= constants
.MAXHEALTH
96 class Chest (GameObject
):
97 def __init__ (self
, row
, col
, text
, image
, key_id
, locked
= False, objects
= []):
100 self
.objects
= objects
101 GameObject
.__init
__ (self
, row
, col
, text
, image
, False, "Open")
103 # no interaction with this object. Also solid so return False
108 # try to use the key passed to it
110 # if chest is locked try to unlock it
111 if self
.locked
is True:
112 # if the item is a key
113 if isinstance (key
, Key
):
114 # if the key fits the lock
116 if key
.key_id
== self
.key_id
:
120 # return None if not a key or key did not fit
125 class Key (GameObject
):
126 def __init__ (self
, row
, col
, text
, image
, key_id
):
128 GameObject
.__init
__ (self
, row
, col
, text
, image
, True)
130 # no interaction with this object
132 # key is not a solid object so return True
135 # using the key - this is relegated to the locked item for
136 # convenience, so key does nothing by defaults
137 def use (self
, lockitem
):