import random
class Player:
def __init__(self):
self.health = 100
self.ammo = 10
def is_alive(self):
return self.health > 0
class Zombie:
def __init__(self):
self.health = 50
def is_alive(self):
return self.health > 0
def game_loop():
player = Player()
zombies = [Zombie() for _ in range(5)]
while player.is_alive():
print "\nPlayer Health: " + str(player.health)
print "Ammo: " + str(player.ammo)
print "Zombies:"
for i, zombie in enumerate(zombies):
print str(i+1) + ". Health: " + str(zombie.health)
action = raw_input("\nWhat do you want to do? (shoot, run, quit): ")
if action.lower() == "shoot":
zombie_index = int(raw_input("Which zombie do you want to shoot? (1-5): ")) - 1
if zombies[zombie_index].is_alive():
zombies[zombie_index].health -= 20
player.ammo -= 1
print "You shot zombie " + str(zombie_index+1) + "!"
else:
print "That zombie is already dead!"
elif action.lower() == "run":
if random.random() < 0.5:
print "You successfully ran away!"
zombies = [Zombie() for _ in range(5)]
else:
print "You failed to run away!"
player.health -= 10
elif action.lower() == "quit":
print "Game over!"
break
else:
print "Invalid action!"
for zombie in zombies:
if zombie.is_alive():
player.health -= 5
print "A zombie attacked you!"
if not player.is_alive():
print "Game over! You died!"
break
game_loop()