Compare commits
4 Commits
377bb43e42
...
2f8dd761ba
Author | SHA1 | Date |
---|---|---|
|
2f8dd761ba | |
|
bcb2ee060d | |
|
3aa6d426fe | |
|
301d3d75db |
|
@ -46,8 +46,7 @@ class Handler(npyscreen.ButtonPress):
|
|||
player = self.parent.parentApp.player
|
||||
roomlocation = player.playerData['player']['location'] + '.yaml'
|
||||
try:
|
||||
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)[
|
||||
player.playerData['player']['location']]
|
||||
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room']
|
||||
|
||||
# If the file could not be found
|
||||
except FileNotFoundError:
|
||||
|
@ -63,45 +62,55 @@ class Handler(npyscreen.ButtonPress):
|
|||
|
||||
# TODO: Should upgrade these to use fuzzy words library! and not direct comparisons!
|
||||
if command == 'LOOK':
|
||||
if arguments[0] == 'AROUND':
|
||||
try:
|
||||
self.parent.update_log(room['look_around'])
|
||||
except KeyError:
|
||||
self.parent.update_log('There is nothing to look at?.. This might be a bug.')
|
||||
if arguments[0] == 'AT':
|
||||
try:
|
||||
# Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it.
|
||||
self.parent.update_log(room[arguments[1].lower()]['look_at'])
|
||||
except KeyError:
|
||||
self.parent.update_log("Not sure what you're trying to look at.")
|
||||
try:
|
||||
if arguments[0] == 'AROUND':
|
||||
try:
|
||||
self.parent.update_log(room['look_around'])
|
||||
except KeyError:
|
||||
self.parent.update_log('There is nothing to look at?.. This might be a bug.')
|
||||
if arguments[0] == 'AT':
|
||||
try:
|
||||
# Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it.
|
||||
self.parent.update_log(room[arguments[1].lower()]['look_at'])
|
||||
except KeyError:
|
||||
self.parent.update_log("Im not sure what you're trying to look at.")
|
||||
except IndexError:
|
||||
self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments))
|
||||
self.parent.update_log("You must specify something to look at.")
|
||||
|
||||
elif command == 'PICK':
|
||||
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
|
||||
try:
|
||||
# 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.update_log(room[arguments[1].lower()]['pick_up'])
|
||||
except KeyError:
|
||||
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
|
||||
try:
|
||||
long_arg = '_'.join(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'])
|
||||
except KeyError:
|
||||
self.parent.update_log("You cant pick that up.")
|
||||
try:
|
||||
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
|
||||
try:
|
||||
# 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.update_log(room[arguments[1].lower()]['pick_up'])
|
||||
except KeyError:
|
||||
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
|
||||
try:
|
||||
long_arg = '_'.join(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'])
|
||||
except KeyError:
|
||||
self.parent.update_log("You cant pick that up.")
|
||||
except IndexError:
|
||||
self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments))
|
||||
self.parent.update_log("You must specify something to pick up.")
|
||||
|
||||
elif command == 'OPEN':
|
||||
try:
|
||||
self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0]))
|
||||
new_room = room[arguments[0].lower()]['leads_to']
|
||||
self.parent.parentApp.log.debug('New room is: {0}'.format(new_room))
|
||||
except KeyError:
|
||||
self.parent.update_log("You cant open that.")
|
||||
except IndexError:
|
||||
self.parent.update_log("you must specify something to open")
|
||||
#try:
|
||||
self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0]))
|
||||
new_room = room[arguments[0].lower()]['leads_to']
|
||||
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.
|
||||
self.parent.update_log(upon_enter) # Print the new room upon enter text.
|
||||
#except KeyError:
|
||||
# self.parent.update_log("You cant open that.")
|
||||
#except IndexError:
|
||||
# self.parent.update_log("you must specify something to open")
|
||||
|
||||
else:
|
||||
self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command))
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
from yaml_parser import parse_datafile as parse
|
||||
|
||||
|
||||
class Player:
|
||||
"""
|
||||
This class intended to abstract out the actual yaml data into a player.(item) that is more
|
||||
friendly to handle in code.
|
||||
"""
|
||||
|
||||
def __init__(self, save_location):
|
||||
self.save_location = save_location
|
||||
|
||||
|
@ -15,4 +17,8 @@ class Player:
|
|||
Should move the player to a new room
|
||||
TODO: Put a check here that checks if the room we're moving to exists!
|
||||
"""
|
||||
self.playerData['player']['location'] = new_room
|
||||
self.playerData['player']['location'] = new_room
|
||||
|
||||
room = self.playerData['player']['location']
|
||||
|
||||
return parse('adventure_game/gamedata/world/' + room)['room']['upon_enter']
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
office:
|
||||
room:
|
||||
grid: [0, 1]
|
||||
upon_enter: "You are standing just outside your office door."
|
||||
look_around: "You look up, and down the hallway, you see the receptionists |desk|. And a |closet| at the other end of the hall."
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
office:
|
||||
room:
|
||||
grid: [0, 0]
|
||||
upon_enter: "You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|"
|
||||
look_around: "You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|"
|
||||
|
|
Loading…
Reference in New Issue