Untitled
unknown
plain_text
9 months ago
2.2 kB
6
Indexable
import random
class Player:
def __init__(self, name):
self.name = name
self.health = 100
self.inventory = []
def take_damage(self, damage):
self.health -= damage
if self.health < 0:
self.health = 0
print(f"{self.name} took {damage} damage! Health: {self.health}")
def heal(self, amount):
self.health += amount
if self.health > 100:
self.health = 100
print(f"{self.name} healed by {amount}. Health: {self.health}")
def add_item(self, item):
self.inventory.append(item)
print(f"{self.name} picked up: {item}")
def attack(self, other_player):
damage = random.randint(10, 30)
print(f"{self.name} attacks {other_player.name} for {damage} damage!")
other_player.take_damage(damage)
def is_alive(self):
return self.health > 0
def main():
print("Welcome to the Text-Based Battle Royale!")
print("Survive and be the last player standing!")
# Create players
players = [Player("Player1"), Player("Player2"), Player("Player3")]
alive_players = players.copy()
# Game loop
while len(alive_players) > 1:
print("\n--- New Round ---")
for player in alive_players:
if not player.is_alive():
continue
print(f"\n{player.name}'s turn (Health: {player.health})")
action = input("Choose action: [move, attack, heal, search]: ").lower()
if action == "move":
print(f"{player.name} moves to a new location.")
elif action == "attack":
target = random.choice([p for p in alive_players if p != player and p.is_alive()])
player.attack(target)
if not target.is_alive():
print(f"{target.name} has been eliminated!")
alive_players.remove(target)
elif action == "heal":
heal_amount = random.randint(10, 25)
player.heal(heal_amount)
elif action == "search":
items = ["bandage", "ammo", "shield"]
found_item = random.choice(items)
player.addEditor is loading...
Leave a Comment