Esempio n. 1
0
    public void ProcessInput(string userText)
    {
        ShowMessage("------------------------------------------------------------");

        // add user text to output history
        string userTextColored = "\n " + Util.ColorText("> " + userText, "#529694");

        ShowMessage(userTextColored);

        // get command Type from text
        CommandAndOtherWords commandNounPair = commandParser.Parse(userText);

        Util.Command command = commandNounPair.command;

        switch (commandNounPair.numWords)
        {
        case 1:
            // process that command
            ProcessSingleWordUserCommand(command, userText);
            break;

        case 2:
        default:
            // process that command
            ProcessMultiWordUserCommand(commandNounPair, userText);
            break;
        }

        // set input field with Focus - ready for next user input
        textIn.Select();
        textIn.ActivateInputField();
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        CommandParser parser = new CommandParser();

        CommandAndOtherWords result = parser.Parse("pickup key");

        Debug.Log("result = " + result.ToString());
    }
Esempio n. 3
0
    private void ProcessMultiWordUserCommand(CommandAndOtherWords commandNounPair, string userText)
    {
        Util.Command command = commandNounPair.command;
        Util.Noun    noun    = commandNounPair.noun;
        // Debug.Log(command.ToString());
        // Debug.Log(noun.ToString());

        string message = "";

        switch (command)
        {
        case Util.Command.Use:
            string itemName = userText.Split(' ')[1];
            Item   item     = player.inventory.GetItem(itemName);
            if (item != null)
            {
                message  = "You use " + item.Name;
                message += "\r\n" + item.use();
                if (currentLocation.monster != null && !currentLocation.monster.amIDead())
                {
                    player.receiveDommage(currentLocation.monster.getAttackPoint());
                }
                break;
            }
            message = "You do not posess that item";
            break;

        case Util.Command.Pick:
            switch (noun)
            {
            case Util.Noun.Up:
                message = "error";
                if (currentLocation.pickupables.Count == 0)
                {
                    message = "There nothing to be picked up.";
                    break;
                }
                while (currentLocation.pickupables.Count != 0)
                {
                    Item pickedup = currentLocation.pickupables[currentLocation.pickupables.Count - 1];
                    currentLocation.pickupables.RemoveAt(currentLocation.pickupables.Count - 1);
                    Debug.Log(pickedup.Name);
                    player.addItem(pickedup);
                    message = "You picked up " + pickedup.Name;
                }

                break;
            }
            break;

        case Util.Command.Unknown:
        default:
            message = Util.Message(Util.Type.Unknown);
            break;
        }

        ShowMessage(message);
    }
Esempio n. 4
0
    private void ProcessMultiWordUserCommand(CommandAndOtherWords commandNounPair)
    {
        Util.Command command = commandNounPair.command;
        Util.Noun    noun    = commandNounPair.noun;
        // Debug.Log(command.ToString());
        // Debug.Log(noun.ToString());

        string message = "";

        switch (command)
        {
        case Util.Command.Use:
            switch (noun)
            {
            case Util.Noun.Todo_List:
                Item item = player.inventory.GetItem("todo list");
                if (item != null)
                {
                    message = "Current tasks: " + map.ship.GetStatus();
                }
                else
                {
                    message = "You do not posess that item";
                }
                break;
            }
            break;

        case Util.Command.Pick:
            switch (noun)
            {
            case Util.Noun.Up:
                message = "error";
                if (currentLocation.pickupables.Count == 0)
                {
                    message = "There nothing to be picked up.";
                    break;
                }
                while (currentLocation.pickupables.Count != 0)
                {
                    Item pickedup = currentLocation.pickupables[currentLocation.pickupables.Count - 1];
                    currentLocation.pickupables.RemoveAt(currentLocation.pickupables.Count - 1);
                    Debug.Log(pickedup.name);
                    player.addItem(pickedup);
                    message = "You picked up " + pickedup.name;
                }

                break;
            }
            break;
        }

        ShowMessage(message);
    }
    private void ProcessMultiWordUserCommand(CommandAndOtherWords commandNounPair)
    {
        Util.Command command = commandNounPair.command;
        Util.Noun    noun    = commandNounPair.noun;


        string message = "";

        switch (command)
        {
        case Util.Command.Pick:
            switch (noun)
            {
            case Util.Noun.Up:
                List <PickUp> pickups = player.GetLocation().pickupables;
                if (pickups.Count > 0)
                {
                    // Pick up the first item in the list only.
                    PickUp item = pickups[0];
                    message = "You picked up: " + item.name + " (" + item.description + ")";
                    item.Pickup(player);
                }
                else
                {
                    message = "Nothing to pick up.";
                }
                break;

            default:
                message = Util.Message(Util.Type.Unknown);
                break;
            }
            break;

        default:
            message = Util.Message(Util.Type.Unknown);
            break;
        }

        ShowMessage(message);
    }
Esempio n. 6
0
    public CommandAndOtherWords Parse(string userText)
    {
        userText = userText.ToLower();
        string[] words = userText.Split(' ');
        string   word1 = words[0];

        CommandAndOtherWords commandNounPair = new CommandAndOtherWords();

        commandNounPair.command = ParseCommand(word1);


        // was there a second word?
        if (words.Length > 1)
        {
            string word2 = words[1];
            commandNounPair.noun     = ParseNoun(word2);
            commandNounPair.numWords = words.Length;
        }

        return(commandNounPair);
    }
    public void ProcessInput(string userText)
    {
        // add user text to output history
        string userTextColored = "\n >" + Util.ColorText(userText, "red");

        ShowMessage(userTextColored);

        // get command Type from text
        CommandAndOtherWords commandNounPair = commandParser.Parse(userText);

        Util.Command command = commandNounPair.command;

        if (command == Util.Command.Help)
        {
            ProcessHelp(userText);
        }
        else
        {
            switch (commandNounPair.numWords)
            {
            case 1:
                // process that command
                ProcessSingleWordUserCommand(command);
                break;

            case 2:
            default:
                // process that command
                ProcessMultiWordUserCommand(commandNounPair);
                break;
            }
        }

        // set input field with Focus - ready for next user input
        textIn.Select();
        textIn.ActivateInputField();

        player.OnPlayerMoved();
    }