This repository has been archived by the owner on Oct 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vital_wildness_adventure.py
212 lines (190 loc) · 6.32 KB
/
vital_wildness_adventure.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
class GameObject:
class_name = ""
desc = ""
objects = {}
def __init__(self, name):
self.name = name
GameObject.objects[self.class_name] = self
def get_desc(self):
return self.class_name + "\n" + self.desc
class Goblin(GameObject):
def __init__(self, name):
self.class_name = "goblin"
self._max_health = 3
self.health = 3
self._desc = " A skinny and foul creature"
super().__init__(name)
@property
def desc(self):
if self.health >=3:
return self._desc
elif self.health == 2:
health_line = "It has a wound on its knee."
elif self.health == 1:
health_line = "Its left arm has been cut off!"
elif self.health <= 0:
health_line = "It is dead."
return self._desc + "\n" + health_line
@desc.setter
def desc(self, value):
self._desc = value
class Barbarian(GameObject):
def __init__(self, name):
self.class_name = "barbarian"
self._max_health = 5
self.health = 5
self._desc = " A strong but brainless creature"
super().__init__(name)
@property
def desc(self):
if self.health >= 5:
return self._desc
elif self.health == 4:
health_line = "It has a wound on its knee."
elif self.health == 3:
health_line = "It has wounds on its knee and arm."
elif self.health == 2:
health_line = "Its left arm has been cut off!"
elif self.health == 1:
health_line = "It has wounds all over his body!"
elif self.health <= 0:
health_line = "It is dead."
return self._desc + "\n" + health_line
@desc.setter
def desc(self, value):
self._desc = value
def get_input():
command = input("☞ ").split()
if not command: #if nothing provided
print("You are too shy to say a word.")
return
verb_word = command[0]
if verb_word in special_verb: #shut the program
return verb_word.upper()
if verb_word in verb_dict: #assign verb function
verb = verb_dict[verb_word]
else:
print("Unknown verb {}". format(verb_word))
return
if verb_word == "say": #run function
noun_words = command[1:]
print(verb(noun_words))
elif len(command) >= 2:
noun_word = command[1]
print(verb(noun_word))
else:
print(verb("nothing"))
def help(noun):
if noun in verb_defi:
msg = "{}\n {}".format(noun,verb_defi[noun])
elif noun == "nothing":
msg = verb_defi["all"]
else:
msg = "There is no information about {}.".format(noun)
return msg
def examine(noun):
if noun in GameObject.objects:
return GameObject.objects[noun].get_desc()
else:
return "There is no {} here.".format(noun)
def say(noun):
return 'You said "{}".'.format(" ".join(noun))
def hit(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if type(thing) == Goblin:
thing.health = thing.health - 1
if thing.health <= 0:
msg = "You killed the goblin!"
else:
msg = "You hit the {}".format(thing.class_name)
if type(thing) == Barbarian:
thing.health = thing.health - 1
if thing.health <= 0:
msg = "You killed the barbarian!"
else:
msg = "You hit the {}".format(thing.class_name)
else:
msg = "There is no {} here.".format(noun)
return msg
def knife(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if type(thing) == Goblin:
thing.health = thing.health - 2
if thing.health <= 0:
msg = "You killed the goblin!"
else:
msg = "You knifed the {}".format(thing.class_name)
if type(thing) == Barbarian:
thing.health = thing.health - 2
if thing.health <= 0:
msg = "You killed the barbarian!"
else:
msg = "You knifed the {}".format(thing.class_name)
else:
msg = "There is no {} here.".format(noun)
return msg
def heal(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if thing.health <= 0:
msg = "{} is already dead.".format(noun.title())
elif thing.health == thing._max_health:
msg = "{} is with full health.".format(noun.title())
else:
thing.health += 1
msg = "You healed {}.".format(noun)
else:
msg = "There is no {} here.".format(noun)
return msg
def revive(noun):
if noun in GameObject.objects:
thing = GameObject.objects[noun]
if thing.health > 0:
msg = "{} is still alive!".format(noun.title())
else:
thing.health = thing._max_health
msg = "You revived {}.".format(noun)
else:
msg = "There is no {} here.".format(noun)
return msg
special_verb = ["leave", "restart"]
verb_dict = {
"help" : help,
"say" : say,
"examine" : examine,
"hit" : hit,
"knife" : knife,
"heal" : heal,
"revive" : revive,
}
verb_defi = {
"all" : ", ".join(verb_dict) + ", " + ", ".join(special_verb),
"help" : "Provide information of specific werbs",
"say" : "Speak out the verb loud",
"examine" : "Examine the condition of a specific creature",
"hit" : "Hit a creature with your fist",
"knife" : "Strike a creature with a knife",
"heal" : "Heal a creature a little bit using magic",
"revive" : "Let a creature reborn",
"pet" : "To obtain a creature as pet",
"order" : "Order your pet to attack another creature",
"leave" : "Wave goodbey to these little creatures",
"restart" : "Go back through time and to the beginning of the game"
}
#main
goblin = Goblin("Gobbly")
barbarian = Barbarian("Boby")
while True:
try:
pyin = get_input()
if pyin == "LEAVE":
print("These little creatures will miss you!")
break
elif pyin == "RESTART": #restart the whole game
goblin = Goblin("Gobbly")
barbarian = Barbarian("Boby")
print("You went back through time!")
except KeyboardInterrupt:
print("\nPlease do not leave without saying!")