public string Interpret(string[] commandArgs, IManagerController managerController)
        {
            var message = string.Empty;
            var command = commandArgs[0];

            switch (command)
            {
            case "AddPlayer":
                message = managerController.AddPlayer(commandArgs[1], commandArgs[2]);
                break;

            case "AddCard":
                message = managerController.AddCard(commandArgs[1], commandArgs[2]);
                break;

            case "AddPlayerCard":
                message = managerController.AddPlayerCard(commandArgs[1], commandArgs[2]);
                break;

            case "Fight":
                message = managerController.Fight(commandArgs[1], commandArgs[2]);
                break;

            case "Report":
                message = managerController.Report();
                break;

            default:
                message = null;
                break;
            }

            return(message);
        }
Exemplo n.º 2
0
        private string ExecuteCommand(string[] input)
        {
            try
            {
                switch (input[0])
                {
                case "AddPlayer":
                    return(managerController.AddPlayer(input[1], input[2]));

                case "AddCard":
                    return(managerController.AddCard(input[1], input[2]));

                case "AddPlayerCard":
                    return(managerController.AddPlayerCard(input[1], input[2]));

                case "Fight":
                    return(managerController.Fight(input[1], input[2]));

                case "Report":
                    return(managerController.Report());

                default:
                    return("Invalid command!");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        private string ExecuteCommand(string command, string[] inputArgs)
        {
            string output = string.Empty;

            if (command == "AddPlayer")
            {
                output = managerController.AddPlayer(inputArgs[0],
                                                     inputArgs[1]);
            }
            else if (command == "AddCard")
            {
                output = managerController.AddCard(inputArgs[0],
                                                   inputArgs[1]);
            }
            else if (command == "AddPlayerCard")
            {
                output = managerController.AddPlayerCard(inputArgs[0],
                                                         inputArgs[1]);
            }
            else if (command == "Fight")
            {
                output = managerController.Fight(inputArgs[0],
                                                 inputArgs[1]);
            }
            else if (command == "Report")
            {
                output = managerController.Report();
            }
            return(output);
        }
        public void Run()
        {
            while (true)
            {
                try
                {
                    string[] data = this.reader.ReadLine().Split();

                    if (data[0] == "Exit")
                    {
                        Environment.Exit(0);
                    }

                    string command = data[0];

                    var result = string.Empty;
                    if (command == "AddPlayer")
                    {
                        string playerType     = data[1];
                        string playerUsername = data[2];

                        result = controller.AddPlayer(playerType, playerUsername);
                    }
                    else if (command == "AddCard")
                    {
                        string cardType = data[1];
                        string cardName = data[2];

                        result = controller.AddCard(cardType, cardName);
                    }

                    else if (command == "AddPlayerCard")
                    {
                        string username = data[1];
                        string cardName = data[2];

                        result = controller.AddPlayerCard(username, cardName);
                    }
                    else if (command == "Fight")
                    {
                        string attackUser = data[1];
                        string enemyUser  = data[2];

                        result = controller.Fight(attackUser, enemyUser);
                    }

                    else if (command == "Report")
                    {
                        result = controller.Report();
                    }

                    this.writer.WriteLine(result);
                }
                catch (Exception e)
                {
                    this.writer.WriteLine(e.Message);
                }
            }
        }
Exemplo n.º 5
0
        public void Run()
        {
            while (true)
            {
                var input = reader.ReadLine();

                if (input == "Exit")
                {
                    break;
                }

                var command = input
                              .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string result = " ";

                try
                {
                    switch (command[0])
                    {
                    case "AddPlayer":
                        var playerType = command[1];
                        var username   = command[2];
                        result = managerController.AddPlayer(playerType, username);
                        break;

                    case "AddCard":
                        var cardType = command[1];
                        var name     = command[2];
                        result = managerController.AddCard(cardType, name);
                        break;

                    case "AddPlayerCard":
                        var player = command[1];
                        var card   = command[2];
                        result = managerController.AddPlayerCard(player, card);
                        break;

                    case "Fight":
                        var attackUser = command[1];
                        var enemyUser  = command[2];
                        result = managerController.Fight(attackUser, enemyUser);
                        break;

                    case "Report":
                        result = managerController.Report();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }

                writer.WriteLine(result);
            }
        }
Exemplo n.º 6
0
        public void Run()
        {
            var    sb      = new StringBuilder();
            string command = reader.ReadLine();

            while (command != "Exit")
            {
                string[] temp = command.Split();

                try
                {
                    switch (temp[0])
                    {
                    case "AddPlayer":
                        string playerType     = temp[1];
                        string playerUsername = temp[2];

                        sb.AppendLine(managerController.AddPlayer(playerType, playerUsername));
                        break;

                    case "AddCard":
                        string cardType = temp[1];
                        string cardName = temp[2];

                        sb.AppendLine(managerController.AddCard(cardType, cardName));
                        break;

                    case "AddPlayerCard":
                        string username        = temp[1];
                        string currentCardName = temp[2];

                        sb.AppendLine(managerController.AddPlayerCard(username, currentCardName));
                        break;

                    case "Fight":
                        string attackUser = temp[1];
                        string enemyUser  = temp[2];

                        sb.AppendLine(managerController.Fight(attackUser, enemyUser));
                        break;

                    case "Report":
                        sb.AppendLine(managerController.Report());
                        break;
                    }
                }
                catch (Exception ex)
                {
                    sb.AppendLine(ex.Message);
                }

                command = reader.ReadLine();
            }

            writer.WriteLine(sb.ToString().TrimEnd());
        }
Exemplo n.º 7
0
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();

                if (input == "Exit")
                {
                    break;
                }

                try
                {
                    string[] inputArgs = input.Split();
                    string   command   = inputArgs[0];

                    if (command == "AddPlayer")
                    {
                        string playerType     = inputArgs[1];
                        string playerUsername = inputArgs[2];

                        Console.WriteLine(managerController.AddPlayer(playerType, playerUsername));
                    }
                    else if (command == "AddCard")
                    {
                        string cardType = inputArgs[1];
                        string cardName = inputArgs[2];

                        Console.WriteLine(managerController.AddCard(cardType, cardName));
                    }
                    else if (command == "AddPlayerCard")
                    {
                        string username = inputArgs[1];
                        string cardName = inputArgs[2];

                        Console.WriteLine(managerController.AddPlayerCard(username, cardName));
                    }
                    else if (command == "Fight")
                    {
                        string attackUser = inputArgs[1];
                        string enemyUser  = inputArgs[2];

                        Console.WriteLine(managerController.Fight(attackUser, enemyUser));
                    }
                    else if (command == "Report")
                    {
                        Console.WriteLine(managerController.Report());
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 8
0
 public void Run()
 {
     while (true)
     {
         var input = Console.ReadLine().Split();
         if (input[0] == "Exit")
         {
             Environment.Exit(0);
         }
         try
         {
             if (input[0] == "AddPlayer")
             {
                 string type = input[1];
                 string name = input[2];
                 Console.WriteLine(managerController.AddPlayer(type, name));
             }
             else if (input[0] == "AddCard")
             {
                 string type = input[1];
                 string name = input[2];
                 Console.WriteLine(managerController.AddCard(type, name));
             }
             else if (input[0] == "AddPlayerCard")
             {
                 string username = input[1];
                 string cardName = input[2];
                 Console.WriteLine(managerController.AddPlayerCard(username, cardName));
             }
             else if (input[0] == "Fight")
             {
                 string attacker = input[1];
                 string enemy    = input[2];
                 Console.WriteLine(managerController.Fight(attacker, enemy));
             }
             else if (input[0] == "Report")
             {
                 Console.WriteLine(managerController.Report());
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
             //throw;
         }
     }
 }
Exemplo n.º 9
0
        private void ProcessCommands()
        {
            string input;

            while ((input = this.reader.ReadLine()) != "Exit")
            {
                string[] parts = input.Split();

                string command = parts[0];

                if (command == "AddPlayer")
                {
                    string type     = parts[1];
                    string userName = parts[2];

                    this.writer.WriteLine(managerController.AddPlayer(type, userName));
                }
                if (command == "AddCard")
                {
                    string type     = parts[1];
                    string cardName = parts[2];

                    this.writer.WriteLine(managerController.AddCard(type, cardName));
                }
                if (command == "AddPlayerCard")
                {
                    string playerName = parts[1];
                    string cardName   = parts[2];

                    this.writer.WriteLine(managerController.AddPlayerCard(playerName, cardName));
                }
                if (command == "Fight")
                {
                    string attackerName = parts[1];
                    string enemyName    = parts[2];

                    this.writer.WriteLine(managerController.Fight(attackerName, enemyName));
                }
                if (command == "Report")
                {
                    this.writer.WriteLine(managerController.Report());
                }
            }
        }
Exemplo n.º 10
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string[] lineElements = reader.ReadLine().Split(" ",
                                                                    StringSplitOptions.RemoveEmptyEntries);

                    if (lineElements[0] == "Exit")
                    {
                        break;
                    }

                    string message = string.Empty;
                    if (lineElements[0] == "AddPlayer")
                    {
                        message = controller.AddPlayer(lineElements[1], lineElements[2]);
                    }
                    else if (lineElements[0] == "AddCard")
                    {
                        message = controller.AddCard(lineElements[1], lineElements[2]);
                    }
                    else if (lineElements[0] == "AddPlayerCard")
                    {
                        message = controller.AddPlayerCard(lineElements[1], lineElements[2]);
                    }
                    else if (lineElements[0] == "Fight")
                    {
                        message = controller.Fight(lineElements[1], lineElements[2]);
                    }
                    else if (lineElements[0] == "Report")
                    {
                        message = controller.Report();
                    }

                    writer.WriteLine(message);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 11
0
        public void Run()
        {
            while (true)
            {
                var input = reader.ReadLine().Split();

                if (input[0] == "Exit")
                {
                    Environment.Exit(0);
                }

                try
                {
                    if (input[0] == "AddPlayer")
                    {
                        writter.WriteLine(managerController.AddPlayer(input[1], input[2]));
                    }
                    else if (input[0] == "AddCard")
                    {
                        writter.WriteLine(managerController.AddCard(input[1], input[2]));
                    }
                    else if (input[0] == "AddPlayerCard")
                    {
                        writter.WriteLine(managerController.AddPlayerCard(input[1], input[2]));
                    }
                    else if (input[0] == "Fight")
                    {
                        writter.WriteLine(managerController.Fight(input[1], input[2]));
                    }
                    else if (input[0] == "Report")
                    {
                        writter.WriteLine(managerController.Report());
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 12
0
        public void Run()
        {
            string commands = Console.ReadLine();

            while (true)
            {
                string[] Args = commands
                                .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                .ToArray();

                string command = Args[0];

                if (command == "Exit")
                {
                    break;
                }

                string result   = string.Empty;
                string cardName = string.Empty;

                switch (command)
                {
                case "AddPlayer":

                    string playerType     = Args[1];
                    string playerUsername = Args[2];

                    result = managerController.AddPlayer(playerType, playerUsername);

                    break;

                case "AddCard":

                    string cardType = Args[1];
                    cardName = Args[2];

                    result = managerController.AddCard(cardType, cardName);

                    break;

                case "AddPlayerCard":

                    string username = Args[1];
                    cardName = Args[2];

                    result = managerController.AddPlayerCard(username, cardName);

                    break;

                case "Fight":

                    break;

                case "Report":

                    break;
                }

                Console.WriteLine(result);

                commands = Console.ReadLine();
            }
        }