Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Jack3

New Coder
new to coding so if my code could be more simple ill take suggestions, anyway I'm doing text based RPG just as fun and I'm stuck on a piece of code, so what I want it to do is say if you have chosen Mage as you player class you wont be able lockpick the door or smash a window but you can use a spell on the door

playerName = input("What is your name traveler?")
playerClass = "player class"
validChoice = False
while not validChoice:
classType = int(input('''
What is your class?
*----------------*
| 1 for Archer |
| 2 for Warrior |
| 3 for Mage |
| 4 for Knight |
| 5 for Thief |
*----------------*
'''))
if classType == 1:
playerClass = "Archer"
validChoice = True
elif classType == 2:
playerClass = "Warrior"
validChoice = True
elif classType == 3:
playerClass = "Mage"
validChoice = True
elif classType == 4:
playerClass = "Knight"
validChoice = True
elif classType == 5:
playerClass = "Thief"
validChoice = True
else:
print("that wasn't a option dumbass")
# begin story and ask them to make a decision
validChoice = False
while not validChoice:
storyChoice = int(input('''
Greetings {} the {}
You arrive at a small village named NewHaven,
you enter the local tavern and sit at the bar,
the tavern owner asks what you would like to drink,
Do you:
*-------------------------*
| 1 Get a drink of water? |
| 2 Get a drink of mead? |
| 3 Get a drink of ale? |
*-------------------------*
'''.format(playerName, playerClass)))
# string formatting to add choices from before
if storyChoice == 1:
print("The tavern owner laughs at you and throws the glass at you and you die")
validChoice = False
elif storyChoice == 2:
print("The other people hear you in tavern and think your a viking and burn you alive")
validChoice = False
elif storyChoice == 3:
print("The tavern owner hands you a mug of ale and you begin to drink it")
validChoice = True
else:
print("That wasn't an option")
validChoice = False
while not validChoice:
storyChoice2 = int(input('''
While drinking you over hear a group of worriers,
fresh from battle with blood over there weapons and armour,
But not there's they mention of a man who died in his house but he was said to be rich,
he had gone mad from his old age and his wealth,
No one knows how he got the money,
But he apparently had set Traps so his spoilt children who took him for granted,
Would not be able to get the money his house was up the hill just out of the village you reach the house
Do you:
*--------------------------------*
| 1 Lock pick the door? |
| 2 Smash the window? |
| 3 Use a spell to open the door?|
*--------------------------------*
'''.format(playerName, playerClass)))
 
I am struggling a bit trying to think what exactly you're trying to achieve but I am thinking you need to have a clear idea what actions you will allow for each skill. Therefore you have a one to many relationship between skill (eg Mage) and allowable actions (eg cast spell). It is not clear whether this overlap between skills and allowable actions and if you do that you end up having to handle even more complicated data structures and at this stage I would suggest you initially keep things simple. If I was doing it I would use a dictionary to store that information but I am not sure if you have learned about those yet otherwise you could end up with thousands of if statements checking every possible skill versus allowable action and particularly if you end up with a lot of skills to keep track of.

One link I just googled might be https://www.w3schools.com/python/python_dictionaries.asp but I am sure there are others.
 
Last edited:
here's a solution, try implementing this on your code. I took your code and played with it a little.
below is the code for a class I made just to make it easier to create the characters. I suggest putting it in separate file and importing it.

Python:
class character:

    def __init__(self, name, special_ability, speed, strength):
        self.name = name
        self.special_ability = special_ability
        self.speed = speed
        self.strength = strength


Below is the remainder of your code tweeked it a little :D... hope it does what you asked, take note: it doesn't work without the code above:

Python:
from rpg01_Class_Types import character
import rpg01_Class_Types
playerName = input("What is your name traveler: ")
playerClass = ""
validChoice = False

def pick_class_type():
    classNum = int(input('''
                        What is your class?
                        *----------------*
                        | 1 for Archer |
                        | 2 for Warrior |
                        | 3 for Mage |
                        | 4 for Knight |
                        | 5 for Thief |
                        *----------------*
                        '''))

    if classNum == 1:
        archer = character("archer", "shoot arrow", 75, 32.25)
        return archer
    elif classNum == 2:
        warrior = character("warrior", "berzerk", 60, 80)
        return warrior
    elif classNum == 3:
        mage = character("mage", "magic", 30, 30)
        return mage
    elif classNum == 4:
        knight = character("knight", "shield", 55, 90)
        return knight
    elif classNum == 5:
        thief = character("thief", "stealth", 90, 40)
        return thief
    else:
        print("that wasn't an option")

classType =  pick_class_type()
print(classType.name.lower())

# begin story and ask them to make a decision
validChoice = False
while not validChoice:
    storyChoice = int(input(f'''
            Greetings {playerName} the {classType.name}
            You arrive at a small village named NewHaven,
            you enter the local tavern and sit at the bar,
            the tavern owner asks what you would like to drink,
            Do you:
            *-------------------------*
            | 1 Get a drink of water? |
            | 2 Get a drink of mead? |
            | 3 Get a drink of ale? |
            *-------------------------*
            '''))
    if storyChoice == 1:
        print("The tavern owner laughs at you and throws the glass at you and you die")
        validChoice = False
    elif storyChoice == 2:
        print("The other people hear you in tavern and think your a viking and burn you alive")
        validChoice = False
    elif storyChoice == 3:
        print("The tavern owner hands you a mug of ale and you begin to drink it")
        validChoice = True
    else:
        print("That wasn't an option")
        validChoice = False

validChoice = False
while not validChoice:
    storyChoice2 = int(input('''
    While drinking you over hear a group of worriers,
    fresh from battle with blood over there weapons and armour,
    But not there's they mention of a man who died in his house but he was said to be rich,
    he had gone mad from his old age and his wealth,
    No one knows how he got the money,
    But he apparently had set Traps so his spoilt children who took him for granted,
    Would not be able to get the money his house was up the hill just out of the village you reach the house
    Do you:
    *--------------------------------*
    | 1 Lock pick the door? |
    | 2 Smash the window? |
    | 3 Use a spell to open the door?
    | 4 cut a hole in the roof?
    | 5 break through the door?
    *--------------------------------*
    '''))
    if classType.name.lower() == "archer" and storyChoice2 != 1 and storyChoice2 != 2 and storyChoice2 != 4:
        print("you couldn't find a way in")
        validChoice = False
    elif classType.name.lower() == "warrior" and storyChoice2 != 4 and storyChoice2 != 2 and storyChoice2 != 5:
       print("you couldn't find a way in")
    elif classType.name.lower() == "mage" and storyChoice2 != 2 and storyChoice2 != 3:
        print("you couldn't find a way in")
    elif classType.name.lower() == "knight" and storyChoice2 != 5 and storyChoice2 != 2 and storyChoice2 != 4:
        print("you couldn't find a way in")
    elif classType.name.lower() == "thief" and storyChoice2 != 1 and storyChoice2 != 2:
        print("you couldn't find a way in")
    else:
        if storyChoice2 == 2:
            print("neighbours hear you break the glass, come out and kill you brutally")
        print("you got the riches")
        validChoice = True
 

Latest posts

Buy us a coffee!

Back
Top Bottom