Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- This file is used in a simple adventure game to teach the use of classes.
- To run this application you need 4 files:
- SimpleAdventureProgram.py: https://pastebin.com/jm9aHBWR
- (mimics C# Program.cs class with Main() function as entry point)
- SimpleAdventureLocation.py: https://pastebin.com/xREn6WB9
- (Class containing properties of exits to/from other locations, name and description)
- SimpleAdventureShared.py: https://pastebin.com/9hRT5XA2
- (Static class containing project-scope global variables and various methods)
- GetInput.py: https://pastebin.com/UceAJsaV
- (Static class with functions to get user input and display menus)
- '''
- import SimpleAdventureShared as Shared
- class Location:
- #constructor
- def __init__(self,
- name,
- displayName,
- description,
- locationToNorth = "",
- locationToEast = "",
- locationToSouth = "",
- locationToWest = ""):
- self._Name = name #string
- self._DisplayName = displayName #string
- self._Description = description #string
- self._LocationToNorth = locationToNorth #string
- self._LocationToEast = locationToEast #string
- self._LocationToSouth = locationToSouth #string
- self._LocationToWest = locationToWest #string
- @property
- def Name(self):
- return self._Name #string
- @property
- def DisplayName(self):
- return self._DisplayName #string
- @property
- def Description(self):
- return self._Description #string
- @property
- def LocationToNorth(self):
- return self._LocationToNorth #string
- @property
- def LocationToEast(self):
- return self._LocationToEast #string
- @property
- def LocationToSouth(self):
- return self._LocationToSouth #string
- @property
- def LocationToWest(self):
- return self._LocationToWest #string
- def Display(self):
- quit = False
- print("You are in " + self._DisplayName + ", " + self._Description)
- if self._LocationToNorth == "" and self._LocationToEast == "" and self._LocationToSouth == "" and self._LocationToWest == "":
- print ("\n" * 30)
- print("Well done, you have completed the adventure!")
- quit = True #trigger quit command
- else:
- if self._LocationToNorth != "":
- print("To the north is " + Shared.dictLocations[self._LocationToNorth].DisplayName)
- if self._LocationToEast != "":
- print("To the east is " + Shared.dictLocations[self._LocationToEast].DisplayName)
- if self._LocationToSouth != "":
- print("To the south is " + Shared.dictLocations[self._LocationToSouth].DisplayName)
- if self._LocationToWest != "":
- print("To the west is " + Shared.dictLocations[self._LocationToWest].DisplayName)
- return quit #bool
- def LocationList(self):
- return [self._LocationToNorth, self._LocationToEast, self._LocationToSouth, self._LocationToWest] # List of strings
- def SetLocations(self, locationToNorth, locationToEast, locationToSouth, locationToWest):
- #self-corrects for spaces e.g " " = "", "room " = "room"
- self._LocationToNorth = locationToNorth.strip()
- self._LocationToEast = locationToEast.strip()
- self._LocationToSouth = locationToSouth.strip()
- self._LocationToWest = locationToWest.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement