Exemple #1
0
        private Command ReadCommand(string ln)
        {
            Command cmd = new Command();

            int colonIndex = ln.IndexOf(":");

            if (colonIndex == -1)
            {
                _abortParse = true;
                return null;
            }

            cmd.PlayerTag = ln.Substring(0, colonIndex);

            if (PlayerTag1.Length == 0)
            {
                PlayerTag1 = cmd.PlayerTag;
            }

            else if (!cmd.PlayerTag.Equals(PlayerTag1) && PlayerTag2.Length == 0)
            {
                PlayerTag2 = cmd.PlayerTag;
            }

            else if (!cmd.PlayerTag.Equals(PlayerTag1) && !cmd.PlayerTag.Equals(PlayerTag2))
            {
                _abortParse = true;
                return null;
            }

            cmd.Direction = ln.Substring(colonIndex + 2);

            if (!_validDirections.Contains(cmd.Direction))
            {
                _abortParse = true;
                return null;
            }

            return cmd;
        }
Exemple #2
0
        private string compileResult(Player activePlayer, Player restingPlayer, Command val, bool p1Active)
        {
            setDirection(val, activePlayer);

            if (validateTriggers(p1Active) == "Empate")
            {
                Console.WriteLine("Ha sido un empate en la " + activePlayer.Trayectoria.LastOrDefault().ToString());
                return "END";
            }

            else if (validateTriggers(p1Active) == String.Format("{0} perdio", activePlayer.Tag))
            {
                Console.WriteLine("El jugador " + restingPlayer.Tag + " ha ganado!");
                Console.WriteLine("El jugador " + activePlayer.Tag + " perdio en la " + activePlayer.Trayectoria.LastOrDefault().ToString());
                return "END";
            }

            return "";
        }
Exemple #3
0
        public void setDirection(Command command, Player player)
        {
            Position lastvalue = player.Trayectoria.Last();
            Position coordenada = new Position
            {
                row = lastvalue.row,
                column = lastvalue.column
            };
            
            switch (command.Direction)
            {
                case "arriba":
                    coordenada.row = coordenada.row != 0 ? coordenada.row - 1 : (Table.GetLength(0)-1); 
                    break;
                case "abajo":
                    coordenada.row = coordenada.row != (Table.GetLength(0)-1) ? coordenada.row + 1 : 0;
                    break;
                case "derecha":
                    coordenada.column = coordenada.column != (Table.GetLength(1)-1) ? coordenada.column + 1 : 0;
                    break;
                case "izquierda":
                    coordenada.column = coordenada.column != 0 ? coordenada.column - 1 : (Table.GetLength(1) - 1);
                    break;
            }

            player.Trayectoria.Add(coordenada);
        }