2edbc5b1c86a11ddb16853c926b191013e35741c
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
):
25 class GoldCoins (GameObject
):
27 def __init__ (self
, row
, col
, image
, value
):
30 GameObject
.__init
__ (self
, row
, col
, text
, image
, False, "Take")
32 # no interaction with this object
36 # use the object on Butaba - add to his gold
37 def use (self
, butaba
):
38 butaba
.gold
+= self
.value
41 class HealthPotion (GameObject
):
43 def __init__ (self
, row
, col
, image
):
44 text
= "health potion"
45 GameObject
.__init
__ (self
, row
, col
, text
, image
, True, "Drink")
47 # no interaction with this object
52 def use (self
, butaba
):
54 if butaba
.health
> butaba
.MAXHEALTH
:
55 butaba
.health
= butaba
.MAXHEALTH
57 class Chest (GameObject
):
58 def __init__ (self
, row
, col
, text
, image
, key_id
, locked
= False, objects
= []):
61 self
.objects
= objects
62 GameObject
.__init
__ (self
, row
, col
, text
, image
, False, "Open")
64 # no interaction with this object. Also solid so return False
69 # try to use the key passed to it
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
77 if key
.key_id
== self
.key_id
:
81 # return None if not a key or key did not fit
86 class Key (GameObject
):
87 def __init__ (self
, row
, col
, text
, image
, key_id
):
89 GameObject
.__init
__ (self
, row
, col
, text
, image
, True)
91 # no interaction with this object
93 # key is not a solid object so return True
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
):