-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_pokemon_battle.py
201 lines (173 loc) · 11.7 KB
/
04_pokemon_battle.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
import random
import time
import linecache
f = open('pokemonsaves.txt', 'r')
def battle():
#read from save file
num = 0
pokemoncount = len(f.readlines())
print(f'Which pokemon do you want to play as? (1 to {pokemoncount}): ')
for i in range(pokemoncount):
num = num + 1
plr = linecache.getline('pokemonsaves.txt', num)
pname = plr.split('/')
pname2 = pname[0]
print(num, '. ', pname2)
pokemon = input(f'Select a pokemon (1 to {pokemoncount}): ')
plr = int(pokemon)
plrline = linecache.getline('pokemonsaves.txt', plr)
plrstats = plrline.split('/')
player_name = plrstats[0]
player_health = int(plrstats[1])
if(player_health > 1000):
print('Invalid Health')
exit(1)
print(f'Which pokemon do you want your opponent to be? (1 to {pokemoncount}): ')
num = 0
for i in range(pokemoncount):
num = num + 1
plr = linecache.getline('pokemonsaves.txt', num)
pname = plr.split('/')
pname2 = pname[0]
print(num, '. ', pname2)
cpupokemon = input(f'What pokemon do you want your opponent to be (1 to {pokemoncount}): ')
cpup = int(cpupokemon)
cpu = linecache.getline('pokemonsaves.txt', cpup)
cpustats = cpu.split('/')
cpu_name = cpustats[0]
cpu_health = int(cpustats[1])
if(cpu_health > 1000):
print('Invalid Health')
exit(1)
#setup attacks
player_attacks = [plrstats[2], plrstats[3], plrstats[4]]
cpu_attacks = [cpustats[2], cpustats[3], cpustats[4]]
print(f"{player_name} vs. {cpu_name}!")
while True:
print(f"{player_name}: {player_health} HP")
print(f"{cpu_name}: {cpu_health} HP")
time.sleep(1)
print("\nYour turn!")
print("Choose your attack:")
for i, attack in enumerate(player_attacks, 1):
print(f"{i}. {attack}")
player_attack = int(input("Enter the number of your attack: "))
time.sleep(1)
if player_attack == 1:
print(f"{player_name} used {player_attacks[0]}!")
time.sleep(1)
damage = random.randint(10, 15)
cpu_health -= damage
print(f"{cpu_name} took {damage} damage!")
elif player_attack == 2:
print(f"{player_name} used {player_attacks[1]}")
time.sleep(1)
damage = random.randint(5, 20)
cpu_health -= damage
print(f"{cpu_name} took {damage} damage!")
elif player_attack == 3:
print(f"{player_name} used {player_attacks[2]}")
time.sleep(1)
damage = random.randint(0, 30)
cpu_health -= damage
print(f"{cpu_name} took {damage} damage!")
else:
time.sleep(1)
print("You missed!")
time.sleep(1)
if cpu_health <= 0:
print(f"{cpu_name} fainted!")
break
print(f"\n{cpu_name}'s turn!")
cpu_attack = random.randint(1, 3)
time.sleep(1)
if cpu_attack == 1:
print(f"{cpu_name} used {cpu_attacks[0]}")
time.sleep(1)
damage = random.randint(10, 15)
player_health -= damage
print(f"{player_name} took {damage} damage!")
elif cpu_attack == 2:
print(f"{cpu_name} used {cpu_attacks[1]}")
time.sleep(1)
damage = random.randint(5, 20)
player_health -= damage
print(f"{player_name} took {damage} damage!")
elif cpu_attack == 3:
print(f"{cpu_name} used {cpu_attacks[2]}")
time.sleep(1)
damage = random.randint(0, 30)
player_health -= damage
print(f"{player_name} took {damage} damage!")
time.sleep(1)
if player_health <= 0:
print(f"{player_name} fainted!")
break
print("\nNext round!")
print("\nBattle over!")
if player_health <= 0:
winner = 'cpu'
else:
winner = 'player'
winnercongrat(winner, player_health)
time.sleep(5)
def winnercongrat(winner, plrhealth):
if(winner == "player"):
print("""
▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄
▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░▌ ▐░▌▐░░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▐░▌ ▐░▌ ▀▀▀▀█░█▀▀▀▀ ▐░▌░▌ ▐░▌▐░▌░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌
▐░▌ ▄ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▐░▌ ▐░▌░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀█░█▀▀
▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌ ▐░▌
▐░▌░▌ ▐░▐░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌ ▐░▐░▌▐░▌ ▐░▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌
▐░░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░░▌▐░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌
▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀ ▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀
""")
print("""
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌
▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌
▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌▐░▌ ▐░▌
▐░▌ ▐░░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░▌
▐░▌ ▀▀▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀ ▐░▌ ▐░▌▐░▌ ▐░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌
▄▄▄▄█░█▄▄▄▄ ▄▄▄▄▄▄▄▄▄█░▌ ▐░▌ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀
""")
print('\n\n\n\n')
print(f'Thanks for playing, of course. You won with {plrhealth} of your health left')
else:
print("""
▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄
▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░▌ ▐░▌▐░░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▐░▌ ▐░▌ ▀▀▀▀█░█▀▀▀▀ ▐░▌░▌ ▐░▌▐░▌░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌
▐░▌ ▄ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▐░▌ ▐░▌░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀█░█▀▀
▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌ ▐░▌
▐░▌░▌ ▐░▐░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌ ▐░▐░▌▐░▌ ▐░▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌
▐░░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░░▌▐░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌
▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀ ▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀
""")
print("""
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌
▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌
▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌
▐░▌ ▐░░░░░░░░░░░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░▌
▐░▌ ▀▀▀▀▀▀▀▀▀█░▌ ▐░▌ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌ ▐░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌
▄▄▄▄█░█▄▄▄▄ ▄▄▄▄▄▄▄▄▄█░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░█▄▄▄▄▄▄▄█░▌
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░░░░░░░░░░░▌
▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀
""")
print('\n\n\n\n')
print('Thanks for playing, of course.')
battle()