Exemple #1
0
        public void Input(Func <CommandParser.Command, string, bool> handler)
        {
            bool isExit = false;

            while (!isExit)
            {
                //System.Console.Write("> ");
                string userinput = System.Console.ReadLine();
                if (!string.IsNullOrEmpty(userinput))
                {
                    string userparams             = string.Empty;
                    CommandParser.Command command = CommandParser.ParseCommand(userinput, out userparams);
                    switch (command)
                    {
                    case CommandParser.Command.Exit:
                    {
                        handler?.Invoke(command, userparams);
                        isExit = true;
                        break;
                    }

                    default:
                    {
                        if (handler == null || !handler(command, userparams))
                        {
                            System.Console.WriteLine("Undefined command.");
                        }
                        break;
                    }
                    }
                }
            }
        }
Exemple #2
0
 public bool Parse(string commandStr)
 {
     if (string.IsNullOrEmpty(commandStr))
     {
         return false;
     }
     if (Globals.Instance.CliSession.Privilege <= 0)
     {
         return false;
     }
     string text = commandStr.Trim();
     if (text.Length < 2)
     {
         return false;
     }
     char c = text[0];
     if (c == '-')
     {
         CommandParser.Command command = new CommandParser.Command(text);
         string key = command.GetName().Trim(new char[]
         {
             '-'
         });
         if (this.mRegistedCmds.ContainsKey(key))
         {
             this.mRegistedCmds[key](command);
         }
         else
         {
             this.SendServerCommand(text);
         }
         return true;
     }
     return false;
 }
Exemple #3
0
        internal void ExecuteSingleCommand(CommandParser.Command command)
        {
            Player currentPlayer = GetPlayer(command.Tag);

            if (currentPlayer == null)
            {
                currentPlayer = AddPlayer(command.Tag);
            }

            AnalyzeAndMovePlayer(currentPlayer, command.Direction);
        }