示例#1
0
    public override void HandleAction(String action)
    {
        string[] input = action.ToLower().Split(char.Parse(" "));
        if (input != null && input[0] != "return")
        {
            string loweredAction = input[0];
            string itemName      = action.Replace(input[0], "").Trim().ToLower();

            BaseItem foundItem = Game.hero.Inventory.Find(x => x.Description.ToLower().Equals(itemName));
            if (foundItem != null)
            {
                switch (loweredAction)
                {
                case "use":
                    foundItem.UseItem();

                    break;

                case "check":
                    _outputMessage = foundItem.CreateItemDescription();

                    break;
                }
            }
            else
            {
                Console.WriteLine($"Inventory does not contain: {itemName}");
            }
        }
        else if (input[0] == "return")
        {
            this._stateManager.ChangeState(this._stateManager.previousState);
        }
    }