This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
349 lines (289 loc) · 12.7 KB
/
main.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import numpy as np
import time # For time delay
import random # For random number generation
class Pokemon:
def __init__(self, HP=0, EA="", attribute="", species="", PA="", maxHP=0):
self.HP = HP
self.maxHP = maxHP
self.attribute = attribute
self.species = species
self.name = species
self.EA = EA
self.PA = PA
def set_name(self):
self.name = input("Enter the name of the pokemon: ")
return self.name
# Pokemon information setting
Unit_info = {"Charmander": {"species": "Charmander", "HP": 50, "EA": "Ember", "attribute": "fire", "PA": "Tackle", "maxHP": 50},
"Squirtle": {"species": "Squirtle", "HP": 50, "EA": "Water Gun", "attribute": "water", "PA": "Tackle", "maxHP": 50},
"Bulbasaur": {"species": "Bulbasaur", "HP": 50, "EA": "Vine Whip", "attribute": "grass", "PA": "Tackle", "maxHP": 50},
}
# Attack damage setting
EA_damage = {"Ember": 10, "Water Gun": 10, "Vine Whip": 10}
PA_damage = {"Tackle": 9}
# Create an instance of Pokémons in dictionary
Charmander = Pokemon(Unit_info["Charmander"]["HP"], Unit_info["Charmander"]["EA"], Unit_info["Charmander"]["attribute"], Unit_info["Charmander"]["species"], Unit_info["Charmander"]["PA"], Unit_info["Charmander"]["maxHP"])
Squirtle = Pokemon(Unit_info["Squirtle"]["HP"], Unit_info["Squirtle"]["EA"], Unit_info["Squirtle"]["attribute"], Unit_info["Squirtle"]["species"], Unit_info["Squirtle"]["PA"], Unit_info["Squirtle"]["maxHP"])
Bulbasaur = Pokemon(Unit_info["Bulbasaur"]["HP"], Unit_info["Bulbasaur"]["EA"], Unit_info["Bulbasaur"]["attribute"], Unit_info["Bulbasaur"]["species"], Unit_info["Bulbasaur"]["PA"], Unit_info["Bulbasaur"]["maxHP"])
class Trainer:
def __init__(self, name="", poke_list=[]):
self.name = name
self.poke_list = poke_list
# Add the pokemon to poke_list
def poke_add(self, poke):
self.poke_list.append(poke)
# Remove the pokemon from poke_list
def poke_remove(self, poke):
self.poke_list.remove(poke)
# Print the player pokemon list
def print_poke_list(self):
print("\n\nThis is your actual Pokémon team:")
for i in range(len(self.poke_list)):
print(i+1, self.poke_list[i].name,"(",self.poke_list[i].HP,"/",self.poke_list[i].maxHP,")")
# Pokemon starter choice between Charmander, Squirtle, and Bulbasaur
def starter_choice(self):
print("\n\nChoose your starter pokemon")
print("1. Charmander ", "2. Squirtle ", "3. Bulbasaur\n")
while True:
choice = int(input("Enter the number of your choice: "))
if choice == 1:
self.poke_add(Charmander)
self.poke_list[0].set_name()
break
elif choice == 2:
self.poke_add(Squirtle)
self.poke_list[0].set_name()
break
elif choice == 3:
self.poke_add(Bulbasaur)
self.poke_list[0].set_name()
break
else:
print("Please enter a valid number")
# Pokemon choose from the poke_list
def choose_poke(self):
print("\nChoose your Pokémon:")
self.print_poke_list()
while True:
choice = int(input("Enter the number of your choice: "))
if choice > 0 and choice <= len(self.poke_list) and choice != 1:
self.poke_list.insert(0, self.poke_list.pop(choice-1))
break
elif choice == 1:
print("This is your current Pokémon ! I saw you coming haha")
else:
print("Please enter a valid number")
def battle_disp(my = Pokemon(),enemy = Pokemon()):
print("\n######################")
print("1. Enemy:", enemy.name, "(", enemy.HP, "/", enemy.maxHP, ")")
print("2. My:", my.name, "(", my.HP, "/", my.maxHP, ")")
print("######################\n")
def poke_EA(attack=Pokemon(), defend=Pokemon()):
time.sleep(0.5)
print(attack.name, "used ", attack.EA, "!")
if attack.attribute == "fire" and defend.attribute == "grass":
print("It's super effective!")
defend.HP -= EA_damage[attack.EA] * 2
elif attack.attribute == "water" and defend.attribute == "fire":
print("It's super effective!")
defend.HP -= EA_damage[attack.EA] * 2
elif attack.attribute == "grass" and defend.attribute == "water":
print("It's super effective!")
defend.HP -= EA_damage[attack.EA] * 2
elif attack.attribute == "fire" and defend.attribute == "water":
print("Not very effective")
defend.HP -= EA_damage[attack.EA] * 0.5
elif attack.attribute == "water" and defend.attribute == "grass":
print("Not very effective")
defend.HP -= EA_damage[attack.EA] * 0.5
elif attack.attribute == "grass" and defend.attribute == "fire":
print("Not very effective")
defend.HP -= EA_damage[attack.EA] * 0.5
else:
defend.HP -= EA_damage[attack.EA]
def poke_PA(attack=Pokemon(), defend=Pokemon()):
time.sleep(0.5)
print("\n", attack.name, "used", attack.PA, "!")
defend.HP -= PA_damage[attack.PA]
def poke_cure(poke=Pokemon()):
poke.HP = poke.maxHP
print("\n", poke.name, "cured !")
def poke_capture(trn=Trainer(),enemy=Pokemon()):
loading()
if enemy.HP < enemy.maxHP * 0.5:
if random.random() < 0.9:
print("gotcha!", enemy.species, "was caught!")
trn.poke_add(enemy)
trn.poke_list[-1].set_name()
trn.poke_list[-1].HP = trn.poke_list[-1].maxHP
trn.print_poke_list()
return True
else:
print("oh no!", enemy.species, "break free!")
return False
else:
if random.random() < 0.15:
print("gotcha!", enemy.species, "was caught!")
enemy.set_name()
trn.poke_add(enemy)
poke_cure(enemy)
trn.print_poke_list()
return True
else:
print("oh no!", enemy.species, "break free!")
return False
def loading():
for i in range(3):
print(".")
time.sleep(1)
# Numpy function for direction
def direction():
# Don't tell me why using numpy for this. I don't have the awnser. I just wanted to try it out.
matrix = np.array([[0, 0], [0, 0]])
matrix[0][0] = 1 # North
matrix[0][1] = 2 # South
matrix[1][0] = 3 # East
matrix[1][1] = 0 # West
# Randomize the matrix
np.random.shuffle(matrix)
# Let the player choose the direction bewteen north, south, east, and west
time.sleep(0.5)
print("Choose the direction you want to go:")
print("1. North")
print("2. South")
print("3. East")
print("4. West")
while True:
choice = int(input("Enter the number of your choice: "))
if choice == 1:
print("You are going north")
result = matrix[0][0]
break
elif choice == 2:
print("You are going south")
result = matrix[0][1]
break
elif choice == 3:
print("You are going east")
result = matrix[1][0]
break
elif choice == 4:
print("You are going west")
result = matrix[1][1]
break
else:
print("Please enter a valid number")
loading()
return result
# Make function choose_action between 1.Elemental Attack 2.Physical Attack 3.Cure 4.Capture Pokémon 5.Change Pokémon
def choose_action(trn=Trainer()):
print("Choose the action you want to do:")
print("1. Elemental Attack")
print("2. Physical Attack")
print("3. Cure")
print("4. Capture Pokémon")
print("5. Change Pokémon")
while True:
choice = int(input("Enter the number of your choice: "))
if choice == 1:
return "EA"
elif choice == 2:
return "PA"
elif choice == 3:
return "cure"
elif choice == 4:
return "capture"
elif choice == 5:
if len(trn.poke_list) > 1:
return "change"
else:
print("You don't have any other Pokémon !")
else:
print("Please enter a valid number")
# Main function
def main():
# Welcome
print("\n\nWelcome to the world of Pokémon!")
input("\nPress enter to continue")
# 1. Set the trainer’s name
trn_name = input("\nSet the name of your trainer: ")
trn = Trainer(trn_name)
print("\nGood luck for this adventure", trn.name, "!")
# 2. Choose the starter Pokémon among (Charmander, Bulbasaur, Squirtle)
# 3. Set the name of Pokémon you choose
trn.starter_choice()
trn.print_poke_list()
# 4. Trainer’s goal is to become a Pokémon master, to achieve his/her dream, trainer has 3 steps left to Pokémon master.
step = 4
while step > 1:
step -= 1
time.sleep(0.5)
print("\nYou have", step, "step left to become a Pokémon master\n")
# 5. Trainer can choose 4 ways to walk, each of east, west, north, south.
result = direction()
# 6. Each of the wild Pokémon (Charmander, Bulbasaur, Squirtle, and None) is assigned randomly to each way (no duplicates).
# B. Otherwise, if the Trainer choose was encountering wild Pokémon, then Pokémon battle starts.
if(result == 1):
enemy = Charmander
print("Wild Charmander appeared")
elif(result == 2):
enemy = Squirtle
print("Wild Squirtle appeared")
elif(result == 3):
enemy = Bulbasaur
print("Wild Bulbasaur appeared")
else:
# A. If the path Trainer choose was None, Trainer doesn’t need to fight wild Pokémon but just walk 1 step.
enemy = None
print("Lucky you, there is nothing here !")
if (enemy != None):
battle_disp(trn.poke_list[0], enemy)
while trn.poke_list[0].HP > 0 and enemy.HP > 0:
# 8.Every battle starts with the action of the Trainer, Trainer has 5 options below:
action = choose_action()
# A. Elemental Attack
if action == "EA":
poke_EA(trn.poke_list[0], enemy)
# B. Physical Attack
elif action == "PA":
poke_PA(trn.poke_list[0], enemy)
# C. Cure
elif action == "cure":
poke_cure(trn.poke_list[0])
# D. Capture wild Pokémon
elif action == "capture":
response = poke_capture(trn, enemy)
if response == True:
break
# E. Change Pokémon in battle (if Trainer has more than 1 Pokémon)
elif action == "change":
trn.choose_poke()
# 10. After each of Pokémon’s turn is over, information of HP left of my Pokémon and wild Pokémon should be printed on python shell
battle_disp(trn.poke_list[0], enemy)
# 9.After the turn of trainer is finished, wild Pokémon use only elemental attack to attack Trainer’s Pokémon.
if enemy.HP > 0:
poke_EA(enemy, trn.poke_list[0])
# 10bis. After each of Pokémon’s turn is over, information of HP left of my Pokémon and wild Pokémon should be printed on python shell
battle_disp(trn.poke_list[0], enemy)
# 7. Pokémon battle finished when either HP of enemy or my Pokémon is 0 (HP cannot be negative)
if trn.poke_list[0].HP <= 0:
print("Your Pokémon is dead")
trn.poke_remove(trn.poke_list[0])
# A. If Trainer has no Pokémon left to fight, game is over
if len(trn.poke_list) == 0:
print("\n", trn.name, "has no other Pokémon left...")
print("\n", trn.name, "blacked out!")
return 0;
# B. If Trainer has Pokémon left alive to fight, Trainer can choose Pokémon among them
else:
trn.choose_poke()
print("You change to", trn.poke_list[0].species)
poke_EA(enemy, trn.poke_list[0])
battle_disp(trn.poke_list[0], enemy)
# Heal the enemy Pokémon/object after the battle
enemy.HP = enemy.maxHP
# 11. After trainer complete his/her 3 steps of walking, print the word “{trainer’s name}! Congratulations! You became Pokémon master!”
print("\n", trn.name, "Congratulations! You became Pokémon master!")
print("The end ! Thank you for playing !\n")
return 0
main()