Untitled
Anonymous
plain_text
03/04/2026 8:25 AM
2.1 KB
11
Indexable
import random
# Player setup
class Player:
def __init__(self, name):
self.name = name
self.hp = 100
self.inventory = []
self.alive = True
def attack(self, other):
if not self.alive: return
damage = random.randint(10, 25)
other.hp -= damage
print(f"{self.name} hits {other.name} for {damage} HP!")
if other.hp <= 0:
other.alive = False
print(f"{other.name} has been eliminated!")
def heal(self):
if "medkit" in self.inventory:
self.hp += 30
self.inventory.remove("medkit")
print(f"{self.name} heals to {self.hp} HP!")
# Game setup
players = [Player("Player1"), Player("Player2"), Player("Player3")]
items = ["medkit", "shield", "weapon"]
# Safe zone shrinking
zone_size = 100
while sum(p.alive for p in players) > 1:
zone_size -= 10
print(f"Safe zone shrinks to {zone_size}m!")
for p in players:
if p.alive:
action = random.choice(["attack", "heal", "loot"])
if action == "attack":
target = random.choice([x for x in players if x != p and x.alive])
p.attack(target)
elif action == "heal":
p.heal()
elif action == "loot":
item = random.choice(items)
p.inventory.append(item)
print(f"{p.name} loots a {item}!")
winner = [p for p in players if p.alive][0]
print(f"{winner.name} wins the battle royale!")Editor is loading...
Leave a Comment