-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathI) A Grots Life( Version A ) .py
293 lines (221 loc) · 8.48 KB
/
I) A Grots Life( Version A ) .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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import random
lootlist=["Fist Full of Straws","Fish Bone","Old Stick","Dirty Potato Sack","Crumbling Stones","Rusty Umbrella","Rope"]
enemylist=("Rat","Hobbit","Tiny Dragon","Drunk Human","Killer Bee")
inventory=[]
food=("Mushrooms","Meaty Bones","Rotten Apples","Spoiled Meat")
larder=[]
goal=[]
# Class defines an object
#self represents the instance of the class.
#When objects are instantiated, the object itself is passed into the self parameter.
#Because of this, the object’s data is bound to the object
# __init__ ( known as a constructor or initialization method)
# This automatically invoked when new object is created.
# All class will have a method __init__ which provide instructions on what arguments is needed
# eg: gob = Goblin(gob_name,0,100,0,20) which is the goblin's name,hunger,health,provision,gold
# can invoke functions/methods but in this case just intialize attribute values
# In python 3 it makes little difference if it is class Goblin: or Goblin (object) or Globin():
# since in python 3 it inherits it behind the scence anyway so 'Goblin:' would be fine
#Left it in the code just to make you aware if you ever see (object), took me awhile to research.
class Goblin(object):
def __init__(self, name, hunger,health,provision,gold ):
self.name = name
self.hunger = hunger
self.health= health
self.provision= provision
self.gold=gold
def __pass_time(self):
self.hunger += 1
@property
def hung(self):
hung=self.hunger
if hung<5:
m=("not hungry")
elif 5 <=hung <=10:
m=(" a bit hungry")
elif 11 <=hung<=15:
m=("hungry")
else:
m= (" staving !!!")
return m
@property
def wounded(self):
cod=self.health
if cod==100:
d=("fighting fit !!")
elif 70 <=cod <=99:
d=("in good health")
elif 40<=cod<=69:
d=(" bleeding bad")
else:
d=("very wounded")
return d
def status(self):
print("You have",self.provision,"provisions")
print("You have",inventory,"in your bag" )
print("You have",self.gold, "gold")
print("You are ",self.hung)
print("You are ",self.wounded)
self.__pass_time()
def eat(self, eat = 5):
if self.hunger<=0:
print("You are not hungry")
elif self.provision>0:
mep=random.choice(larder)
print("You eat some",mep)
larder.remove(mep)
print("It was a tasty meal")
self.hunger -= eat
self.provision-=2
else:
print("You do not have any food")
self.__pass_time()
def hunt(self):
loot=random.choice(lootlist)
enemy=random.choice(enemylist)
if ("Fish Bone Spear") in goal:
print("Armed with your Fish Bone Spear...")
damage=random.randint(1,10)
self.health-=damage
else:
damage=random.randint(11,30)
self.health-=damage
print ("You came across a",enemy)
print("After an epic fight you took ",damage,"damage")
if loot in inventory:
print("You see nothing of interest")
else:
inventory.append(loot)
print("But you find",loot)
coin=random.randint(1,5)
self.gold+=coin
print("You have gain",coin,"gold")
self.__pass_time()
def farm(self,stash=2):
grub=random.choice(food)
print("You have found some",grub)
larder.append(grub)
print("You have gained",stash,"provisions")
self.provision+= stash
self.__pass_time()
def rest(self):
if self.health>=100:
print("You do not need rest")
else:
if("Straw Bed") in goal:
print("You rest better in your Straw Bed")
sleep=random.randint(10,30)
else:
print("Sleeping on the floor is rough ")
sleep=random.randint(5,20)
bob=self.health
self.health+=sleep
if self.health>=100:
self.health=100
recover= self.health-bob
print("You have recovered",recover,"health")
self.__pass_time()
def craft(self):
print( """
0-exit
1-Fish Bone Spear
2-Straw Bed
3-Small Hut
""")
choice=input("Choice:")
if choice == "0":
print("come back when you have more resource")
elif choice=="1":
if ("Fish Bone Spear") in goal:
print("You only need one")
elif "Fish Bone" and "Old Stick" in inventory:
inventory.remove("Fish Bone")
inventory.remove("Old Stick")
goal.append("Fish Bone Spear")
print("You have crafted the Fish Bone Spear")
else:
print("You do not have the crafting material")
elif choice=="2":
if ("Straw Bed") in goal:
print("You only need one")
elif "Fist Full of Straws" and "Dirty Potato Sack" in inventory:
inventory.remove("Fist Full of Straws")
inventory.remove("Dirty Potato Sack")
goal.append("Straw Bed")
print("You have crafted Straw Bed")
else:
print("You do not have the crafting material")
elif choice=="3":
if ("Small Hut") in goal:
print("You only need one")
elif "Crumbling Stones" and "Rusty Umbrella" and "Rope" in inventory:
inventory.remove("Crumbling Stones")
inventory.remove("Rusty Umbrella")
inventory.remove("Rope")
goal.append("Small Hut")
print("You have crafted Small Hut")
else:
print("You do not have the crafting material")
else:
print("invalid")
def main():
gob_name = input("What do you want to name your Goblin?: ")
gob = Goblin(gob_name,0,100,0,20)
endgame = False
choice = None
while choice != "0":
print ( " So... " ,gob_name, " What is your action ?" )
print \
("""
0 - Quit
1 - status
2 - Eat
3 - Scavenge
4 - Explore
5 - Rest
6 - Craft
""")
choice = input("Choice: ")
print()
if choice == "0":
print("Good-bye.")
elif choice == "1":
gob.status()
elif choice == "2":
gob.eat()
elif choice == "3":
gob.farm()
elif choice == "4":
gob.hunt()
elif choice == "5":
gob.rest()
elif choice == "6":
gob.craft()
else:
print("\nSorry, but", choice, "isn't a valid choice.")
if gob.hunger >20:
print("died from hunger")
input("press any button to continue")
break
if gob.health <=0:
print("died from wounds")
input("press any button to continue")
break
if endgame == False:
if ("Fish Bone Spear") in goal and ("Straw Bed")in goal and("Small Hut") in goal:
print("You have built your home and prove you are a survivor, you win !!")
con=input("Do you want to continue playing 1-yes, 2-no" )
if con == "1":
endgame = True
elif con == "2":
print("Good bye")
break
else:
pass
else:
pass
else:
pass
main()
("\n\nPress the enter key to exit.")
#https://github.com/Ninedeadeyes/15-mini-python-games-