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