D4 #100DaysOfCode Challenge

Day 4 of my #100DaysOfCode Challenge!

Read Time56Seconds

New project time!

So I wanted to tackle Python classes, so why not make a text based adventure game!

So far it does not have a name or a story, but it does have classes! Check out the below GIF to see it in action.

So below is my current code for my game.

class Archer():
        ArcherAttack = 6
        ArcherHealth = 8
        ArcherDefense = 3

class Wizard():
        WizardAttack = 7
        WizardHealth = 8
        WizardDefense = 2

# Hero aka the Player
class Hero:
    def __init__(self, HeroName, HeroClass, HeroAttack, HeroHealth, HeroDefence):
        self.HeroName = HeroName
        self.HeroClass = HeroClass
        self.HeroAttack = HeroAttack
        self.HeroHealth = HeroHealth
        self.HeroDefence = HeroDefence
    
    def description(self):
        print(f"Hello {self.HeroName} you are an {self.HeroClass}. You have {self.HeroAttack} Attack Points, {self.HeroAttack} Health and {self.HeroDefence} Defence ")

PlayerName = input("Enter Player Name: ")
PlayerClass = "NoClass"
while True:
    PlayerClass = "NoClass"
    PlayerClass = input("Enter Class (Archer, Wizard)")
    if PlayerClass == "Archer":
        PlayerAttack = Archer.ArcherAttack
        PlayerHealth = Archer.ArcherHealth
        PlayerDefence = Archer.ArcherDefense
        Player = Hero(PlayerName, PlayerClass, PlayerAttack, PlayerHealth, PlayerDefence)
        Player.description()
        break
    elif PlayerClass == "Wizard":
        PlayerAttack = Wizard.WizardAttack
        PlayerHealth = Wizard.WizardHealth
        PlayerDefence = Wizard.WizardDefense
        Player = Hero(PlayerName, PlayerClass, PlayerAttack, PlayerHealth, PlayerDefence)
        Player.description()
        break
    else:
        print("Please select a correct class")
0 0
100 %
Happy
0 %
Sad
0 %
Excited
0 %
Angry
0 %
Surprise

Leave a Reply

Your email address will not be published. Required fields are marked *

Close