Added the Conversation Interaction
[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 GoldCoins (GameObject):
26 # initialize
27 def __init__ (self, row, col, image, value):
28 text = "gold coins"
29 self.value = value
30 GameObject.__init__ (self, row, col, text, image, False, "Take")
31
32 # no interaction with this object
33 def interact (self):
34 return True
35
36 # use the object on Butaba - add to his gold
37 def use (self, butaba):
38 butaba.gold += self.value
39
40
41 class HealthPotion (GameObject):
42 # initialize
43 def __init__ (self, row, col, image):
44 text = "health potion"
45 GameObject.__init__ (self, row, col, text, image, True, "Drink")
46
47 # no interaction with this object
48 def interact (self):
49 return True
50
51 # using the potion
52 def use (self, butaba):
53 butaba.health += 25
54 if butaba.health > butaba.MAXHEALTH:
55 butaba.health = butaba.MAXHEALTH
56
57 class Chest (GameObject):
58 def __init__ (self, row, col, text, image, key_id, locked = False, objects = []):
59 self.key_id = key_id
60 self.locked = locked
61 self.objects = objects
62 GameObject.__init__ (self, row, col, text, image, False, "Open")
63
64 # no interaction with this object. Also solid so return False
65 def interact (self):
66 # object is solid
67 return False
68
69 # try to use the key passed to it
70 def use (self, key):
71 # if chest is locked try to unlock it
72 if self.locked is True:
73 # if the item is a key
74 if isinstance (key, Key):
75 # if the key fits the lock
76 # unlock the chest
77 if key.key_id == self.key_id:
78 self.locked = False
79 # return the key
80 return key
81 # return None if not a key or key did not fit
82 return None
83 else:
84 return self.locked
85
86 class Key (GameObject):
87 def __init__ (self, row, col, text, image, key_id):
88 self.key_id = key_id
89 GameObject.__init__ (self, row, col, text, image, True)
90
91 # no interaction with this object
92 def interact (self):
93 # key is not a solid object so return True
94 return True
95
96 # using the key - this is relegated to the locked item for
97 # convenience, so key does nothing by defaults
98 def use (self, lockitem):
99 pass