OK, I just started learning Python & I never liked how people had the classes on same page everything else went on. So I placed them on another page, but sadly I don’t know how to actually get to them. I liked one of the tutorials I was doing and tried to make it more. I tried using import sounded good but still running into errors.
here is sketch, the main page that I don’t want the classes on
def setup():
size(600,600)
def draw():
background(0)
def fight(unit1,unit2):
round = 0;
if round == 0:
unit2.health -= unit1.attack
if unit2.health > 0:
round = 1;
else:
unit2.is_alive = false
if round == 1:
unit1.health -= unit2.attack
return True;
if unit1.health > 0:
round = 0;
else:
unit1.is_alive = false
return False;
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
chuck = Warrior()
bruce = Warrior()
carl = Knight()
dave = Warrior()
mark = Warrior()
assert fight(chuck, bruce) == True
assert fight(dave, carl) == False
assert chuck.is_alive == True
assert bruce.is_alive == False
assert carl.is_alive == True
assert dave.is_alive == False
assert fight(carl, mark) == False
assert carl.is_alive == False
for knight & warrior I know they short for now but I plan to add more later
here is knight.py
class Knight(Warrior):
attack = 7
here Warrior
class Warrior:
health = 50
is_alive = true;
attack = 5;