adventure-game #3

Open
Kenwood wants to merge 80 commits from adventure-game into master
2 changed files with 40 additions and 17 deletions
Showing only changes of commit ebd518dd01 - Show all commits

View File

@ -29,12 +29,16 @@ class GameNavigator(npyscreen.FormBaseNew):
self.logBox.value = res # Set the logbox to that value self.logBox.value = res # Set the logbox to that value
def update_location(self, location): def update_location(self, location, art=None):
""" """
This may not be needed in the future, dynamic This may not be needed in the future, dynamic
handling of location is something the navigator should do and should inherit from player. handling of location is something the navigator should do and should inherit from player.
""" """
self.artBox.footer = location self.artBox.footer = location
if art != None:
self.artContent.value = art
else:
self.artContent.value = self.parentApp.gamelib['menu']['graphics']['not_found']
def update_inventory(self, items): def update_inventory(self, items):
res = '' res = ''
@ -62,7 +66,7 @@ class GameNavigator(npyscreen.FormBaseNew):
relx=inventory_width + 2, relx=inventory_width + 2,
max_width=art_width - 2, max_width=art_width - 2,
max_height=top_division_height - 2, max_height=top_division_height - 2,
value=self.parentApp.gamelib['menu']['graphics']['not_found'], value=self.parentApp.gamelib['menu']['graphics']['start_to_continue'],
editable=False) editable=False)
self.artBox.footer = 'Unknown Location' self.artBox.footer = 'Unknown Location'

View File

@ -11,6 +11,23 @@ class Handler(npyscreen.ButtonPress):
3: re-render the screen 3: re-render the screen
""" """
def localize_room(self, roomlocation):
"""
This method can re-localize the room.
"""
try:
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room']
# If the file could not be found
except FileNotFoundError:
# Log a critical error!
self.parent.parentApp.log.critical(
'Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(
self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation))
# Put the player in a blank room i forgot to finish
room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml')
return room
def whenPressed(self): def whenPressed(self):
self.parent.parentApp.log.debug('Send button pressed!') self.parent.parentApp.log.debug('Send button pressed!')
# This is the raw command from the user # This is the raw command from the user
@ -44,17 +61,8 @@ class Handler(npyscreen.ButtonPress):
# Localize the player # Localize the player
player = self.parent.parentApp.player player = self.parent.parentApp.player
roomlocation = player.playerData['player']['location']
try:
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room']
# If the file could not be found room = self.localize_room(player.playerData['player']['location']) # Localize the room
except FileNotFoundError:
# Log a critical error!
self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(
self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation))
# Put the player in a blank room i forgot to finish
room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml')
# By now we should be situated in our room, and with our player. # By now we should be situated in our room, and with our player.
# self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! # self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose!
@ -80,7 +88,8 @@ class Handler(npyscreen.ButtonPress):
elif command == 'PICK': elif command == 'PICK':
try: try:
if arguments[0] == 'UP': if arguments[0] == 'UP':
if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg if len(
arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg
try: try:
# Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it.
self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1]))
@ -90,8 +99,10 @@ class Handler(npyscreen.ButtonPress):
self.parent.update_log("You cant pick that up.") self.parent.update_log("You cant pick that up.")
else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer
try: try:
long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between long_arg = '_'.join(
self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) arguments[1:]) # Joins whatever comes after 1 in our args with '_' between
self.parent.parentApp.log.info(
'Player tried to pick up long object {0}'.format(long_arg))
self.parent.update_log(room[long_arg.lower()]['pick_up']) self.parent.update_log(room[long_arg.lower()]['pick_up'])
player.add_inventory(room[long_arg.lower()]['item_name']) player.add_inventory(room[long_arg.lower()]['item_name'])
except KeyError: except KeyError:
@ -107,6 +118,8 @@ class Handler(npyscreen.ButtonPress):
self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) self.parent.parentApp.log.debug('New room is: {0}'.format(new_room))
upon_enter = player.change_room(new_room) # Change the player to that new room. upon_enter = player.change_room(new_room) # Change the player to that new room.
self.parent.update_log(upon_enter) # Print the new room upon enter text. self.parent.update_log(upon_enter) # Print the new room upon enter text.
room = self.localize_room(player.playerData['player']['location']) # Re-Localize!
except KeyError: except KeyError:
self.parent.update_log("You cant open that.") self.parent.update_log("You cant open that.")
except IndexError: except IndexError:
@ -115,12 +128,16 @@ class Handler(npyscreen.ButtonPress):
elif command == 'INSPECT': elif command == 'INSPECT':
try: try:
self.parent.parentApp.log.info('Player inspecting: {0}'.format(arguments[0])) self.parent.parentApp.log.info('Player inspecting: {0}'.format(arguments[0]))
self.parent.update_log(room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists self.parent.update_log(
room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists
except KeyError: except KeyError:
self.parent.update_log("Nothing more to inspect here.") self.parent.update_log("Nothing more to inspect here.")
except IndexError: except IndexError:
self.parent.update_log("You must specify something to inspect.") self.parent.update_log("You must specify something to inspect.")
elif command == 'START':
self.parent.update_log('Welcome to the game! Try to |LOOK AROUND|.')
else: else:
self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command))
self.parent.update_log('I didn\'t understand {0}'.format(command)) self.parent.update_log('I didn\'t understand {0}'.format(command))
@ -137,7 +154,9 @@ class Handler(npyscreen.ButtonPress):
need to, change the text at the bottom and update the inventory. need to, change the text at the bottom and update the inventory.
""" """
try: try:
self.parent.update_location(room['name']) self.parent.update_location(
room['name'],
room['art'])
except KeyError: except KeyError:
self.parent.update_location('Unknown Location') self.parent.update_location('Unknown Location')