import random
import time
# Character attributes
player_name = input("What's your cowboy name? ")
player_health = 100
player_accuracy = random.randint(70, 90)
enemy_name = "Wild Outlaw"
enemy_health = 100
enemy_accuracy = random.randint(60, 80)
# Function for dueling
def duel(player_name, player_accuracy, enemy_name, enemy_accuracy):
player_shot = random.randint(1, 100)
enemy_shot = random.randint(1, 100)
if player_shot <= player_accuracy:
print(f"{player_name} shoots and hits {enemy_name}!")
return True
else:
print(f"{player_name} misses the shot!")
return False
def enemy_duel(player_name, player_accuracy, enemy_name, enemy_accuracy):
player_shot = random.randint(1, 100)
enemy_shot = random.randint(1, 100)
if enemy_shot <= enemy_accuracy:
print(f"{enemy_name} shoots and hits {player_name}!")
return True
else:
print(f"{enemy_name} misses the shot!")
return False
# Main game loop
while player_health > 0 and enemy_health > 0:
print(f"\n{player_name}'s Health: {player_health} | {enemy_name}'s Health: {enemy_health}")
input("Press Enter to draw and shoot...")
player_shot = duel(player_name, player_accuracy, enemy_name, enemy_accuracy)
enemy_shot = enemy_duel(player_name, player_accuracy, enemy_name, enemy_accuracy)
if player_shot and not enemy_shot:
enemy_health -= random.randint(10, 20)
elif not player_shot and enemy_shot:
player_health -= random.randint(10, 20)
elif player_shot and enemy_shot:
print(f"You and {enemy_name} both hit your shots. It's a standoff!")
else:
print("Both missed the shots. It's a tense moment!")
time.sleep(1)
# Game outcome
if player_health <= 0 and enemy_health <= 0:
print("It's a draw. You both went down!")
elif player_health <= 0:
print(f"{player_name} is out of the game. {enemy_name} wins!")
else:
print(f"{enemy_name} is out of the game. {player_name} wins!")
print("The dust settles. The duel is over!")