import random # Define the player's stats and behavior def player_turn(player_hp, player_exp, player_def, player_attack): print("\nYour turn!") print("[s] Attack with your sword") print("[a] Attack with your axe") print("[p] Drink a healing potion") print("[m] Attack with magic") print("[d] Defend with your shield") choice = input("Your choice? ").lower() if choice == 's': # Sword attack damage = random.randint(1, 20) + (player_exp // 100) # Sword damage + experience bonus print(f"You swing your sword! You deal {damage} damage.") return damage elif choice == 'a': # Axe attack damage = random.randint(5, 40) + (player_exp // 100) # Axe damage + experience bonus print(f"You swing your axe! You deal {damage} damage.") return damage elif choice == 'p': # Healing potion healing = 20 + (player_exp // 100) * 5 player_hp += healing print(f"You drink a healing potion and restore {healing} health.") return 0 elif choice == 'm': # Magic attack damage = random.randint(5, 35) + (player_exp // 100) * 10 # Magic attack damage print(f"You cast a magic spell! You deal {damage} damage.") return damage elif choice == 'd': # Defend with shield print("You raise your shield to defend!") return "defend" else: print("Invalid choice, try again.") return player_turn(player_hp, player_exp, player_def, player_attack) # Define the enemy's stats and behavior def enemy_turn(enemy_hp, enemy_def, enemy_attack): print(f"\n{enemy.name} attacks!") damage = random.randint(1, enemy_attack) # Enemy attacks with random damage if damage > enemy_def: damage_taken = damage - enemy_def print(f"{enemy.name} hits you for {damage_taken} damage!") return damage_taken else: print(f"{enemy.name}'s attack misses!") return 0 # Character class definition class Character: def __init__(self, name, hp, att, defense, move, exp): self.name = name self.hp = hp self.att = att self.defense = defense self.move = move self.exp = exp # Set up the player and the enemy def setup_game(): player_name = "Player" player_hp = 50 player_exp = 0 player_def = 13 player_attack = 10 # Increase health based on experience player_hp += (player_exp // 100) * 10 # Set up the enemy (Corvus Glaive as an example) enemy = Character("Corvus Glaive", 95, 4, 13, 20, 100) return player_name, player_hp, player_exp, player_def, player_attack, enemy def battle_loop(player_hp, player_exp, player_def, player_attack, enemy): while player_hp > 0 and enemy.hp > 0: print(f"\nHealth Levels: You: {player_hp}, {enemy.name}: {enemy.hp}") # Player's turn damage = player_turn(player_hp, player_exp, player_def, player_attack) if damage != "defend": if damage > enemy.defense: enemy.hp -= damage print(f"You deal {damage} damage to {enemy.name}.") else: print("You missed!") else: # Handle defending (enemy may attack back) if random.random() < 0.5: # 50% chance of rebounding damage rebound_damage = random.randint(1, 20) enemy.hp -= rebound_damage print(f"You successfully deflect the attack! Rebound damage: {rebound_damage}") else: print(f"You defended but took no damage.") # Check if the enemy is dead if enemy.hp <= 0: print(f"\n{enemy.name} has been defeated! You win!") break # Enemy's turn damage_taken = enemy_turn(player_hp, player_def, enemy.att) player_hp -= damage_taken if player_hp <= 0: print(f"You have been defeated by {enemy.name}!") break # Start the game player_name, player_hp, player_exp, player_def, player_attack, enemy = setup_game() print(f"Welcome, {player_name}. Prepare for battle!\n") battle_loop(player_hp, player_exp, player_def, player_attack, enemy)