Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game #27

Open
aman8603946661 opened this issue Apr 5, 2024 · 0 comments
Open

Game #27

aman8603946661 opened this issue Apr 5, 2024 · 0 comments

Comments

@aman8603946661
Copy link

aman8603946661 commented Apr 5, 2024

import random

class Player:
def init(self, name):
self.name = name
self.health = 100
self.position = (0, 0)

class BattlegroundGame:
def init(self, num_players):
self.players = [Player(f"Player {i+1}") for i in range(num_players)]
self.round = 1

def start_game(self):
    print("Welcome to the Battleground Game!")
    print(f"Starting with {len(self.players)} players.")
    self.play_rounds()

def play_rounds(self):
    while len(self.players) > 1:
        print(f"\nRound {self.round}:")
        self.play_round()
        self.round += 1
    print("\nGame Over!")
    print(f"{self.players[0].name} wins!")

def play_round(self):
    for player in self.players:
        if player.health <= 0:
            continue
        print(f"\n{player.name}'s turn:")
        self.attack(player)

def attack(self, attacker):
    target = random.choice([p for p in self.players if p != attacker and p.health > 0])
    damage = random.randint(10, 30)
    target.health -= damage
    print(f"{attacker.name} attacks {target.name} for {damage} damage.")
    if target.health <= 0:
        print(f"{target.name} has been eliminated!")

def main():
num_players = 50
game = BattlegroundGame(num_players)
game.start_game()

if name == "main":
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant