public GridToolBarCustomCommandBuilder <T> Action(string actionName, string controllerName, RouteValueDictionary routeValues)
        {
            Command.Action(actionName, controllerName, routeValues);

            SetTextIfEmpty(actionName);

            return(this);
        }
示例#2
0
        private void xOkButtonClicked(object sender, RoutedEventArgs e)
        {
            Command command = (xcomboBox.SelectedItem as Command);

            if (command != null)
            {
                command.Action();
            }
        }
        public GridToolBarCustomCommandBuilder <T> Action(RouteValueDictionary routeValues)
        {
            Command.Action(routeValues);

            if (Command.ActionName.HasValue())
            {
                SetTextIfEmpty(Command.ActionName);
            }

            return(this);
        }
示例#4
0
        private void LateUpdate()
        {
            if (_communicator == null ||
                !_communicator.IsConnected)
            {
                return;
            }
            Command cmd = GetCommand();

            if (cmd != null)
            {
                cmd.Action();
            }
        }
示例#5
0
 private static async Task RunCommand(Publisher publisher, string commandIndex)
 {
     // try to convert the key to index of available actions
     if (int.TryParse(commandIndex, out var index) &&
         (index >= 0 && index < commands.Length))
     {
         Command command = commands[index];
         Console.WriteLine($"Running '{command.Description}'");
         await command.Action(publisher);
     }
     else
     {
         Console.WriteLine("Unknown command");
     }
 }
示例#6
0
    private void showMenu(string title, List <Command> commands)
    {
        Command action = null;
        string  info   = "";

        while (true)
        {
            display(title, info, commands);

            var choice = Console.ReadLine();

            action = commands.FirstOrDefault(c => c.Keys == choice);

            if (action == null)
            {
                info = "Invalid Choice!";
            }
            else
            {
                action.Action();
            }
        }
    }
        public GridCustomActionCommandBuilder <T> Action(string actionName, string controllerName)
        {
            Command.Action(actionName, controllerName, (object)null);

            return(this);
        }
        public GridCustomActionCommandBuilder <T> Action(string actionName, string controllerName, object routeValues)
        {
            Command.Action(actionName, controllerName, routeValues);

            return(this);
        }
示例#9
0
 public void ExecuteCommand()
 {
     _command.Action();
 }
示例#10
0
 private bool During(Command command)
 {
     currentState = State.During;
     return command.Action();
 }
示例#11
0
        public static void Main(string[] args)
        {
            // Initialize World and Rooms
            List <Room> World = new List <Room>();

            // Initialize Player
            Player player = new Player();

            // Create Rooms
            Room mainRoom     = new Room("Small Cell", "You're in a small dark cell.", "You woke up feeling awful in a dark damp tiny cell. You hear distant echos. There's a door to the north.");
            Room cellCorridor = new Room("Cell Corridor", "You're in a long corridor.", "You reach a long and dark corridor. There's a huge holding cell to your right. There's a faint light to the north and a door to the south.");
            Room ladderRoom   = new Room("Ladder Room", "You're in a small room. There's a ladder that goes up.", "You're in a small flooded room. There's someone sitting in a corner. There's a rusty ladder that goes Up.");
            Room bonfireRoom  = new Room("Bonfire Room", "You're in a large hall. There's a ladder down and some gates south.", "You're in a large hall. In the middle of the hall there's a bonfire with an old sword burning amid the fire. There's a ladder down. A big wooden gate blocks your way to the south.");

            // Starting room:
            Room currentRoom = mainRoom;

            // Put Rooms in the World
            World.Add(mainRoom);
            World.Add(cellCorridor);
            World.Add(ladderRoom);
            World.Add(bonfireRoom);

            // Create Room Exits
            mainRoom.Exits.Add(Direction.north, cellCorridor);
            cellCorridor.Exits.Add(Direction.south, mainRoom);
            cellCorridor.Exits.Add(Direction.north, ladderRoom);
            ladderRoom.Exits.Add(Direction.south, cellCorridor);
            ladderRoom.Exits.Add(Direction.up, bonfireRoom);
            bonfireRoom.Exits.Add(Direction.down, ladderRoom);


            // Create Items
            Item itemCellKey      = new Item(true, false, "key", "It's a small rusty cell key.", "on the floor.");
            Item itemCellSkylight = new Item(false, false, "skylight", "There's a couple of bricks missing in the ceiling letting through a faint light.", "above you.");
            Item itemCellDoor     = new Item(false, true, "door", "It's a cell door.", "in front of you.");
            Item itemHollow       = new Item(false, false, "person", "It's a catatonic husk of a person. There's no response.", "sitting in a corner.");
            Item itemBonfire      = new Item(false, false, "bonfire", "It's a rather wild bonfire. Amidst the flames there is an incandescent old sword stuck to the ground.", "in the middle of the hall.");
            Item itemBonfireGates = new Item(false, true, "gate", "Big sturdy heavy old wooden gate, blocking your path to the south.", "on the south wall.");

            // Put Items inside Rooms
            mainRoom.Items.Add("key", itemCellKey);
            mainRoom.Items.Add("skylight", itemCellSkylight);
            mainRoom.Items.Add("door", itemCellDoor);
            ladderRoom.Items.Add("person", itemHollow);
            bonfireRoom.Items.Add("bonfire", itemBonfire);
            bonfireRoom.Items.Add("gate", itemBonfireGates);


            // Init Variables
            string currentMessage = currentRoom.FirstDescription;

            bool   isPlaying = true;
            bool   isNewRoom = true;
            string playerInput;

            string[] inputArray = new string[4];


            // ----- MAIN LOOP ----- //

            while (isPlaying)
            {
                if (isNewRoom)
                {
                    // Name the room
                    Message.Name(currentRoom);
                    // Full room description
                    Message.Description(currentMessage);
                    // Items in the room
                    if (!currentRoom.Items.GetEnumerator().MoveNext())
                    {
                        foreach (var roomItems in currentRoom.Items)
                        {
                            Message.Description($"{roomItems.Value.Name} {roomItems.Value.Place}");
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(currentMessage))
                    {
                        Message.Description(currentMessage);
                    }
                }

                // Get Console Command
                Console.Write("\n> ");
                playerInput = Console.ReadLine();

                Command.GetInput(playerInput, out inputArray);
                Command.Action(inputArray, out string verb, out string target);

                if (playerInput != string.Empty)
                {
                    if (Enum.TryParse <Verbs>(verb, out Verbs action))
                    {
                        switch (action)
                        {
                            #region Movement
                        case Verbs.go:
                            if (Command.IsValid(target) && Enum.TryParse <Direction>(target, out Direction exit))
                            {
                                currentRoom.Exits.TryGetValue(exit, out Room destination);
                                if (destination != null)
                                {
                                    currentMessage          = (destination.IsFirstTime) ? destination.FirstDescription : destination.Description;
                                    destination.IsFirstTime = false;

                                    currentRoom = destination;
                                    isNewRoom   = true;
                                }
                                else
                                {
                                    currentMessage = Command.ErrorMessage(action);
                                    isNewRoom      = false;
                                }
                            }
                            else
                            {
                                currentMessage = $"Go where?";
                                isNewRoom      = false;
                            }
                            break;

                            #endregion
                            #region Pick up
                        case Verbs.pick:
                            if (Command.IsValid(target))
                            {
                                if (currentRoom.Items.TryGetValue(target, out Item pickItem))
                                {
                                    if (pickItem.IsPickable)
                                    {
                                        currentRoom.Items.Remove(pickItem.Name);
                                        player.Inventory.Add($"{pickItem.Name}", pickItem);
                                        currentMessage = $"Picked up {pickItem.Name}";
                                    }
                                    else
                                    {
                                        currentMessage = Command.ErrorMessage(action);
                                    }
                                }
                                else
                                {
                                    currentMessage = "Pick what?";
                                }
                                isNewRoom = false;
                            }
                            else
                            {
                                currentMessage = "Pick what?";
                                isNewRoom      = false;
                            }
                            break;

                            #endregion
                            #region Drop
                        case Verbs.drop:
                            if (Command.IsValid(target))
                            {
                                if (player.Inventory.TryGetValue(target, out Item dropItem))
                                {
                                    // Let's assume the player can drop anything

                                    player.Inventory.Remove(dropItem.Name);
                                    currentRoom.Items.Add($"{dropItem.Name}", dropItem);
                                    currentMessage = $"Dropped {dropItem.Name}";
                                }
                                else
                                {
                                    currentMessage = "Drop what?";
                                }
                                isNewRoom = false;
                            }
                            else
                            {
                                currentMessage = "Drop what?";
                                isNewRoom      = false;
                            }
                            break;

                            #endregion
                            #region Use

                            /*
                             * case Verbs.use:
                             * if (!string.IsNullOrEmpty(target))
                             * {
                             *      Item useItem;
                             *      if (currentRoom.Items.TryGetValue(target, out useItem) || player.Inventory.TryGetValue(target, out useItem))
                             *      {
                             *              currentMessage = $"Used {useItem.Name}";
                             *      }
                             *      else
                             *      {
                             *              currentMessage = "Use what?";
                             *      }
                             *      isNewRoom = false;
                             * }
                             * else
                             * {
                             *      currentMessage = "Use what?";
                             *      isNewRoom = false;
                             * }
                             * break;
                             */
                            #endregion
                            #region Inventory
                        case Verbs.inventory:
                            if (player.Inventory.GetEnumerator().MoveNext())
                            {
                                Console.WriteLine($"\nInventory: ");
                                foreach (var item in player.Inventory)
                                {
                                    Console.Write($"- {item.Key}");
                                    currentMessage = "";
                                }
                            }
                            else
                            {
                                currentMessage = $"\nYou inventory is empty.";
                            }
                            isNewRoom = false;
                            break;

                            #endregion
                            #region Inspect Things
                        case Verbs.inspect:
                            if (Command.IsValid(target))
                            {
                                if (currentRoom.Items.TryGetValue(target, out Item inspectItem))
                                {
                                    currentMessage = inspectItem.Description;
                                }
                                else
                                {
                                    currentMessage = $"There is no such thing as a {target}";
                                }
                                isNewRoom = false;
                            }
                            else
                            {
                                currentMessage = "";
                                Console.WriteLine($"{currentRoom.FirstDescription}\n");

                                if (currentRoom.Items.Count != 0)
                                {
                                    Console.WriteLine($"You look arround and see:\n");
                                    foreach (var roomItems in currentRoom.Items)
                                    {
                                        Message.Description($"A {roomItems.Value.Name} {roomItems.Value.Place}");
                                    }
                                }

                                isNewRoom = false;
                            }
                            break;

                            #endregion
                            #region Clear Screen
                        case Verbs.clear:
                            Console.Clear();
                            currentMessage = currentRoom.Description;
                            isNewRoom      = true;
                            break;

                            #endregion
                            #region Help
                        case Verbs.help:
                            if (!Command.IsValid(target))
                            {
                                currentMessage = $"You can \"Go\", \"Pick\", \"Drop\", \"Inspect\", \"Clear\", \"Quit\".";
                                isNewRoom      = false;
                            }
                            break;

                            #endregion
                            #region Quit
                        case Verbs.quit:
                            isPlaying = false;
                            break;

                            #endregion
                        default:
                            currentMessage = Command.ErrorMessage(verb);
                            isNewRoom      = false;
                            break;
                        }
                    }
                    else
                    {
                        currentMessage = Command.ErrorMessage(verb);
                        isNewRoom      = false;
                    }
                }
                else
                {
                    isNewRoom = false;
                }
            }
        }
        /// <summary>
        /// チャット入力を受け取り、コマンドとして実行します
        /// </summary>
        /// <param name="message"></param>
        /// <returns>処理された場合、true</returns>
        protected bool TrySendMessage(string message)
        {
            message = message?.Trim();
            if (message.IsNullOrEmpty())
            {
                return(false);
            }
            UnityEngine.Debug.Log($"message : {message}");

            //先頭に / をコマンドとします。
            if (!message.StartsWith("/"))
            {
                return(false);
            }

            string[] fields = message.Split(' ', ',').Where(s => !s.IsNullOrWhiteSpace()).ToArray();
            if (!fields.Any())
            {
                return(false);
            }

            string cmd = fields[0].Substring(1);

            string[] parameters = fields.Skip(1).ToArray();

            Command command = null;
            //コマンドが一致する定義を取得
            //  サブコマンドがある場合や重複する場合、複数ある
            //大文字、小文字は区別しないものとします
            var commands = _Commands.Where(c => c.IsMatch(cmd)).ToArray();

            //サブコマンドの一致チェック
            if (parameters.Length >= 1)
            {
                string subCmd      = parameters[0];
                var    subCommands = commands.Where(c => c.HasSubCommand).ToArray();
                command = subCommands.FirstOrDefault(c => c.IsMatch(cmd, subCmd));
            }
            if (command == null)
            {
                //サブコマンド一致がなかった場合
                commands = commands.Where(c => !c.HasSubCommand).ToArray();
                command  = commands.FirstOrDefault();   //コマンドの一致は確認済み
            }

            //コマンド実行
            bool handled = false;

            if (command != null)
            {
                if (command.HasSubCommand)
                {
                    string subCmd = parameters[0];
                    parameters = parameters.Skip(1).ToArray();
                    handled    = command.SubCommandAction(cmd, subCmd, parameters);
                }
                else
                {
                    handled = command.Action(cmd, parameters);
                }
            }
            if (handled)
            {
                //送った場合、そのままだと入力が残るため、EndEnterMessageでチャット欄を閉じます。
                EndEnterMessage();
            }
            return(handled);
        }