def first_fighter(): """ See which of two fighters go first by comparing random roll numbers. Simulates rolling a die for each character and compares the two values. The player with the higher die roll goes first. :Postcondition: Returns a string that can be used in conditional statements in the combat_round function to determine the next step in the battle, specifically which fighter goes first. :return: A string. """ # See who goes first by rolling a die. input("Press enter to roll to see who goes " "first.") opponent1_roll = roll_die(1, 20) print("Player rolled", opponent1_roll) opponent2_initial_roll = roll_die(1, 20) print("Enemy rolled", opponent2_initial_roll) step = 1 if opponent1_roll == opponent2_initial_roll: print("Tie! Roll again!") elif opponent1_roll > opponent2_initial_roll: print("Player goes first!!!") step = "player first attack" else: print("Enemy goes first!!") step = "enemy first attack" return step
def player_deal_damage(enemy_stats: dict, enemy_name: str): """ Determine how much damage the player inflicts on the enemy. :param enemy_stats: An dictionary :param enemy_name: A string. :postcondition: Will reduce the enemy's health by a certain amount if the player successfully hits. :return: """ input("Roll to see how much damage you do.") damage_inflicted = roll_die(1, 5) # Subtract the damage from the enemy's initial health to get their remaining health. enemy_stats["Health"] -= damage_inflicted # If their remaining health is above zero, # They survive and now it is their turn. if enemy_stats["Health"] > 0: print(f"The {enemy_name} lost {damage_inflicted} HP!!") step = "enemy retaliates" # If their health reaches zero they are dead and the battle is over. else: print(f"You kill the {enemy_name}!") step = "over" return step
def player_deal_damage2(enemy_stats: dict, enemy_name: str): """ Decide how much damage the player's attack does. Randomly chooses an integer from one to five and subtracts that amount from the enemy's health stat. :param enemy_stats: A dictionary with a 'Health' key. This function returns what the next step. :param enemy_name: A string :postcondition: a string saying the round is over. :return: a string. """ input("Roll to see how much damage you do.") damage_inflicted = roll_die(1, 10) # Subtract the damage from the enemy's initial health to get their remaining health. enemy_stats["Health"] -= damage_inflicted # If their remaining health is above zero, # They survive and now it is their turn. if enemy_stats["Health"] > 0: print(f"The {enemy_name} lost {damage_inflicted} HP!!") step = 1 return step # If their health reaches zero they are dead and the battle is over. else: print(f"You kill the {enemy_name}.") step = "over" return step
def enemy_deal_damage2(your_stats: dict, enemy_name: str): """ Decide how much damage the enemy attack does. Randomly chooses an integer from one to five and subtracts that amount from the player's health stat. :param your_stats: A dictionary with a 'Health' key. This function returns what the next step. :param enemy_name: A string :postcondition: a string saying the round is over. :return: a string. """ damage_inflicted = roll_die(1, 5) your_stats["Health"][1] = (your_stats["Health"][1] - damage_inflicted) # If your remaining health is above zero, state how much health was lost # Now it's your turn. if your_stats["Health"][1] > 0: print("You lost " + str(damage_inflicted) + " HP!!\nYou stumble back, dazed.") step = 1 # If your health reaches zero, you are dead and the round is over. else: print(f"The {enemy_name} kills you.") step = "over" return step
def flee(player: dict, enemy: str): """ Describes the player running away from the enemy. There is a 10% chance the enemy will attack the player and inflict damage if the player tries to flee. :param player: a dictionary. :param enemy: a string. :precondition player: must have the key "Health" attached to a list of at least two integers as a key, value pair. :precondition enemy: must be a string. """ print("You decide to flee") # There's a 10% chance the enemy will hit you when you run away. enemy_attack = roll_die(1, 10) if enemy_attack == 1: damage = (roll_die(1, 4)) player["Health"][1] -= damage print(f"The {enemy} strikes you as you flee. You lost {damage} HP!") else: print("The enemy tries to strike you, but you get away!")
def enemy_appear(): """ Cause an enemy to appear 25% of the time this function is called. :postcondition: returns True if an enemy appears and False if the enemy does not. :return: a boolean. """ enemy_appearance = roll_die(1, 4) if enemy_appearance == 1: return True else: return False
def test_roll_die_lowerbound(self): value = roll_die(3, 6) self.assertTrue(value >= 3)
def test_roll_die_upper_bound(self): value = roll_die(3, 6) self.assertTrue(value <= 18)
def test_roll_die_negative(self): self.assertEqual(0, roll_die(-3, -2))
def test_roll_die_zero(self): self.assertEqual(0, roll_die(0, 0))