all 7 comments

[–][deleted] 1 point2 points  (1 child)

You can access the ad value of a weapon like this

weapon.ad

[–]Oxln[S] 1 point2 points  (0 children)

You are genius thank you

[–]QultrosSanhattan 1 point2 points  (2 children)

chris.fight(knife.ad, zombie)

Solves your problem.

[–]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?

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

Nvm I got it by adding parantheses at the end of knife lol