Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Text Adventure
#1
So im working on a small little game but its becoming a pain in the ass to have to run through every line just to test one thing so i wanted to create a way to basically skip around from level to level. 
I feel like i got close but not close enough for it to work. 
heres the code. 
and you can see that i tried to create an almost goto simulator with the skipmod part but it wont work. Any suggestions? I also am not dedicated to making the while goto work so if you have any suggestions please list them.
import time
playerclass = "0"
playerhealth = 0
playerdamage = 0
playerspeed = 0
playerdefense = 0
playerrange = 0
op1 = 1
op2 = 1
op3 = 1
op4 = 1
level = 0
skip = 0
print("Hello player!")
print("Welcome to The Last Calling")


while (level == 0):
    print("Type start to begin")
    command1 = input("")
    if (command1.lower() == "start"):
        print("")
        print("Which Charcter Would you Like to Be?")
        level = "select"
        print (level)
        continue

    elif (command1.lower() == "skipmod"):
        print("")
        print("Where to?")
        skip = input("")
        if (skip == "2"):
            level = "2"
            continue
    
        while (level == "select"):
            print(" ________________________________________________")
            print("|Classes| Survivor |  Brute  | Assassin | Sniper |")
            print("|Health |     90   |   120   |     80   |    95  |")
            print("|Damage |     12   |    20   |     15   |    10  |")
            print("|Speed  |      3   |     2   |      4   |     2  |")
            print("|Defense|      7   |    10   |      5   |     5  |")
            print("|Range  |      2   |     1   |      3   |     5  |")
            print(" ⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻")
            print("1. Survivor")
            print("2. Brute")
            print("3. Assassin")
            print("4. Sniper")
            print("")
            charclass = input("")
                
            if (charclass == "1" or charclass == "2"  or charclass == "3"  or charclass == "4" ):
                if (charclass == "1"):
                    playerclass = "Survivor"
                elif (charclass == "2"):
                    playerclass = "Brute"
                elif (charclass == "3"):
                    playerclass = "Assassin"
                elif (charclass == "4"):
                    playerclass = "Sniper"
                    print("")
                print("Are you sure?")
                print("Yes")
                print("No")
                print("")
                sure = input("")            
            else:
                print("Select a valid option")
                print("")
                continue
                    
                    
            if (sure.lower() == "yes"):
                level = "2"
                while (level == "2"):
                    print("")
                    print("Select a name")
                    print("")
                    name = input("")
                    print("")
                    print(name + " Is that right?")
                    print("Yes")
                    print("No")
                    print("")
                    nameright = input("")
                    if (nameright.lower() == "yes"):
                        print("")
                        print("hello " + name + " the " + playerclass)
                        print("")
                        print("Would you like to start the game?")
                        startgame = input("")
                        if (startgame.lower() == "yes"):
                            print("A few pointers before you start your adventure.")
                            print("1. Permadeath is on (meaning if your health reaches 0 your dead.)")
                            print("2. To see your stats type in \"Hud\" when you finish the prologue")
                            print("3. You choose where you shoot but the more damage it does the less chance you have of hitting that shot")
                            print("so if you aim for the head it will do alot more damage than a shot to the arm or leg")
                            time.sleep(15)
                            print("Game loading")
                            print(".")
                            time.sleep(3)
                            print(".")
                            time.sleep(3)
                            print(".")
                            print("You wake up with hazy vision in a unfimiliar bed, you're vision isn't clear enough to see much but you see a figure across the room")
                            print(name + ": Where am I?")
                            input("Press enter")
                            print("Mysterious Voice: You've been sleeping for a while now. Good to see your well enough to talk after what you went through")
                            
                            
                            if (playerclass == "Survivor"):
                                playerhealth = 90
                                playerdamage = 12
                                playerspeed = 3
                                playerdefense = 7
                                level = "3"
                                
                            elif (playerclass == "Brute"):
                                playerhealth = 120
                                playerdamage = 20
                                playerspeed = 2
                                playerdefense = 10
                                level = "3"
                                
                            elif (playerclass == "Assassin"):
                                playerhealth = 80
                                playerdamage = 14
                                playerspeed = 4
                                playerdefense = 5
                                level = "3"

                            elif (playerclass == "Sniper"):
                                playerhealth = 95
                                playerdamage = 10
                                playerspeed = 2
                                playerdefense = 5
                                level = "3"
                                
                                
                            while (level == "3"):
                                
                                print("")
                                print("Select an option")
                                if (op1 != 0):
                                    print("1. Reach for your pistol")
                                if (op2 != 0):
                                    print("2. Ask who they are")
                                if (op3 != 0):
                                    print("3. Ask where you are")
                                if (op4 != 0):
                                    print("4. Stay silent")
                                print("")
                                choice = input()
                                if (choice == "1"):
                                    print("you reach for the holster you were wearing last you could remember but only feel flesh as you grab for your gun that is not there")
                                    input("Press Enter")
                                    print("Mysterious Voice: Had to make sure that you wouldn't try anything so I took your gun while you were knocked out")
                                    op1 = 0
                                elif (choice == "2"):
                                    print(name + ": Who are you?")
                                    input("Press Enter")
                                    print("Mysterious Voice: Just a good person or so it seems.")
                                    op2 = 0
                                elif (choice == "3"):
                                    print(name + ": You didn't answer my first question. Where am I?")
                                    input("Press Enter")
                                    print("Mysterious Voice: Somewhere safe")
                                    op3 = 0
                                elif (choice == "4"):
                                    op1 = 1
                                    op2 = 2
                                    op3 = 3
                                    op4 = 4
                                    print(name + ":...")
                                    input("Press Enter")
                                    print("Mysterious Voice: I didnt take you for the silent type but i guess you can't judge a book by its cover. Whatever, I'll leave you be. Ill be back later to check on you")
                                    input("Press Enter")
                                    print("")
                                    print("He left the room. What are you going to do?")
                                    level = "4"
                                else:
                                    print("Select a valid option")
                                    continue
                                    
                                while (level == "4"):
                                    print("1. Look for a weapon")
                                    print("2. Hide")
                                    print("3. Try to escape")
                                    print("4. Stay in bed")
                                    choice = input()
            else:
                print("Reselect your character")
                continue

           
                 
                    


            

    else:
        print("Im afraid that is not a command")
        continue
Reply
#2
When you run it, how it doesn't  work? Any error messages? Unexpected result?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
There is a tutorial on text adventures on the forums. It doesn't directly address your problem, but it gets at the basic problem: you are trying to do this as one huge if-then structure. As you are finding, that becomes a nightmare to deal with once it gets to any reasonable size.

If you build your map as a dictionary, getting to any particular place to test things is a simple as changing the starting location to the place you want to test.

If you build combat as a function which takes the player and the opponent as parameters, you can test combat without even going to a location. To make this work, you would want to put the player and the opponent into dictionaries, so they can be passed as one variable. You can then return the player (and maybe the opponent) dictionary to get their state after the combat.

Basically, the best thing to do is to modularize your code so that it's easier to deal with. The easiest way to do this is with functions and dictionaries. Even better is to use classes. There are tutorials on all of the is the Tutorials forum.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  loop adventure game ilikedofs 1 1,671 May-26-2021, 12:43 AM
Last Post: bowlofred
  how to make a hotkey for text adventure game myn2018 2 1,918 Jan-06-2021, 10:39 PM
Last Post: myn2018
  Choose your own adventure game noahc2004 2 2,523 Jun-26-2020, 02:06 PM
Last Post: DPaul
  Waiting in a text adventure StickyLizard 1 36,941 Jan-19-2019, 10:45 PM
Last Post: ichabod801
  Errors in simple text adventure game? ecloev 5 4,799 Apr-10-2018, 05:55 PM
Last Post: nilamo
  Need a little more help in a Choose Your Own Adventure Program Goldberg291 13 18,314 Jan-31-2017, 08:33 AM
Last Post: Ofnuts
  How do I shorten my input options? - text adventure ShiningKnight 3 4,624 Jan-01-2017, 03:21 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020