import random
class Player:
def __init__(self, id, team, max_health, attack, heal):
self.id = id
self.team = team
self.max_health = max_health
self.current_health = max_health
self.attack = attack
self.heal = heal
self.money = 0
def is_dead(self):
return self.current_health <= 0
def action(self, players):
targets = [p for p in players
if (p.team != self.team and not p.is_dead())]
teammates = [p for p in players
if (p.team == self.team and not p.is_dead())]
if random.random() > 0.5:
target = random.choice(targets)
target.receive_damage(self.attack)
print(f"Player {self.id} from Team {self.team} attacked Player {target.id} from Team {target.team}")
else:
teammate = random.choice(teammates)
teammate.receive_healing(self.heal)
print(f"Player {self.id} from Team {self.team} healed Player {teammate.id} from Team {teammate.team}")
def receive_damage(self, damage):
self.current_health -= damage
if self.current_health < 0:
self.current_health = 0
def receive_healing(self, healing):
self.current_health += healing
if self.current_health > self.max_health:
self.current_health = self.max_health
def __str__(self):
return f"Player {self.id} (Team {self.team}): {self.current_health}/{self.max_health}"
def main():
print("Enter the number of players and teams:")
num_players = int(input("Number of players: "))
num_teams = int(input("Number of teams: "))
players = []
for i in range(num_players):
team = i % num_teams
max_health = 100
attack = random.randint(10, 30)
heal = random.randint(5, 15)
players.append(Player(i, team, max_health, attack, heal))
round = 1
while True:
print(f"\nRound {round}")
for player in players:
print(player)
living_players = [p for p in players if not p.is_dead()]
teams_alive = set(p.team for p in living_players)
if len(teams_alive) <= 1:
break
for player in living_players:
player.action(players)
round += 1
print(f"\nTeam {teams_alive.pop()} wins!")
if __name__ == "__main__":
main()