D10d3

game.py

Nov 13th, 2016
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. os.system('cls')
  3. import random
  4. import game_engine
  5. import game_data
  6.  
  7.  
  8. class game_loop(object): #Game loop
  9.     def __init__(self):
  10.         self.player = game_data.player() #player data
  11.         self.items = game_data.items() #all Gear,Inventory, and static items
  12.         self.map = game_data.map()          #rooms superclass
  13.         self.system = game_data.system()    #engine data
  14.         self.words = game_data.words()
  15.         self.location = self.map.starting_room #starting location
  16.        
  17.  
  18.     def play(self):
  19.         #instanced methods
  20.         engine = game_engine.engine() #engine classes
  21.         parser = game_engine.parser() #parser classes
  22.         last_input = "look here"
  23.         while True:
  24.             engine.describe_room(self.location,self.system,self.items)         
  25.             #get user input, then break it down into a list of words
  26.             input = raw_input("Command?> ")
  27.             if input == "g":
  28.                 input = last_action
  29.             last_action = input
  30.             action = parser.break_words(input)
  31.             nouns = []
  32.             verb = ""
  33.             event = ""
  34.             #now run the input list against a number of word checkers in the parser
  35.             recognized = parser.recognized(action)              #returns error message if all words unknown
  36.             if recognized == True:
  37.                 nouns = parser.get_nouns(action,self.location,self.items,self.player)#get nouns from input
  38.                 verb = parser.get_verb(action)
  39.                 profanity = parser.profanity(action)    #swearing?
  40.                 look_at = parser.look_at(verb,nouns,self.location,self.items,self.player)   #looking at an object?
  41.                 #begin events
  42.                 event = engine.event_handler(self.location,self.items,self.player,self.words,nouns,verb) #checks events
  43.                 if event == "get" or "drop":
  44.                     engine.inventory(event,self.location,self.items,self.player,nouns,verb)
  45.                 if event == "put" or "get from":
  46.                     engine.place_item(event,self.location,self.items,self.player,nouns,verb)
  47.                    
  48.                 self.location = parser.exit(action,self.location,self.system,self.map)  #moving to another room?
  49.                 system = parser.system(self.system,verb)        #system command?
  50.                 if system: #if parser.system receives "restart" it sets system to True
  51.                     restart = game_loop() #creates new game_loop instance
  52.                     restart.play() #starts new game loop
  53.             print""
  54.            
  55.  
  56. start = game_loop() #instantiate game_loop
  57. start.play() #start game loop
RAW Paste Data