def damage_dealt(weapon_input, enemy, move): if move == 1: a = 1 else: a = 2 while True: print("\n-----========[BATTLE ROUND]========-----") alpha = randint(0, len(weapon_input["feedback"]) - 1) print() print(weapon_input["feedback"][alpha]) if (enemy["dodge"] - randint(1, 100)) < 0: damage = int((weapon_input["attributes"]["damage"] + randint(-5, 3))/a) player.in_battle_enemy_hp -= damage hp = player.in_battle_enemy_hp if hp <= 0: print("With the last blow you deal to your opponent" + "\nyou come out victorious as " + enemy["name"] + " is slain!") print(" ______________________________________________ _______________________________") print(" / __ ) / | /__ __/ /__ __/ / / / ____/ | | / / / __ \ / | / / / /") print(" / __ | / /| | / / / / / / / __/ | | /| / / / / / / / |/ / / / ") print(" / /_/ / / ___ | / / / / / /___ / /___ | |/ |/ / / /_/ / / /| / /_/ ") print("/_____/ /_/ |_| /_/ /_/ /_____/ /_____/ |__/|__/ \____/ /_/ |_/ (_) ") print() player.score += enemy["score"] print("You have earned: " + str(enemy["score"]) + " bits!") enter() return False else: print(enemy["name"] + " is still alive with " + str(hp) + " HP Left.") return True else: print("Your opponent dodges your attack.") return True
def main_fight(enemy): screen_flush() player.in_battle_enemy_hp = enemy["hp"] print_encounter() alpha = randint(0, len(encounter_fill) - 1) print("You have encountered " + enemy["name"] + encounter_fill[alpha]) print("You must fight " + enemy["name"] + " to proceed (you cannot save during battle).") print() while True: a = input("Heads or Tails (winner goes first)? ") normalise_input(a) while True: quit_test(a) if "tails" in a: a = 0 break elif "heads" in a: a = 1 break else: a = input("You have to choose between Heads and Tails: ") a = normalise_input(a) b = randint(0, 1) if b == a: screen_flush() print_encounter() print("You go first!") enter() while player.in_battle_enemy_hp >= 1: screen_flush() print_encounter() print_stats(enemy) weapon_choice = valid_weapon() move = move_prompt() # Damage_dealt would return FALSE if enemy is dead, therefore damage_got will not be further executed. if damage_dealt(weapon_choice, enemy, move): print() damage_got(enemy, move) if player.hp <= 0: raise GameOver enter() screen_flush() break else: screen_flush() print_encounter() print(enemy["name"] + " goes first!") enter() print() move = 1 while player.in_battle_enemy_hp >= 1: screen_flush() print_encounter() print_stats(enemy) print() damage_got(enemy, move) if player.hp <= 0: raise GameOver weapon_choice = valid_weapon() move = move_prompt() # Damage_dealt would return FALSE if enemy is dead, therefore damage_got will not be further executed. if damage_dealt(weapon_choice, enemy, move): enter() screen_flush() break