-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.py
56 lines (42 loc) · 1.91 KB
/
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
# Futurelearn - adventure game
class Character():
def __init__(self, char_name, char_description): # create a character
self.name = char_name
self.description = char_description
self.conversation = None
def describe(self): # describe this character
print( self.name + " is here!" )
print( self.description )
def set_conversation(self, conversation): # set what this character will say when talked to
self.conversation = conversation
def talk(self): # talk to this character
if self.conversation is not None:
print("[" + self.name + " says]: " + self.conversation)
else:
print(self.name + " doesn't want to talk to you")
def fight(self, combat_item): # fight with this character
print(self.name + " doesn't want to fight with you")
return True
class Enemy(Character):
def __init__(self, char_name, char_description):
super().__init__(char_name, char_description) # inherits attributes and methods from Character class
self.weakness = None
def fight(self, combat_item):
if combat_item == self.weakness:
print("You fend " + self.name + " off with the " + combat_item )
return True
else:
print(self.name + " crushes you, puny adventurer")
return False
def set_weakness(self, item_weakness): # set enemy weakness
self.weakness = item_weakness
def get_weakness(self):
return self.weakness
def steal(self):
print("You steal from " + self.name)
class Friend(Character):
def __init__(self, char_name, char_description):
super().__init__(char_name, char_description) # inherits attributes and methods from Character class
self.feeling = None
def hug(self):
print(self.name + " hugs you back!")