Day 65 Solution

preview_player
Показать описание
These projects are getting tricky. Watch David do a code-along of the solution.

Рекомендации по теме
Комментарии
Автор

For the arguments in initiations ( _ _ init _ _ ( ) : ) I had to repeat all of the variables even though I had (self) before them in order for the program to run. Is it the way I'm formatting that is making me do this? Or a mistake in the way I formatted it?

EXAMPLE:

class character: #Need 1 plr 2 vampires 3 orcs
name = None
health = None
magicPoints = None
#values


def __init__(self, name, health, magicPoints): #initializing values
self.name = name
self.healh = health
self.magicPoints = magicPoints


class player(character):
def __init__(self, name, health, magicPoints, numberLives, alive):
self.name = name
self.healh = health
self.magicPoints = magicPoints
self.numberLives = numberLives
self.alive = alive

mariaxii
Автор

class character:
name = None
health = None
MP = None

def __init__(self, name, health, MP):
self.name = name
self.health = health
self.MP = MP

def printer(self):
print(f"Name: {self.name}")
print(f"Health: {self.health}")
print(f"Magic Points: {self.MP}")

class player(character):
def __init__(self, name, health, MP, lives, alive):
self.name = name
self.health = health
self.MP = MP
self.lives = lives
self.alive = alive

def printer(self):
print(f"Name: {self.name}")
print(f"Health: {self.health}")
print(f"Magic Points: {self.MP}")
print(f"Lives: {self.lives}")
print(f"Alive?: {self.alive}")

# never called enemy; vamp and orc inherit it
class enemy(character):
def __init__(self, name, health, MP, lives, type, strength):
self.name = name
self.health = health
self.MP = MP
self.lives = lives
self.type = type
self.strength = strength

def printer(self):
print(f"Name: {self.name}")
print(f"Health: {self.health}")
print(f"Magic Points: {self.MP}")
print(f"Lives: {self.lives}")
print(f"Type: {self.type}")
print(f"Alive?: {self.strength}")

class orc(enemy):
def __init__(self, name, health, MP, type, strength, speed):
self.name = name
self.health = health
self.MP = MP
self.type = type
self.strength = strength
self.speed = speed

def printer(self):
print(f"Name: {self.name}")
print(f"Health: {self.health}")
print(f"Magic Points: {self.MP}")
print(f"Type: {self.type}")
print(f"Strength: {self.strength}")
print(f"Speed: {self.speed}")

class vampire(enemy):
def __init__(self, name, health, MP, type, strength, time):
self.name = name
self.health = health
self.MP = MP
self.type = type
self.strength = strength
self.time = time

def printer(self):
print(f"Name: {self.name}")
print(f"Health: {self.health}")
print(f"Magic Points: {self.MP}")
print(f"Type: {self.type}")
print(f"Strength: {self.strength}")
print(f"Day/Night?: {self.time}")


human = player("Beatle", "100", "1", "9", "yes")
human.printer()
print()

orc1 = orc("Bill", "60", "5", "Orc", "75", "90")
orc1.printer()
print()

orc2 = orc("Ted", "75", "40", "Orc", "80", "45")
orc2.printer()
print()


vamp1 = vampire("Rishi", "70", "10", "Vampire 1", "3", "Day")
vamp1.printer()
print()


vamp2 = vampire("Boris", "45", "70", "Vampire 2", "75", "Night")
vamp2.printer()

vAccevt