0

I'm building a text adventure game for one of my projects. I'm currently trying to make it so that only certain weapon options appear depending on which 'class' the player has previously selected. For eg. if the player has chosen ranger, only bow or dagger will appear. Regardless of what the player has chosen, only the warrior options appear. Any advice?

def preferred_weapon(player_class):
    """
    Player chooses their preferred weapon, each class has different options.
    """
    fprint("I'm sure you're strong in a fight, but if you had to choose, which weapon would be your preference?\n", 1)
    if player_class == "warrior" or "Warrior":
        fprint("Sword")
        fprint("or")
        fprint("Axe")
        while True:
            weapon = input(" ")
            weapons = ["sword", "Sword", "axe", "Axe"]
            if weapon in weapons:
                print(f"The mighty {weapon}, of course... of course.")
                break
            else:
                print("Please type one of the weapons listed.")
                continue
    elif player_class == "ranger" or "Ranger":
        fprint("Dagger")
        fprint("or")
        fprint("Bow")
        while True:
            weapon = input(" ")
            weapons = ["dagger", "Dagger", "bow", "Bow"]
            if weapon in weapons:
                print(f"The elegant {weapon}, of course... of course.")
                break
            else:
                print("Please type one of the weapons listed.")
                continue
    else:
        fprint("Staff")
        fprint("or")
        fprint("Spell Tome")
        while True:
            weapon = input(" ")
            weapons = ["staff", "Staff", "spell tome", "Spell Tome"]
            if weapon in weapons:
                print(f"The mystical {weapon}, of course... of course.")
                break
            else:
                print("Please type one of the weapons listed.")
                continue
    return weapon
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 2
    So, have an `armament` dictionary, where the key is the player type, and the value is a list of the valid weapons. Keep everything in lower case, and you will avoid the `x == a or b` bug. – Tim Roberts Oct 16 '22 at 23:06

0 Answers0