From 9a61fa42c90cdda1184194646fe3deddcfae726f Mon Sep 17 00:00:00 2001 From: Chuck Husak Date: Sat, 27 May 2023 14:59:02 -1000 Subject: [PATCH] Update added check to ensure that user can only input values corresponding to the list of attacks 1-4. Also added a section that accounts for a 20% chance of the Pokemon attack will miss the opponent resulting in 0 damage taken. --- pokemone_battle.py/main.py | 100 +++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/pokemone_battle.py/main.py b/pokemone_battle.py/main.py index 4cd9ab6e..114dc2b6 100644 --- a/pokemone_battle.py/main.py +++ b/pokemone_battle.py/main.py @@ -1,7 +1,7 @@ import time import numpy as np import sys - +import random # Delay printing def delay_print(s): @@ -81,19 +81,33 @@ def fight(self, Pokemon2): print(f"Go {self.name}!") for i, x in enumerate(self.moves): - print(f"{i+1}.", x) - index = int(input('Pick a move: ')) - delay_print(f"\n{self.name} used {self.moves[index-1]}!") - time.sleep(1) - delay_print(string_1_attack) - - # Determine damage - Pokemon2.bars -= self.attack - Pokemon2.health = "" - - # Add back bars plus defense boost - for j in range(int(Pokemon2.bars+.1*Pokemon2.defense)): - Pokemon2.health += "=" + print(f"{i + 1}.", x) + while True: + index = input('Pick a move: ') + if index.isdigit() and 1 <= int(index) <= 4: + index = int(index) + break + else: + print("Choose a number ranging from 1 to 4") + + if random.random() < 0.2: # 20% chance of missing the opponent + delay_print(f"\n{self.name} used {self.moves[index - 1]}!") + time.sleep(1) + delay_print(f"\nBut it missed!") + else: + delay_print(f"\n{self.name} used {self.moves[index - 1]}!") + time.sleep(1) + delay_print(string_1_attack) + + # Determine damage + Pokemon2.bars -= self.attack + Pokemon2.health = "" + + + + # Add back bars plus defense boost + for j in range(int(Pokemon2.bars+.1*Pokemon2.defense)): + Pokemon2.health += "=" time.sleep(1) print(f"\n{self.name}\t\tHLTH\t{self.health}") @@ -109,24 +123,33 @@ def fight(self, Pokemon2): print(f"Go {Pokemon2.name}!") for i, x in enumerate(Pokemon2.moves): - print(f"{i+1}.", x) - index = int(input('Pick a move: ')) - delay_print(f"\n{Pokemon2.name} used {Pokemon2.moves[index-1]}!") - time.sleep(1) - delay_print(string_2_attack) - - # Determine damage - self.bars -= Pokemon2.attack - self.health = "" + print(f"{i + 1}.", x) + while True: + index = input('Pick a move: ') + if index.isdigit() and 1 <= int(index) <= 4: + index = int(index) + break + else: + print("Choose a number ranging from 1 to 4") + + if random.random() < 0.2: # 20% chance of missing the opponent + delay_print(f"\n{Pokemon2.name} used {Pokemon2.moves[index - 1]}!") + time.sleep(1) + delay_print(f"\nBut it missed!") + else: + delay_print(f"\n{Pokemon2.name} used {Pokemon2.moves[index - 1]}!") + time.sleep(1) + delay_print(string_2_attack) + + # Determine damage + self.bars -= Pokemon2.attack + self.health = "" + + # Add back bars plus defense boost + for j in range(int(self.bars+.1*self.defense)): + self.health += "=" - # Add back bars plus defense boost - for j in range(int(self.bars+.1*self.defense)): - self.health += "=" - time.sleep(1) - print(f"{self.name}\t\tHLTH\t{self.health}") - print(f"{Pokemon2.name}\t\tHLTH\t{Pokemon2.health}\n") - time.sleep(.5) # Check to see if Pokemon fainted if self.bars <= 0: @@ -143,17 +166,18 @@ def fight(self, Pokemon2): if __name__ == '__main__': #Create Pokemon + + Charmander = Pokemon('Charmander', 'Fire', ['Ember', 'Scratch', 'Tackle', 'Fire Punch'],{'ATTACK': 4, 'DEFENSE': 2}) + Squirtle = Pokemon('Squirtle', 'Water', ['Bubblebeam', 'Tackle', 'Headbutt', 'Surf'], {'ATTACK': 3, 'DEFENSE': 3}) + Bulbasaur = Pokemon('Bulbasaur', 'Grass', ['Vine Wip', 'Razor Leaf', 'Tackle', 'Leech Seed'],{'ATTACK': 2, 'DEFENSE': 4}) + + Charmeleon = Pokemon('Charmeleon', 'Fire', ['Ember', 'Scratch', 'Flamethrower', 'Fire Punch'],{'ATTACK': 6, 'DEFENSE': 5}) + Wartortle = Pokemon('Wartortle', 'Water', ['Bubblebeam', 'Water Gun', 'Headbutt', 'Surf'],{'ATTACK': 5, 'DEFENSE': 5}) + Ivysaur = Pokemon('Ivysaur\t', 'Grass', ['Vine Wip', 'Razor Leaf', 'Bullet Seed', 'Leech Seed'],{'ATTACK': 4, 'DEFENSE': 6}) + Charizard = Pokemon('Charizard', 'Fire', ['Flamethrower', 'Fly', 'Blast Burn', 'Fire Punch'], {'ATTACK':12, 'DEFENSE': 8}) Blastoise = Pokemon('Blastoise', 'Water', ['Water Gun', 'Bubblebeam', 'Hydro Pump', 'Surf'],{'ATTACK': 10, 'DEFENSE':10}) Venusaur = Pokemon('Venusaur', 'Grass', ['Vine Wip', 'Razor Leaf', 'Earthquake', 'Frenzy Plant'],{'ATTACK':8, 'DEFENSE':12}) - Charmander = Pokemon('Charmander', 'Fire', ['Ember', 'Scratch', 'Tackle', 'Fire Punch'],{'ATTACK':4, 'DEFENSE':2}) - Squirtle = Pokemon('Squirtle', 'Water', ['Bubblebeam', 'Tackle', 'Headbutt', 'Surf'],{'ATTACK': 3, 'DEFENSE':3}) - Bulbasaur = Pokemon('Bulbasaur', 'Grass', ['Vine Wip', 'Razor Leaf', 'Tackle', 'Leech Seed'],{'ATTACK':2, 'DEFENSE':4}) - - Charmeleon = Pokemon('Charmeleon', 'Fire', ['Ember', 'Scratch', 'Flamethrower', 'Fire Punch'],{'ATTACK':6, 'DEFENSE':5}) - Wartortle = Pokemon('Wartortle', 'Water', ['Bubblebeam', 'Water Gun', 'Headbutt', 'Surf'],{'ATTACK': 5, 'DEFENSE':5}) - Ivysaur = Pokemon('Ivysaur\t', 'Grass', ['Vine Wip', 'Razor Leaf', 'Bullet Seed', 'Leech Seed'],{'ATTACK':4, 'DEFENSE':6}) - Charizard.fight(Squirtle) # Get them to fight \ No newline at end of file