D5 #100DaysOfCode Challenge

Day 5 of my #100DaysOfCode Challenge!

Read Time2 Minutes, 52 Seconds

So I’ve been doing a fair bit of work on my adventure game and I noticed that I was using the classes wrong… well I wasn’t even using them…

Now that I am using them correctly they are making more sense. I am finding it cleaner to create most of my program as functions and just link them to other functions when needed, this means I can call the ‘main()’ function, and away the program goes. It also allows me to make changes easier.

Here is a GIF of my current program.

Game breakdown

So at this moment you can choose two classes that have set stats, then your starting coin is based off a random int between 1 and 250, you start poor or rich.

The Inns beers price is between 1 and 5 and each time you buy a beer you give away your coins (Coins will have more use later on).

If you don’t have another drink the Barkeep will ask you what you are doing, this will trigger the quest phase.

Current Code

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

Player = Hero
BeerCost = random.randint(1,5)
# Player Classes
class Archer():
        ArcherAttack = 6
        ArcherHealth = 8
        ArcherDefense = 3

class Wizard():
        WizardAttack = 7
        WizardHealth = 8
        WizardDefense = 2
#Player Classes end.
def Coin():
    print("Time to see how much gold you start with!")
    print("Calculating")
    time.sleep(2.0)
    print("Calculating some more!")
    time.sleep(2.0)
    Hero.HeroCoin = random.randint(1,250)
    print(f"You start with {Hero.HeroCoin} coin/s")

def quest():
    print(f"Barkeep: So what big adventure are you preparing for {Player.HeroName}? *The Barkeep looks over to your backpack*")
    time.sleep(2.0)
    print("1. I'm going to go out to the Ethril Forests, heard there's a bounty for a few bandits out there")
    PlayerResponeBarkeep = input("Make a choice: 1 | 2")
    if PlayerResponeBarkeep == "1":
        print("Barkeep: Ethril aye, well you better get going soon then *The Barkeep looks out the Window at the sun as it lowers behind the trees*")

def main():
#Player Creation.
    Player.HeroName = input("Enter Player Name: ")
    Coin()
    while True:
        Player.HeroClass = input("Enter Class (Archer, Wizard)").capitalize()
        if Player.HeroClass == "Archer":
            Player.HeroAttack = Archer.ArcherAttack
            Player.HeroHealth = Archer.ArcherHealth
            Player.HeroDefence = Archer.ArcherDefense
            Player.description(Player)
            break
        elif Player.HeroClass == "Wizard":
            Player.HeroAttack = Wizard.WizardAttack
            Player.HeroHealth = Wizard.WizardHealth
            Player.HeroDefence = Wizard.WizardDefense
            Player.description(Player)
            break
    else:
        print("Please select a correct class")
    while True:
        beerChoice = input(f"Barkeep: Another round {Player.HeroName}? (1 = Yes, 2 = No, 3 = How much?):")
        if beerChoice == "1":     
            NewBeer()
        elif beerChoice =="2":
            quest()
        elif beerChoice == "3":
            print(f"Barkeep: {BeerCost} coins")  
        else:
            print("Make a choice")

def NewBeer():
    Player.HeroCoin >= BeerCost
    print(f"*You grab {BeerCost} coins out of your bag and slide them over to the Barkeep*")
    Player.HeroCoin -= BeerCost
    if Player.HeroCoin < BeerCost:
        print("You Don't have enough coins")
        main()
    time.sleep(2.0)
    print(f"You have {Player.HeroCoin} coins")
    time.sleep(2.0)
    print(f"*The Barkeep grabs your empty glass and begins cleaning it with a cloth tucked into his belt*")
    time.sleep(2.0)
    print(f'*The Barkeep fills the glass with beer, and wipes of the excess foam*')
    time.sleep(2.0)
    print("*You drink your beer")
    time.sleep(2.0)
    print("*You finish your beer*")
    

if __name__ == "__main__":
    main() 

  

   







1 0

About Post Author

Nick

0 %
Happy
0 %
Sad
0 %
Excited
0 %
Angry
0 %
Surprise

Leave a Reply

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

Close