-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.py
79 lines (64 loc) · 2.5 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class Character():
# Create a character
def __init__(self, char_name, char_description):
self.name = char_name
self.description = char_description
self.conversation = None
# Describe this character
def describe(self):
print( self.name + " is here!" )
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("[" + self.name + " says]: " + self.conversation)
else:
print(self.name + " doesn't want to talk to you")
# Fight with this character
def fight(self, combat_item):
print(self.name + " doesn't want to fight with you")
return True
# creating an enemy subclass
class Enemy(Character): #Putting Character inside the brackets tells Python that the Enemy class will inherit all of the methods from Character.
def __init__(self, char_name, char_description):
super().__init__(char_name, char_description)
self.weakness = None
# set the weakness of this character
def set_weakness(self, enemy_weakness):
self.weakness = enemy_weakness
# output the enemy weakness
def get_weakness(self):
return self.weakness
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 steal(self):
print("You steal from " + self.name)
# How will you decide what this character has to steal?
# Creating a friend subclass
class Friend(Character):
def __init__(self, char_name, char_description):
super().__init__(char_name, char_description)
self.need = None
def hug(self):
print(self.name + " hugs you back!")
# What other methods could your Friend class have?
# Set the item he is looking for
def set_need(self, friend_need):
self.need = friend_need
# output the item he wants
def get_need(self):
return self.need
def reward(self, given_item):
if given_item == self.need :
print("You give " + self.name + " a " + given_item + ". He loves it and Hugs you")
return True
else:
return False