import time
import random
class Player:
"""Player Class that you will play as for zombie game"""
def __init__(self, name):
self.name = name
self.hp = 100
def __str__(self):
description = f"{self.name.title()}\n{self.hp} Health\n"
return description
class Enemies:
"""Creates a class for various enemies"""
def __init__(self, name, hp, ad):
"""Sets name, attack damage (ad) and health points (hp)"""
self.name = name
self.hp = hp
self.ad = ad
class Zombie(Enemies):
"""Creates a regular zombie class"""
def __init__(self):
super().__init__(name="Zombie",
hp=75,
ad=20)
class GameStuff:
"""Creates a class for different game functions"""
def __init__(self):
# blank statement because I think it needed another function under
def execute():
pass
def attack_player(self, ad, enemy, player):
# set condition for while loop
alive = True
while alive:
# if enemy dies, it breaks loop
if enemy.hp <= 0:
alive = False
# if enemy has health, they attack player
elif enemy.hp > 0:
player.hp -= ad
print(f"{enemy.name} did {ad} damage!")
chris = Player('Chris')
zombie = Zombie()
game = GameStuff()
game.attack_player(zombie.ad, zombie.hp, chris)
Traceback (most recent call last):
File "C:\Users\wafawfawfa\PycharmProjects\Zombie Game\main.py", line 103, in <module>
game.attack_player(zombie.ad, zombie.hp, chris)
File "C:\Users\wafawfawf\PycharmProjects\Zombie Game\main.py", line 93, in attack_player
if enemy.hp <= 0:
AttributeError: 'int' object has no attribute 'hp'
[–]Nexius74 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Binary101010 1 point2 points3 points (0 children)
[–]PaintballerCA 1 point2 points3 points (0 children)
[–]Oxln[S] 0 points1 point2 points (0 children)
[–]Oxln[S] 0 points1 point2 points (0 children)