Untitled
unknown
plain_text
2 years ago
5.0 kB
17
Indexable
import random
class Player:
def __init__(self, name):
self.name = name
self.health = 100
self.inventory = []
def is_alive(self):
return self.health > 0
def take_damage(self, damage):
self.health -= damage
def heal(self, amount):
self.health += amount
def add_to_inventory(self, item):
self.inventory.append(item)
class Zombie:
def __init__(self, name, health, attack):
self.name = name
self.health = health
self.attack = attack
def is_alive(self):
return self.health > 0
def take_damage(self, damage):
self.health -= damage
def attack_player(self, player):
damage = random.randint(1, self.attack)
print(f"{self.name} attacks {player.name} for {damage} damage!")
player.take_damage(damage)
def main():
player_name = input("Enter your name: ")
player = Player(player_name)
zombies = [
Zombie("Student Zombie", 20, 5),
Zombie("Teacher Zombie", 30, 8),
Zombie("Principal Zombie", 50, 15)
]
print("Welcome to Zombie School Escape!")
print("You wake up to find your school overrun by zombies. You must escape!")
while player.is_alive():
zombie = random.choice(zombies)
print(f"\nYou encounter a {zombie.name}!\n")
while zombie.is_alive() and player.is_alive():
action = input("What will you do? (fight/flee) ").lower()
if action == 'fight':
player.attack_enemy(zombie)
if zombie.is_alive():
zombie.attack_player(player)
elif action == 'flee':
print("You try to flee from the zombie!")
flee_chance = random.random()
if flee_chance < 0.5:
print("You successfully escape!")
break
else:
print("You couldn't escape and the zombie catches up to you!")
zombie.attack_player(player)
else:
print("Invalid choice. Please choose 'fight' to attack or 'flee' to escape.")
if not player.is_alive():
print("Game Over. You have been caught by the zombies.")
break
else:
print(f"You defeated the {zombie.name}! You have {player.health} health remaining.")
print("Thanks for playing Zombie School Escape!")
if __name__ == "__main__":
main()import random
class Player:
def __init__(self, name):
self.name = name
self.health = 100
self.inventory = []
def is_alive(self):
return self.health > 0
def take_damage(self, damage):
self.health -= damage
def heal(self, amount):
self.health += amount
def add_to_inventory(self, item):
self.inventory.append(item)
class Zombie:
def __init__(self, name, health, attack):
self.name = name
self.health = health
self.attack = attack
def is_alive(self):
return self.health > 0
def take_damage(self, damage):
self.health -= damage
def attack_player(self, player):
damage = random.randint(1, self.attack)
print(f"{self.name} attacks {player.name} for {damage} damage!")
player.take_damage(damage)
def main():
player_name = input("Enter your name: ")
player = Player(player_name)
zombies = [
Zombie("Student Zombie", 20, 5),
Zombie("Teacher Zombie", 30, 8),
Zombie("Principal Zombie", 50, 15)
]
print("Welcome to Zombie School Escape!")
print("You wake up to find your school overrun by zombies. You must escape!")
while player.is_alive():
zombie = random.choice(zombies)
print(f"\nYou encounter a {zombie.name}!\n")
while zombie.is_alive() and player.is_alive():
action = input("What will you do? (fight/flee) ").lower()
if action == 'fight':
player.attack_enemy(zombie)
if zombie.is_alive():
zombie.attack_player(player)
elif action == 'flee':
print("You try to flee from the zombie!")
flee_chance = random.random()
if flee_chance < 0.5:
print("You successfully escape!")
break
else:
print("You couldn't escape and the zombie catches up to you!")
zombie.attack_player(player)
else:
print("Invalid choice. Please choose 'fight' to attack or 'flee' to escape.")
if not player.is_alive():
print("Game Over. You have been caught by the zombies.")
break
else:
print(f"You defeated the {zombie.name}! You have {player.health} health remaining.")
print("Thanks for playing Zombie School Escape!")
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment