-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom_character.py
78 lines (55 loc) · 2.12 KB
/
room_character.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#Create a character
class Character():
def __init__(self, char_name, char_description):
self.name = char_name
self.description = char_description
self.conversation = None
#Decribe this character
def describe(self):
print(f"/!\ /!\ /!\ ❗️ {self.name} is here ❗️ /!\ /!\ /!\ \n")
print(self.description)
#Set what this character will say when talked to
def set_conversation(self, conversation):
self.conversation = conversation
#Talk to this character
def talk(self):
if self.conversation is not None:
print(f"[{self.name} says]: {self.conversation}")
else:
print(f"{self.name} doesn't want to talk to you.")
#Fight with this character
def fight(self, combat_item):
combat_item = combat_item
print(self.name + " doesn't want to fight you")
return True
#Subclass
class Enemy(Character):
def __init__(self, char_name, char_description, char_weakness):
super().__init__(char_name, char_description)
self.char_weakness = char_weakness
def set_weakness(self, item_weakness):
self.weakness = item_weakness
def get_weakness(self):
return self.weakness
def drop_item(self, item):
print(f"A {item} has dropped from his pocket!")
def fight(self, combat_item): #Overrides the method used in Character
if combat_item == self.weakness:
print(f"☞ You fend {self.name} off, using {combat_item}." )
return True
else:
print("\n")
print(f"☞ {self.name} crushes you, puny adventurer!")
return False
##########
class Friend(Character):
def __init__(self, char_name, char_description):
super().__init__(char_name, char_description)
self.gift_item = "shield"
def set_gift(self, gift_item):
self.gift_item = gift_item
def get_gift(self, gift_item):
return gift_item
def give_item(self):
print(f"☞ Brave mortal, let me give you this {self.gift_item}." )
##########