Advertisement
Guest User

Referenced before assignment?

a guest
Jan 25th, 2015
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. name="blank"
  2. import os
  3.  
  4. #Set up all the processes and functions etc.
  5. #----------------------------------------------------------------
  6. def initLocations():
  7.     locName = ["The Town","The Blacksmith Hut","The Pub","The Street","The Library"]
  8.     locDesc = ["A Small Town","A Small Hut","A nice pub","An ancient paved street","Filled with brilliant books"]
  9.     return locName, locDesc
  10.  
  11. def initVariables():
  12.     global health
  13.     health=10
  14.     global currentLoc
  15.     currentLoc=0
  16.     return currentLoc, health
  17.  
  18. def gameInit():
  19.     initVariables()
  20.     initLocations()
  21.  
  22. def mainProcess(command):
  23.     if command=="help":
  24.         displayMessage("help")
  25.         pass
  26.     if command=="play":
  27.         gameInit()
  28.         pass
  29.     if command=="move":
  30.         displayMessage("move")
  31.         pass
  32.  
  33. def displayMessage(call):
  34.     os.system("cls")
  35.     if call=="help":
  36.         print("**HELP**")
  37.         print("")
  38.         print("The Adventure Game uses a system of commands")
  39.         print("Here is a list of currently known commands:")
  40.         print("")
  41.         print("- MOVE - Allows the player to move left or right")
  42.         print("")
  43.         input("Press any key to return....")
  44.         pass
  45.     if call=="move":
  46.         print("Move where?")
  47.         print("")
  48.         if currentLoc==0:
  49.             print("Left: You cannot move left.")
  50.             print("Right: " + locName[currentLoc+1])
  51.         elif currentLoc>1:
  52.             print("Left: " + locName[currentLoc-1])
  53.             print("Right: " + locName[currentLoc+1])
  54.         print("")
  55.         print("Move left or right? Enter your choice.")
  56.         direction = input("?: ")
  57.         if direction=="left":
  58.             print("Moved left.")
  59.             if currentLoc>1:
  60.                 currentLoc = currentLoc-1
  61.                 pass
  62.         elif direction=="right":
  63.             currentLoc = currentLoc+1
  64.             pass
  65.     pass
  66.     input("Press any key to return....")
  67.     os.system("cls")
  68. #----------------------------------------------------------------
  69.  
  70. #Main Game
  71.  
  72. print("Adventure Game")
  73. print("")
  74. print("Please enter your name: ")
  75. name = input("?: ")
  76.  
  77. while name=="":
  78.     os.system("cls")
  79.     print("* - Make sure you enter a name.")
  80.     print("")
  81.     print("Please enter your name: ")
  82.     name = input("?: ")
  83.     pass
  84.  
  85. print("Hello, " + name + "!")
  86. print("")
  87.  
  88. global currentLoc
  89. currentLoc, health = initVariables()
  90. gameInit()
  91. locName, locDesc = initLocations()
  92.  
  93.  
  94. #Let's say the final location is 20.
  95.  
  96. while currentLoc<20:
  97.     print(currentLoc)
  98.     #Locations
  99.     print(locName[currentLoc])
  100.     print(locDesc[currentLoc])
  101.  
  102.     print("Type 'Help' for advice on what to do next.")
  103.     passedCommand = input("?: ")
  104.     mainProcess(passedCommand)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement