Exemple #1
0
def prompt(player, room):
    """
    Desc: Main game prompt.
    Called by: main game loop

    Notes:
    returns either a room or None. If returning None, all necessary actions are taken within the called function.
    """
    command = None
    while not command:
        commandFull = raw_input(player.showHP() + ">")
        parts = commandFull.lower().split(' ')
        command = parts[0]
        args = parts[1:]
    if command in ('1','2','3','4','enter'):
        if command in ('1','2','3','4'):
            command = int(command)
            #this seems hacky, but actions are classes and must return themselves. Making the new room a variable of the action instance allows it to return a room.
            return actions.enter(command, room, player).newRoom
        elif command == "enter":
            try:
                args = int(args)
                return actions.enter(args, room, player).newRoom
            except:
                print "That is not a valid door."
    elif command == 'help':
        #need to extend this to look at other commands
        gamehelp = actions.ghelp()
        print gamehelp.helpTxt
        return None
    elif command in ('l', 'look'):
        action = actions.look(room)
        return None
    elif command in ('quit', 'exit'):
        action = actions.quit(player)
        return None
    elif command in ('stat','stats','status'):
        action = actions.status(player)
        return None
    else:
        return None
Exemple #2
0
def prompt(player, room):
    """
    Desc: Main game prompt.
    Called by: main game loop

    Notes:
    returns either a room or None. If returning None, all necessary actions are taken within the called function.
    """
    command = None
    while not command:
        commandFull = raw_input(player.showHP() + ">")
        parts = commandFull.lower().split(' ')
        command = parts[0]
        args = parts[1:]
    if command in ('1', '2', '3', '4', 'enter'):
        if command in ('1', '2', '3', '4'):
            command = int(command)
            #this seems hacky, but actions are classes and must return themselves. Making the new room a variable of the action instance allows it to return a room.
            return actions.enter(command, room, player).newRoom
        elif command == "enter":
            try:
                args = int(args)
                return actions.enter(args, room, player).newRoom
            except:
                print "That is not a valid door."
    elif command == 'help':
        #need to extend this to look at other commands
        gamehelp = actions.ghelp()
        print gamehelp.helpTxt
        return None
    elif command in ('l', 'look'):
        action = actions.look(room)
        return None
    elif command in ('quit', 'exit'):
        action = actions.quit(player)
        return None
    elif command in ('stat', 'stats', 'status'):
        action = actions.status(player)
        return None
    else:
        return None
Exemple #3
0
def parse_args(user_input, player):
    """
    Args:
        user_input (string): raw string of user input
        player (Player object): object of active player
    """
    # Accounting for null input
    if user_input.strip() == "":
        print(random.choice(CONFUSED_RESPONSES))
        return

    # Split string into list of strings (separated by spaces)
    list_of_input = user_input.split()
    # Splitting command into a verb and its following argument
    command = list_of_input[0].lower()
    if len(list_of_input) > 1:
        arguments = [x.lower() for x in list_of_input[1:]]  # Formatting each argument
        if command == "pick" and arguments[0] == "up":
            if len(arguments) > 1:
                actions.pick_up(player, "".join(arguments[1:]), " ".join(arguments[1:]))
            else:
                print("What do you want to pick up?")
            return
        elif command == "use" and ("on" in arguments):
            # Deals with "use ___ on ___ " input
            actions.use_on(arguments, player)
            return
        elif command == "interact" and (arguments[0] == "with"):
            # Deals with "interact with _____ " input
            if len(arguments) < 2:  # If user just says "interact with"
                print("Specify what you'd like to interact with.")
            else:
                actions.interact_with(arguments[1:], player)
            return
        raw_argument = " ".join(list_of_input[1:])  # Here's the raw argument
        argument = (" ".join(arguments))  # Turning into name format.
    else:
        argument = ""
        raw_argument = ""

    if command == "go" or command == "move":
        actions.move(argument, player)
    elif command in ["east", "west", "north", "south"]:
        actions.move(command, player)
    elif command == "observe" and argument == "" or command == "look" and (argument == "around" or argument == ""):
        actions.examine_surroundings(player)
    elif command == "inventory" or (command == "view" and argument == "inventory") or (command == "i" and argument==""):
        actions.print_inventory(player)
    elif command == "where" and argument == "am i" or (command == "location" and argument == ""):
        actions.where(player)
    elif command == "drop":
        actions.drop(player, argument, raw_argument)
    elif command == "grab" or command == "take" or command == "get":
        actions.pick_up(player, argument, raw_argument)
    elif command == "examine":
        actions.examine(player, arguments, raw_argument)
    elif command == "enter":
        actions.enter(player, argument, raw_argument)
    elif (command == "kill" and argument == "myself") or (command == "kms"):
        actions.kill_player(player)
    elif command == "drink":
        actions.drink(player, argument, raw_argument)
    elif command == "eat":
        actions.eat(player, argument, raw_argument)
    elif command == "uuddlrlrbastart":  # Konami code
        print("Nice try, bud.")
    else:
        print(random.choice(CONFUSED_RESPONSES))

    return
Exemple #4
0
def basePrompt(player, room):
    """
    Desc: Main game prompt.
    Called by: main game loop
    Notes:
    returns either a room or None. If returning None, all necessary actions are taken within the called function.
    """
    command = None
    while not command:
        commandFull = raw_input(player.showHP() + ">")
        parts = commandFull.lower().split(" ")
        command = parts[0]
        args = parts[1:]
    if command in ("1","2","3","4","enter"):
        if command in ("1","2","3","4"):
            command = int(command)
            return actions.enter(command, room, player)
        elif command == "enter":
            try:
                args = int(args)
                return actions.enter(args, room, player)
            except:
                print "That is not a valid door."
    elif command == "help":
        #need to extend this to look at other commands
        if len(args) == 0:
            actions.ghelp()
        else:
            actions.ghelp(args[0])
        return
    elif command in ("l", "look"):
        if len(args) == 0:
            actions.look(room)
        else:
            actions.examine(player, args[0])
        return
    elif command in ("quit", "exit"):
        actions.quit(player)
        return
    elif command in ("stat","stats","status"):
        actions.status(player)
        return
    elif command == "use":
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.use(player, args[0])
        return
    elif command in ("i", "inv", "inven", "inventory"):
        actions.inventory(player)
        return
    elif command in ("e", "eq", "equip"):
        if len(args) == 0:
            actions.worn(player)
        else:
            actions.equipCommand(player, args[0])
        return
    elif command == "worn":
        actions.worn(player)
        return
    elif command in ("un", "une", "uneq", "unequip"):
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.unequipCommand(player, args[0])
        return
    elif command == "get":
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.get(player, room, args[0])
    elif command == "drop":
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.drop(player, room, args[0])
    elif command in ("ex", "exam", "examine"):
        if len(args) == 0:
            print "That command requires a target.\n"
        else:
            actions.examine(player, args[0])
    elif command == "set":
        if len(args) == 0:
            actions.set(player)
        elif len(args) == 1:
            print "Set command requires a hotkey and a skill.\n"
        elif len(args) == 2:
            actions.set(player, args[0], args[1])
        else:
            actions.set(player, args[0], args[1], args[2])
    else:
        return