import random
class Boxer:
def __init__(self, name):
self.name = name
self.strength = random.randint(60, 100)
self.speed = random.randint(60, 100)
self.stamina = random.randint(60, 100)
self.wins = 0
self.losses = 0
def get_overall(self):
return (self.strength + self.speed + self.stamina) / 3
def __str__(self):
return (f"{self.name}: Strength={self.strength}, Speed={self.speed}, "
f"Stamina={self.stamina}, Wins={self.wins}, Losses={self.losses}")
class Fight:
def __init__(self, boxer1, boxer2):
self.boxer1 = boxer1
self.boxer2 = boxer2
def simulate(self):
print(f"\nSimulating fight between {self.boxer1.name} and {self.boxer2.name}...")
b1_score = (
self.boxer1.strength * random.uniform(0.8, 1.2) +
self.boxer1.speed * random.uniform(0.8, 1.2) +
self.boxer1.stamina * random.uniform(0.8, 1.2)
)
b2_score = (
self.boxer2.strength * random.uniform(0.8, 1.2) +
self.boxer2.speed * random.uniform(0.8, 1.2) +
self.boxer2.stamina * random.uniform(0.8, 1.2)
)
print(f"{self.boxer1.name} Score: {b1_score:.2f}")
print(f"{self.boxer2.name} Score: {b2_score:.2f}")
if b1_score > b2_score:
winner = self.boxer1
loser = self.boxer2
else:
winner = self.boxer2
loser = self.boxer1
winner.wins += 1
loser.losses += 1
print(f"Winner: {winner.name}")
return winner
class Tournament:
def __init__(self, boxers):
self.boxers = boxers
self.rounds = []
def organize(self):
random.shuffle(self.boxers)
while len(self.boxers) > 1:
next_round = []
print("\n--- New Round ---")
for i in range(0, len(self.boxers), 2):
if i + 1 < len(self.boxers):
fight = Fight(self.boxers[i], self.boxers[i+1])
winner = fight.simulate()
next_round.append(winner)
else:
print(f"{self.boxers[i].name} advances to the next round by default.")
next_round.append(self.boxers[i])
self.boxers = next_round
print(f"\nTournament Winner: {self.boxers[0].name}")
def display_scoreboard(boxers):
print("\n--- Scoreboard ---")
sorted_boxers = sorted(boxers, key=lambda b: b.wins, reverse=True)
for boxer in sorted_boxers:
print(f"{boxer.name} - Wins: {boxer.wins}, Losses: {boxer.losses}")
def main():
print("Welcome to the Boxing Tournament Game!")
# Create boxers
player_name = input("Enter your boxer's name: ")
player_boxer = Boxer(player_name)
opponents = [
Boxer("Rocky"),
Boxer("Apollo"),
Boxer("Clubber"),
Boxer("Drago")
]
all_boxers = [player_boxer] + opponents
# Display boxers
print("\n--- Boxers ---")
for boxer in all_boxers:
print(boxer)
# Create and organize a tournament
tournament = Tournament(all_boxers)
tournament.organize()
# Display the scoreboard
display_scoreboard(all_boxers)
if __name__ == "__main__":
main()
code
Welcome to the Boxing Tournament Game!
Enter your boxer's name: Thunder
--- Boxers ---
Thunder: Strength=85, Speed=76, Stamina=67, Wins=0, Losses=0
Rocky: Strength=68, Speed=95, Stamina=80, Wins=0, Losses=0
Apollo: Strength=77, Speed=64, Stamina=73, Wins=0, Losses=0
Clubber: Strength=88, Speed=79, Stamina=90, Wins=0, Losses=0
Drago: Strength=91, Speed=84, Stamina=85, Wins=0, Losses=0
--- New Round ---
Simulating fight between Rocky and Apollo...
Rocky Score: 223.45
Apollo Score: 162.10
Winner: Rocky
Simulating fight between Drago and Clubber...
Drago Score: 235.67
Clubber Score: 196.34
Winner: Drago
Thunder advances to the next round by default.
--- New Round ---
Simulating fight between Rocky and Drago...
Rocky Score: 210.89
Drago Score: 245.56
Winner: Drago
Simulating fight between Thunder and Thunder...
Thunder Score: 192.33
Thunder Score: 192.33
Winner: Thunder
--- New Round ---
Simulating fight between Drago and Thunder...
Drago Score: 220.44
Thunder Score: 180.22
Winner: Drago
Tournament Winner: Drago
--- Scoreboard ---
Drago - Wins: 3, Losses: 0
Rocky - Wins: 1, Losses: 1
Thunder - Wins: 1, Losses: 1
Apollo - Wins: 0, Losses: 1
Clubber - Wins: 0, Losses: 1