Skip to content

Commit c2cf29c

Browse files
author
abc
committed
adding my game
1 parent 99f3a41 commit c2cf29c

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

pokemone_battle.py/main.py

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
import time
2+
import numpy as np
3+
import sys
4+
5+
# Delay printing
6+
7+
def delay_print(s):
8+
# print one character at a time
9+
# https://stackoverflow.com/questions/9246076/how-to-print-one-character-at-a-time-on-one-line
10+
for c in s:
11+
sys.stdout.write(c)
12+
sys.stdout.flush()
13+
time.sleep(0.05)
14+
15+
# Create the class
16+
class Pokemon:
17+
def __init__(self, name, types, moves, EVs, health='==================='):
18+
# save variables as attributes
19+
self.name = name
20+
self.types = types
21+
self.moves = moves
22+
self.attack = EVs['ATTACK']
23+
self.defense = EVs['DEFENSE']
24+
self.health = health
25+
self.bars = 20 # Amount of health bars
26+
27+
28+
def fight(self, Pokemon2):
29+
# Allow two pokemon to fight each other
30+
31+
# Print fight information
32+
print("-----POKEMONE BATTLE-----")
33+
print(f"\n{self.name}")
34+
print("TYPE/", self.types)
35+
print("ATTACK/", self.attack)
36+
print("DEFENSE/", self.defense)
37+
print("LVL/", 3*(1+np.mean([self.attack,self.defense])))
38+
print("\nVS")
39+
print(f"\n{Pokemon2.name}")
40+
print("TYPE/", Pokemon2.types)
41+
print("ATTACK/", Pokemon2.attack)
42+
print("DEFENSE/", Pokemon2.defense)
43+
print("LVL/", 3*(1+np.mean([Pokemon2.attack,Pokemon2.defense])))
44+
45+
time.sleep(2)
46+
47+
# Consider type advantages
48+
version = ['Fire', 'Water', 'Grass']
49+
for i,k in enumerate(version):
50+
if self.types == k:
51+
# Both are same type
52+
if Pokemon2.types == k:
53+
string_1_attack = '\nIts not very effective...'
54+
string_2_attack = '\nIts not very effective...'
55+
56+
# Pokemon2 is STRONG
57+
if Pokemon2.types == version[(i+1)%3]:
58+
Pokemon2.attack *= 2
59+
Pokemon2.defense *= 2
60+
self.attack /= 2
61+
self.defense /= 2
62+
string_1_attack = '\nIts not very effective...'
63+
string_2_attack = '\nIts super effective!'
64+
65+
# Pokemon2 is WEAK
66+
if Pokemon2.types == version[(i+2)%3]:
67+
self.attack *= 2
68+
self.defense *= 2
69+
Pokemon2.attack /= 2
70+
Pokemon2.defense /= 2
71+
string_1_attack = '\nIts super effective!'
72+
string_2_attack = '\nIts not very effective...'
73+
74+
75+
# Now for the actual fighting...
76+
# Continue while pokemon still have health
77+
while (self.bars > 0) and (Pokemon2.bars > 0):
78+
# Print the health of each pokemon
79+
print(f"\n{self.name}\t\tHLTH\t{self.health}")
80+
print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n")
81+
82+
print(f"Go {self.name}!")
83+
for i, x in enumerate(self.moves):
84+
print(f"{i+1}.", x)
85+
index = int(input('Pick a move: '))
86+
delay_print(f"\n{self.name} used {self.moves[index-1]}!")
87+
time.sleep(1)
88+
delay_print(string_1_attack)
89+
90+
# Determine damage
91+
Pokemon2.bars -= self.attack
92+
Pokemon2.health = ""
93+
94+
# Add back bars plus defense boost
95+
for j in range(int(Pokemon2.bars+.1*Pokemon2.defense)):
96+
Pokemon2.health += "="
97+
98+
time.sleep(1)
99+
print(f"\n{self.name}\t\tHLTH\t{self.health}")
100+
print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n")
101+
time.sleep(.5)
102+
103+
# Check to see if Pokemon fainted
104+
if Pokemon2.bars <= 0:
105+
delay_print("\n..." + Pokemon2.name + ' fainted.')
106+
break
107+
108+
# Pokemon2s turn
109+
110+
print(f"Go {Pokemon2.name}!")
111+
for i, x in enumerate(Pokemon2.moves):
112+
print(f"{i+1}.", x)
113+
index = int(input('Pick a move: '))
114+
delay_print(f"\n{Pokemon2.name} used {Pokemon2.moves[index-1]}!")
115+
time.sleep(1)
116+
delay_print(string_2_attack)
117+
118+
# Determine damage
119+
self.bars -= Pokemon2.attack
120+
self.health = ""
121+
122+
# Add back bars plus defense boost
123+
for j in range(int(self.bars+.1*self.defense)):
124+
self.health += "="
125+
126+
time.sleep(1)
127+
print(f"{self.name}\t\tHLTH\t{self.health}")
128+
print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n")
129+
time.sleep(.5)
130+
131+
# Check to see if Pokemon fainted
132+
if self.bars <= 0:
133+
delay_print("\n..." + self.name + ' fainted.')
134+
break
135+
136+
money = np.random.choice(5000)
137+
delay_print(f"\nOpponent paid you ${money}.\n")
138+
139+
140+
141+
142+
143+
144+
if __name__ == '__main__':
145+
#Create Pokemon
146+
Charizard = Pokemon('Charizard', 'Fire', ['Flamethrower', 'Fly', 'Blast Burn', 'Fire Punch'], {'ATTACK':12, 'DEFENSE': 8})
147+
Blastoise = Pokemon('Blastoise', 'Water', ['Water Gun', 'Bubblebeam', 'Hydro Pump', 'Surf'],{'ATTACK': 10, 'DEFENSE':10})
148+
Venusaur = Pokemon('Venusaur', 'Grass', ['Vine Wip', 'Razor Leaf', 'Earthquake', 'Frenzy Plant'],{'ATTACK':8, 'DEFENSE':12})
149+
150+
Charmander = Pokemon('Charmander', 'Fire', ['Ember', 'Scratch', 'Tackle', 'Fire Punch'],{'ATTACK':4, 'DEFENSE':2})
151+
Squirtle = Pokemon('Squirtle', 'Water', ['Bubblebeam', 'Tackle', 'Headbutt', 'Surf'],{'ATTACK': 3, 'DEFENSE':3})
152+
Bulbasaur = Pokemon('Bulbasaur', 'Grass', ['Vine Wip', 'Razor Leaf', 'Tackle', 'Leech Seed'],{'ATTACK':2, 'DEFENSE':4})
153+
154+
Charmeleon = Pokemon('Charmeleon', 'Fire', ['Ember', 'Scratch', 'Flamethrower', 'Fire Punch'],{'ATTACK':6, 'DEFENSE':5})
155+
Wartortle = Pokemon('Wartortle', 'Water', ['Bubblebeam', 'Water Gun', 'Headbutt', 'Surf'],{'ATTACK': 5, 'DEFENSE':5})
156+
Ivysaur = Pokemon('Ivysaur\t', 'Grass', ['Vine Wip', 'Razor Leaf', 'Bullet Seed', 'Leech Seed'],{'ATTACK':4, 'DEFENSE':6})
157+
158+
159+
Charizard.fight(Squirtle) # Get them to fight

0 commit comments

Comments
 (0)