[Python] Conundrum in an RPG battle simulator

Discussão em 'Python' iniciado por Stack, Junho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to, as the title suggests, make an RPG battle simulator in Python. I have a few options for the player to do, but the problem is in the action 'spells'. It would show you the character's available spells and ask which one you want to use. However, if you were to say 'back', I want it to back out of that option and start the loop over. Here's what it looks like (The ellipses is a placeholder for a code segment that has no effect on what I want to do at the moment, keep in mind this is in a class):

    def Action(self):
    ...
    actionList = ["attack", "spells", "defend", "rest"]
    act = input(f"""What will {self.name} do? >""").lower() #choosing what to do
    while not act in actionList: #to make sure you do something you can
    act = input(f"""What will {self.name} do? >""").lower()

    if act == "spells": #spellcasting
    spellcast = input(f"""{self.spells} What spell should {self.name} cast? (type 'back' if none) >""").lower()
    while not spellcast in self.spells or spellcast != 'back':
    spellcast = input(f"""What spell should {self.name} cast? (type 'back' if none) >""").lower()
    if spellcast == 'back':


    Now, I'm fairly new to Python - I don't know much about the language, just some bare bones - so I'm kind of at a standstill here. If it was the only option you could select, I'd easily make the loop while not == 'back', but also if it was the only option, having the back option would be redundant since there would be no 'menu' for choosing what to do.

    Continue reading...

Compartilhe esta Página