def combat_round(opponent: dict) -> None: """Determine the amount of damage between character and opponent. PRECONDITION opponent: must be a well-formed dictionary from random_pokemon >>> random.seed(3) >>> combat_round({'Name': 'Palkia', 'Class': 'Water', 'Attack': 'Pressure', 'HP': 5}) You attacked Palkia with a slap and he took 2 damage. Palkia attacked you with Pressure and you took 5 damage. You attacked Palkia with a slap and he took 5 damage. Success! Your opponent has fainted and you gained 20 prize dollars from your battle. <BLANKLINE> >>> random.seed() """ pokemon_attack = roll_die(1, 6) opponent_attack = roll_die(1, 6) if opponent["HP"] > 0: opponent["HP"] -= pokemon_attack print("You attacked %s with a slap and he took %s damage." % (opponent["Name"], pokemon_attack)) if opponent["HP"] <= 0: print( "Success! Your opponent has fainted and you gained 20 prize dollars from your battle.\n" ) if opponent["HP"] <= 0: return None if get_hp() > 0: change_hp(-opponent_attack) print("%s attacked you with %s and you took %s damage." % (opponent["Name"], opponent["Attack"], opponent_attack)) if get_hp() <= 0: print("You fainted. Try again next time!") exit() while True: return combat_round(opponent)
def potential_attack(opponent: dict) -> None: """Determine whether opponent will do damage to user when fleeing. PRECONDITION opponent: must be a well-formed dictionary from random_pokemon >>> random.seed(31) >>> potential_attack({"Name": "Pikachu", "Class": "Electric", "Attack": "Static", "HP": 5}) Despite fleeing, Pikachu still attacked you! He inflicted you by 4 damage. >>> potential_attack({"Name": "Pikachu", "Class": "Electric", "Attack": "Static", "HP": 5}) You fled successfully! >>> random.seed() """ opponent_probability_attack = roll_die(1, 10) opponent_attack = roll_die(1, 4) if opponent_probability_attack == 1: change_hp(-opponent_attack) print( "Despite fleeing, %s still attacked you! He inflicted you by %s damage." % (opponent["Name"], opponent_attack)) else: print("You fled successfully!")
def encounter_percentage(opponent: dict) -> None: """Determine whether opponent will fight or flee. PRECONDITION opponent: must be a well-formed dictionary from random_pokemon """ encounter = roll_die(1, 10) if encounter == 1: print("You encountered another Pokemon!") user_input = user_input_type("Would you like to fight or flee?\n") while user_input.strip().title() != "Fight" and user_input.strip( ).title() != "Flee": print("Was that in Pokemon language? I couldn't understand that!") user_input = user_input_type("Would you like to fight or flee?\n") if user_input.strip().title() == "Fight": print( "%s | HP: %s \nYou encountered %s! It's time for a Poke-Battle.\n" % (opponent["Name"], opponent["HP"], opponent["Name"])) combat_round(opponent) elif user_input.strip().title() == "Flee": potential_attack(opponent)
def test_roll_die_min(self): """Assert output is greater than or equal to min.""" self.assertGreaterEqual(roll_die(1, 103), 1)
def test_roll_die_range_max(self): """Assert output is less than or equal to max.""" self.assertLessEqual(roll_die(1, 8), 8)
def test_roll_die_random_output(self): """Assert random output.""" random.seed(56) self.assertEqual(roll_die(8, 100), 581) random.seed()
def test_roll_die_zero_rolls(self): """Assert output when number_of_rolls is 0.""" self.assertEqual(roll_die(0, 8), 0)
def test_roll_die_zero_sides(self): """Assert output when number_of_sides is 0.""" self.assertEqual(roll_die(4, 0), 0)
def test_roll_die_both_zero(self): """Assert output when both parameters are 0.""" self.assertEqual(roll_die(0, 0), 0)
def test_roll_die_output_type(self): """Assert output type.""" self.assertEqual(type(roll_die(1, 6)), int)