Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PLS IMMEDIATELY HELP
#1
I am sorry that I had used all cap for this, however, this is an emergency situation. Can someone pls help me debug the following code for this game?
import time
import random
from random import randint

print("\n" *100)
print("\n\n[-STARFALL: By Jansen:-]")
print("\n\n\n----------------------")
print("\nWe are all like the bright moon, we still have our dark side.\n-Kahlil Gibran")
time.sleep(1)
print("\nStars,hide your fires;Let not light see my black and deep desires.\n-William Shakespeare, Macbeth")
time.sleep(1)
print("""\n\n\nThe land of shadow, is not something good for a mortal, but nonetheless,
you are here, and you must look for a way to get out of it. Since if you can't, you shall
lay dead just like many before you had.""")

def start():
      print("Choose Your Path Before You")
      time.sleep(1)
      print("\n1.) Go North(There is a huge tree that way).")
      print("2.) Go South(There is a small portal looming blue lights.)")
      print("3.) Go East(The Mass Tomb awaits you.)")
      print("4.) Go West(There is a hub in that direction, maybe someone friendly?)")
      print("5.) To The Throne Of Death")

      cmdlist = ["1","2","3","4","5"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            tree_o_life()
      elif cmd == "2":
            small_portal()
      elif cmd == "3":
            mass_tomb()
      elif cmd == "4":
            hotel_o_death()
      elif cmd == "5":
            reaper_throne()
      else:
            print("I don't understand what you have wrote. Pls try again.")
            start(inventory)

def tree_o_life():
      print("""After walking for several hours, you are exhausted and walks into the realm of the great tree,
a sign nearby wrote: Enter, Traveler, if you shall dear, One entrance shall grant you the eternal life on the ground
while the other shall forbidden you to enter the realm of living forever. The clue is, the left door have the
two Naaru in front of it. While one shall tell the truth, the other shall tell a lie, so which one shall you choose?""")
      print("\n1.) Question the left Naaru")
      print("2.) Question the right Naaru")
      print("3.) Go through the left door")
      print("4.) Go through the right door")

      cmdlist == ["1","2","3","4","5"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You ask the left Naaru, shall left door be the that led to death?")
            print("The Naaru answered yes.")
            tree_o_life()
      elif cmd == "2":
            print("You ask the right Naaru, shall left door be the one that led to death?")
            print("The Naaru answered no.")
      elif cmd == "3":
            print("You have entered the left portal, and you are swiftly sucked into it.")
            time.sleep(1)
            print("You fall into a coma by seeing so many bright things at once.")
            time.sleep(3)
            print("You have chosen the wrong door, You are doomed to wander around the realm of void.")
            dead()
      elif cmd == "4":
            print("You enter the right portal, and you are swiftly sucked into it.")
            time.sleep(1)
            print("A hand waved in front of you, and helped you up, you have enter the realm of living in the land of shadow, however, your quest is still not finished....")
            time.sleep(1)
            shadowland_fold_2()
      else:
            print("you have enter an illegal command, pls type in your command again.")
            tree_o_life()

def small_portal():
      print("""You decided to walk toward south, on your path to the small portal, you encountered a man in his 30s, he told you the following information: "In the realm of shadow,
or the shadowland, even the realm of living is not safe, you must battle your way through many dangerous dark creatures who served the reaper himself." He offered to teach you
the path of sword, do you like to learn it?""")
      print("\n1.) Yes.")
      print("2.) No.")
      print("3.) Ignore the man and continue walk toward the portal.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("The man teach you the secret of the sword art and give you his sword.")
            small_portal_2()
      elif cmd == "2":
            print("You politely refused the man of his offer, and he quietly walks away.")
            time.sleep(1)
            print("You decided to to continue advancing toward the small portal")
            small_portal_2()
      elif cmd == "3":
            print("You ignored the man and simply walks on.")
            small_portal_2()
      else:
            print("I don't understand what you have inputted, please type in the command again.")
            time.sleep(1)
            small_portal()

def small_portal_2():
      print("""After about 2 hours of walking, even though you felt weak from the shadow force that had been trying to invade your mortal soul, you had finally reached the small portal,
what will you do now?""")
      print("\n1.) Go through the portal.")
      print("2.) Have a good look around.")
      print("3.) Leave the portal and go back to the original point.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You got sucked through the small portal, what will await you on the other side?")
            time.sleep(1)
      elif cmd == "2":
            print("You have a good look around, and you found some interesting unidentified object.")
            print("You come back around to the portal.")
            small_port_2()
      elif cmd == "3":
            print("You decided to walk back to the original cross point, however, in the middle of your journey, the shadowforce finally corrupted your entire soul, and the reaper, who laughed and took away your soul.")
            dead()
      else:
            print("I don't understand the command, pls enter it again.")
            small_port_2()

def mass_tomb():
      print("""You slowly walked into the cemetry of death, a sign that had been hang up swirled lonely in the wind caught your attention,
it said: Enter, traveler, if you dare. Either you shall find the treasure, or you shall be swallowed, by the cemetry of death. So what is
your path? Enter, at your own risk.""")
      print("You decided to look back around, but the road you have come from had disappeared.")
      print("What would you do now?")
      print("\n1.) Go through the door.")
      print("2.) Run back into the darkness.")

      cmdlist == ["1","2"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You go through the creaking metal cemetry, only time can tell if you can get the treasure or shall you die.")
            cemetry_death()
      elif cmd == "2":
            print("You runs through the darkness, however, as you see the light in front of you, you suddenly just falled through a hole in the ground. What a pathetic attempt.")
            dead()
      else:
            print("I don't understand what you are saying, pls enter it again.")
            mass_tomb()

def hotel_o_death():
      print("""You slowly approach the hotel, however, you detect something is not right about the place, many elves are walking around the hotel, but they are simply wandering around without any eyesight or any consciousness.
what should you do right now?""")
      print("\n1.) Go through the hotel's door.")
      print("2.) Try to talk to one of the elves.")
      print("3.) Avoid the elves and look for items around.")

      cmdlist == ["1","2"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You decided to go into the hotel and sits at a desk. A elf girl walks up to you and ask what do you want.")
            hotel_o_death_1()
      elif cmd == "2":
            print("You walk up to one of the elves, however, before you can speak to it, it instantly leapt up and bite you in the neck, before you lost consciousness, you finally realized that they are zombies.")
            dead()
      elif cmd == "3":
            print("As you look around, you managed to find a elvish gold coin.")
            print("You return to the front door of the hotel.")
            hotel_o_death()
      else:
            print("I don't understand what have you input. Pls try again.")
            hotel_o_death()

def reaper_throne():
      print("""You approach the throne of reaper, the man sits on it leans his head in his palm, however, nearly all of his body is covered with a black robe. By his side, there is
a huge scythe, what can you do right now?""")
      print("\n1.) Approach the reaper's throne")
      print("2.) Go back to the orginal point.")

      cmdlist == ["1","2"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("As you approach, the reaper raised his head, and with a swift swing of his scythe, you falled just another victim to his prey.")
            dead()
      elif cmd == "2":
            print("You decided that you should probably walk back to the tree of life.")
            time.sleep(1)
            print("However, on the way, your body still fell victim to the shadowforce and dies.")
            dead()
      else:
            print("I don't understand what you have inputted, pls try again.")
            reaper_throne()

def shadow_fold_2():
      print("""Congrautlation, you have successfully avoided the fate of many before by choosing the correct door, it is a extremely simple logic, but shall you continue?
Lie before you, is the great vast land of the Shadowfold, where many monsters are thirsty for your very own blood. Will you be able to escape and appeal to Aslan before you
are devoured by one of them monsters?""")
      print("\n1.) charge toward a monster in the front.")
      print("2.) Sneak on the monster.")
      print("3.) Silently sneak away.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("The Monster laughed at your pathetic attempt and easily drags you in front of him and rip you to pieces with bare hand.")
            dead()
      elif cmd == "2":
            print("You silently sneak upon the monster, and with a stone, you managed to leapt up to deliever a fatal hit to the monster's temple.")
            print("You continues advancing toward Aslan.")
            shadowfold_3()
      elif cmd == "3":
            print("You managed to silently sneak away. However, how long can you continue hiding?")
            print("There are no more escape chances.")
            shadowfold_3()
      else:
            print("I don't understand your command, pls write it again.")
            shadow_fold_2()

def shadowfold_3():
      print("""You continue to advance forward, however, a man blocked your path. He asked you politely to go with him in order to meet his master,
would you, or would you not?""")
      print("\n1.) Go with the man.")
      print("2.) Refuse and go on.")
      print("3.) Try to slain him with a sword on the ground and loot.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You decided to go on with the man, but what would happen to you next?")
            castle()
      elif cmd == "2":
            print("You politely refuse the man and simply go on. He moved and lets you on.")
            shadowfold_4()
      elif cmd == "3":
            print("You picked a sword by your hand, however, the man saw it coming and slain you with a swift swing of a pistol")
            dead()
      else:
            print("I don't understand your command, is it that hard to enter a number that was presented to you?")
            shadowfold_3()

def castle():
      print("""You arrive at a grand castle, there is a man who is dressed very elaboratly standing on the castle wall, however, before you can reach the door, he raise his hand and brings it down and
you are shot down by a barrage of arrows.""")
      dead()

def shadowfold_4():
      print("""You continued on, as you watch in horror when you come upon the castle in your way and saw the brutal act of killing many others who are tricked by the man, you managed to reach
the palace of Aslan. As you advance, the guards blocked you from entering and demanded the name of person you want to see.""")
      print("\n1.) I wish to see Aslan.")
      print("2.) I wish to see Aslan, The Great Son Of The Great Emperor Of Sea.")
      print("3.) I wish to enter the palace.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You bluntly said the word, however they are unconvinced and drives you back around.")
            print("You decided to go back.")
            time.sleep(1)
            print("Your body just can't take the impact of shadowforce anymore, and you collapse.")
            dead()
      elif cmd == "2":
            print("You politely declared the words, and they pleasantly lets you in.")
            aslan()
      elif cmd == "3":
            print("The guards are furious at your word, and stabs in the chest with their spear. It is extremely sharp and you slowly collapse into a coma.")
            dead()
      else:
            print("I don't understand your command, but please, is it that hard to type numbers?")

def aslan():
      print("""You got inside the palace, and you saw a great figure sat on the throne. Angels with white wings sat around and sings a holy song,
that you don't understand at all. However, despite not being able to understand it, you feeled eternal peace. The figure reach out his hand and touch your
forehead, and you suddenly change into a robe of white, and was put into the crowd who are singing eternally of the glory of the god.""")
      win()

def hotel_o_death_1():
      print("""The girl handed you a menu, after looking for a while, you discovered three drinks you can buy, one will help you immediately gain immortality and goes back to the
mortal realm, while the other two will sent you to see the reaper immediately.There is only one clue, the most dangerous place is also the safest place to be.""")
      print("\n1.) The First Drink: Life Elixir.")
      print("2.) The Second Drink: Eternal Rose Sweet.")
      print("3.) The Third Drink: The Acheron Water.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You drink down the clear looking elixir, and it tasted quite bitter.")
            print("You began to feel a grip in the stomach.")
            print("Oh No! You fell victim to the Life Elixir which in true is the extremely poisnous water.")
            dead()
      elif cmd == "2":
            print("You decided that it was probably wise to enjoy a sweet drink even if you are going to die.")
            print("It tasted quite sweet, however, as you drink it down, your entire face began to bleed.")
            print("You have chosen the wrong drink and you fell yet another victim of the Hotel Of Death.")
            dead()
      elif cmd == "3":
            print("The Elf girl handed you the drink, and you paid with the elvish gold coin you found.")
            print("You gulp down the drink, and suddenly found it to be very sweet, and you began to shine. The others tried to grab you, however, you slowly raise up and returned to the mortal realm.")
            win()
      else:
            print("I can't understand what you are saying. Pls enter it again.")

def cemetry_death():
      print("""Despite the Green gas tried to hinder you away from the sign, you still managed somehow to find it. It said: In this cemetry, traveler, a wild, little roseflower was grown.
It will grant you the ability to leave the shadowland, however, can you find it?""")
      print("\n1.) Walk Straight")
      print("2.) Turn Left")
      print("3.) Turn Right")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You continued to walk straight, however, you immediately met a skeleton that did not hesistate to cut you to pieces.")
            dead(inventory)
      elif cmd == "2":
            print("You decided to turn left, it was a free path, and a sign said: You are farther away from the flower.")
            cemetry_left_1()
      elif cmd == "3":
            print("You decided to turn right, and it was a safe passage. A sign said: You are closer to the flower.")
            cemetry_right_1()
      else:
            print("I don't understand what you are saying. Pls enter it again.")
            cemetry_death()

def cemetry_left_1(inventory):
      print("Now you are stuck at a cross again. Where should you go?")
      print("\n1.) Straight Forward.")
      print("2.) Turn Left.")
      print("3.) Turn right.")
      print("4.) Go back.")

      cmdlist == ["1","2","3","4"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You began to walk straight foward, but you fall through a hole on the ground and into the void where you are trapped forever.")
            dead()
      elif cmd == "2":
            print("You managed to come to a sign that said: You are just one step away from the flower.")
            cemetry_left_2()
      elif cmd == "3":
            print("You bumped into a wall.")
            cemetry_left_1()
      elif cmd == "4":
            print("You went back to the starting point.")
            cemetry_death()

def cemetry_left_2():
      print("What should you do next?")
      print("\n1.) Go Forward.")
      print("2.) Go left.")
      print("3.) Go Right.")
      print("4.) Go Back.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("you walked into a huge plant that had swallowed you in one bite.")
            dead()
      elif cmd == "2":
            print("You walked into a wall that said: Oh NO! You must go back to the original place. This flower is one wall away!.")
            cemetry_left_2()
      elif cmd == "3":
            print("You walked into a wall. You have no choice but to come back to the same spot.")
            cemetry_left_2()
      elif cmd == "4":
            print("You managed to got back to the original spot.")
            cemetry_death()

def cemetry_right_1():
      print("What should you do next?")
      print("\n1.) Continue Forward.")
      print("2.) Follow the footstep on the ground.")
      print("3.) Go Back to the original spot.")

      cmdlist == ["1","2","3"]
      cmd == getcmd(cmdlist)

      if cmd == "1":
            print("You found the flower!")
            print("You slowly eat it, and managed to lift off the ground, and fly up to the mortal realm.")
            win()
      elif cmd == "2":
            print("You carefully followed the footstep.")
            print("As you continue, you felt something dripping on your head.")
            print("You raise your head, and you found a Tyrannsauraus staring at you.")
            print("You began to run, but you got swallowed in one bit.")
            dead()
      elif cmd == "3":
            print("You go back to the original spot.")
            cemetry_death()

def win():
      print("You managed to escape the shadow realm. You win.")
      print("Would you like to exit?")
      exit == input(">")
      if "yes" in exit or "Y" in exit:
            exit(0)
      else:
            start(inventory)

def dead():
      print("You failed to get out of the shadowland. Your soul shall forever suffer.")
      print("Would you like to play again?")
      exit = input(">")
      if "yes" in exit or "Y" in exit:
            exit(0)
      else:
            start(inventory)

def getcmd(cmdlist):
      cmd = input("\nexplorer")
      if cmd in cmdlist:
            return cmd
      else:
            print("\nInvalid command.")
            return getcmd(cmdlist)

start()
The shell screen would appear with the following:
([-STARFALL: By Jansen:-]



----------------------

We are all like the bright moon, we still have our dark side.
-Kahlil Gibran

Stars,hide your fires;Let not light see my black and deep desires.
-William Shakespeare, Macbeth



The land of shadow, is not something good for a mortal, but nonetheless,
you are here, and you must look for a way to get out of it. Since if you can't, you shall
lay dead just like many before you had.
Choose Your Path Before You

1.) Go North(There is a huge tree that way).
2.) Go South(There is a small portal looming blue lights.)
3.) Go East(The Mass Tomb awaits you.)
4.) Go West(There is a hub in that direction, maybe someone friendly?)
5.) To The Throne Of Death
Traceback (most recent call last):
File "D:\qwerty.py", line 427, in <module>
start()
File "D:\qwerty.py", line 26, in start
cmd == getcmd(cmdlist)
NameError: name 'cmd' is not defined)
Reply
#2
Did you mean to use = instead of ==?
Reply
#3
There is _way_ too much code here. Especially as a new programmer, you need to test your code as you write it instead of copy-pasting bad code.
Reply
#4
I would also mention that I am total newbie on Python, and doesn't really know how to do it. This code was also inferences from the online stack overflow. I would like to know how to start() in this program, and also how does getcmd(cmdlist) work. Thank you.(I might add that this is a last minute resort since I must do a presentation on this tmr.
Reply
#5
You need to learn Python - https://python-forum.io/Forum-Tutorials
You can't stitch SO code together unless you have some idea of what you're doing. If you don't know how to assign a variable, you need to go back to square one.

In any future posts, keep the code you post down to 5-10 lines - it should run and reproduce your problem.
I say this because with your deadline, back-and-forth with us will take too long. If you simplify your code, it will make it more like you can figure it out yourself, which is significantly faster.
(Lastly, I want to say you should not cut corners on your posts - a single additional back-and-forth because of not enough information will take longer than the time to make a good post.)
Reply


Forum Jump:

User Panel Messages

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