Added dialogues for the mayor
[butaba-adventures.git] / gameobjects.py
1 # object classes - classes for game interactive objects
2
3 # base class for all objects
4 class GameObject:
5 # initialization routine
6 def __init__ (self, row, col, text, image = None, can_pickup = True, use_str = "Use"):
7 self.row = row
8 self.col = col
9 self.image = image
10 self.text = text
11 self.can_pickup = can_pickup
12 self.use_str = use_str
13
14 # override this for interaction, i.e. when character walks into the item
15 def interact (self):
16 # always return True if the object is interacted with
17 # return False to make the object block the player from
18 # moving over it
19 return True
20
21 # use the object on another object
22 def use (self, otherobject):
23 pass
24
25 # class for well
26 class Well (GameObject):
27 def __init__ (self, row, col, image=None, liquid = "water"):
28 self.liquid = liquid
29 text = "Well"
30 GameObject.__init__ (self, row, col, text, image, False, "Draw %s" % liquid)
31
32 def interact (self):
33 return False
34
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
41
42
43 # class for buckets
44 class Bucket (GameObject):
45 def __init__ (self, row, col, image=None, liquid = None):
46 self.liquid = liquid
47 text = "Bucket"
48 if liquid is not None:
49 text = text + " containing %s" % liquid
50 GameObject.__init__ (self, row, col, text, image, True, "Empty it")
51
52 def interact (self):
53 return True
54
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
61 self.liquid = None
62 self.text = "Bucket"
63
64 class GoldCoins (GameObject):
65 # initialize
66 def __init__ (self, row, col, image, value):
67 text = "gold coins"
68 self.value = value
69 GameObject.__init__ (self, row, col, text, image, False, "Take")
70
71 # no interaction with this object
72 def interact (self):
73 return True
74
75 # use the object on Butaba - add to his gold
76 def use (self, butaba):
77 butaba.gold += self.value
78
79
80 class HealthPotion (GameObject):
81 # initialize
82 def __init__ (self, row, col, image):
83 text = "health potion"
84 GameObject.__init__ (self, row, col, text, image, True, "Drink")
85
86 # no interaction with this object
87 def interact (self):
88 return True
89
90 # using the potion
91 def use (self, butaba):
92 butaba.health += 25
93 if butaba.health > constants.MAXHEALTH:
94 butaba.health = constants.MAXHEALTH
95
96 class Chest (GameObject):
97 def __init__ (self, row, col, text, image, key_id, locked = False, objects = []):
98 self.key_id = key_id
99 self.locked = locked
100 self.objects = objects
101 GameObject.__init__ (self, row, col, text, image, False, "Open")
102
103 # no interaction with this object. Also solid so return False
104 def interact (self):
105 # object is solid
106 return False
107
108 # try to use the key passed to it
109 def use (self, key):
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
115 # unlock the chest
116 if key.key_id == self.key_id:
117 self.locked = False
118 # return the key
119 return key
120 # return None if not a key or key did not fit
121 return None
122 else:
123 return self.locked
124
125 class Key (GameObject):
126 def __init__ (self, row, col, text, image, key_id):
127 self.key_id = key_id
128 GameObject.__init__ (self, row, col, text, image, True)
129
130 # no interaction with this object
131 def interact (self):
132 # key is not a solid object so return True
133 return True
134
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):
138 pass