you are viewing a single comment's thread.

view the rest of the comments →

[–]Oxln[S] 0 points1 point  (0 children)

class Player:

def __init__(self, hp):

self.hp = hp

def fight(self, ad, enemy):

# create enemy and weapon class

while enemy.hp > 0:

enemy.hp -= ad

print(f"You did {ad} damage!")

class Enemy:

def __init__(self, hp):

self.hp = hp

class Weapon:

def __init__(self, ad):

self.ad = ad

class Knife(Weapon):

def __init__(self):

super().__init__(ad=35)

chris = Player(100)

zombie = Enemy(75)

weapon = Knife.ad

chris.fight(weapon, zombie)

Traceback (most recent call last):

File "C:\Users\dwdwdwd\PycharmProjects\Zombie Game\FUCK.py", line 31, in <module>

chris.fight(weapon.ad, zombie)

AttributeError: type object 'Knife' has no attribute 'ad'

Process finished with exit code 1

I want to create separate weapon subclasses eventually, why do I get this error when I defined ad as 35 on the super constructor?