Advertisement
Inksaver

SimpleAdventureLocation

Oct 8th, 2017
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 KB | None | 0 0
  1. '''
  2. This file is used in a simple adventure game to teach the use of classes.
  3. To run this application you need 4 files:
  4. SimpleAdventureProgram.py:    https://pastebin.com/jm9aHBWR
  5.  (mimics C# Program.cs class with Main() function as entry point)
  6. SimpleAdventureLocation.py:    https://pastebin.com/xREn6WB9
  7.  (Class containing properties of exits to/from other locations, name and description)
  8. SimpleAdventureShared.py:    https://pastebin.com/9hRT5XA2
  9.  (Static class containing project-scope global variables and various methods)
  10. GetInput.py:   https://pastebin.com/UceAJsaV
  11.  (Static class with functions to get user input and display menus)
  12. '''
  13. import SimpleAdventureShared as Shared
  14.  
  15. class Location:
  16.     #constructor
  17.     def __init__(self,
  18.                  name,
  19.                  displayName,
  20.                  description,
  21.                  locationToNorth = "",
  22.                  locationToEast = "",
  23.                  locationToSouth = "",
  24.                  locationToWest = ""):
  25.        
  26.         self._Name = name                       #string
  27.         self._DisplayName = displayName         #string
  28.         self._Description = description         #string
  29.         self._LocationToNorth = locationToNorth #string
  30.         self._LocationToEast = locationToEast   #string
  31.         self._LocationToSouth = locationToSouth #string
  32.         self._LocationToWest = locationToWest   #string
  33.  
  34.     @property
  35.     def Name(self):
  36.         return self._Name #string
  37.  
  38.     @property
  39.     def DisplayName(self):
  40.         return self._DisplayName #string
  41.  
  42.     @property
  43.     def Description(self):
  44.         return self._Description #string
  45.  
  46.     @property
  47.     def LocationToNorth(self):
  48.         return self._LocationToNorth #string
  49.  
  50.     @property
  51.     def LocationToEast(self):
  52.         return self._LocationToEast #string
  53.  
  54.     @property
  55.     def LocationToSouth(self):
  56.         return self._LocationToSouth #string
  57.  
  58.     @property
  59.     def LocationToWest(self):
  60.         return self._LocationToWest #string
  61.  
  62.     def Display(self):
  63.         quit = False
  64.         print("You are in " + self._DisplayName + ", " + self._Description)
  65.         if self._LocationToNorth == "" and self._LocationToEast == "" and self._LocationToSouth == "" and self._LocationToWest == "":
  66.             print ("\n" * 30)
  67.             print("Well done, you have completed the adventure!")
  68.             quit = True #trigger quit command
  69.         else:
  70.             if self._LocationToNorth != "":
  71.                 print("To the north is " + Shared.dictLocations[self._LocationToNorth].DisplayName)
  72.             if self._LocationToEast != "":
  73.                 print("To the east is " + Shared.dictLocations[self._LocationToEast].DisplayName)
  74.             if self._LocationToSouth != "":
  75.                 print("To the south is " + Shared.dictLocations[self._LocationToSouth].DisplayName)
  76.             if self._LocationToWest != "":
  77.                 print("To the west is " + Shared.dictLocations[self._LocationToWest].DisplayName)
  78.         return quit #bool
  79.                    
  80.     def LocationList(self):
  81.         return [self._LocationToNorth, self._LocationToEast, self._LocationToSouth, self._LocationToWest] # List of strings
  82.        
  83.     def SetLocations(self, locationToNorth, locationToEast, locationToSouth, locationToWest):
  84.         #self-corrects for spaces e.g " " = "", "room " = "room"
  85.         self._LocationToNorth = locationToNorth.strip()
  86.         self._LocationToEast = locationToEast.strip()
  87.         self._LocationToSouth = locationToSouth.strip()
  88.         self._LocationToWest = locationToWest.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement