Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                ChessMatch match = new ChessMatch();

                while (!match.Finished)
                {
                    try
                    {
                        Console.Clear();

                        Display.ToDisplayMatch(match);

                        Console.WriteLine();
                        Console.Write("Origem: ");
                        Position origin = Display.ReadChessPosition().ToPosition();

                        match.ValidateOriginPosition(origin);


                        bool[,] possiblePositions = match.Board.GetPiece(origin).PossiblesMoviments();

                        Console.Clear();
                        Display.ToDisplayBoard(match.Board, possiblePositions);

                        Console.Write("Destino: ");
                        Position destiny = Display.ReadChessPosition().ToPosition();

                        match.ValidateDestinyPosition(origin, destiny);


                        match.ToPlay(origin, destiny);
                    }
                    catch (BoardException e) {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }
                Console.Clear();
                Display.ToDisplayMatch(match);
            }
            catch (BoardException e)
            {
                Console.WriteLine("Error: " + e.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                ChessMatch game = new ChessMatch();

                while (!game.finished)
                {
                    try
                    {
                        Console.Clear();
                        Screen.ShowGame(game);

                        Console.WriteLine();
                        Console.Write("Origin: ");
                        Position origin = Screen.ReadSquare().toPosicao();
                        game.ValidateOriginPosition(origin);

                        bool[,] posicoesPossiveis = game.brd.GetPiece(origin).possibleMovements();

                        Console.Clear();
                        Screen.ShowBoard(game.brd, posicoesPossiveis);

                        Console.WriteLine();
                        Console.Write("Destiny: ");
                        Position destiny = Screen.ReadSquare().toPosicao();
                        game.ValidateDestinyPosition(origin, destiny);

                        game.ExecuteMovement(origin, destiny);
                    }
                    catch (BoardException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }
                Console.Clear();
                Screen.ShowGame(game);
            }
            catch (BoardException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            try
            {
                var match = new ChessMatch();

                while (!match.IsMatchCompleted)
                {
                    try
                    {
                        Console.Clear();
                        Screen.PrintMatch(match);

                        Console.Write("Origin: ");
                        Position origin = Screen.ReadChessPosition()?.ToPosition();
                        match.ValidateOriginPosition(origin);

                        bool[,] possibleMoves = match.Board.GetPiece(origin).PossibleMoves();

                        Console.Clear();
                        Screen.PrintBoard(match.Board, possibleMoves);

                        Console.WriteLine();
                        Console.Write("Destination: ");
                        Position destination = Screen.ReadChessPosition()?.ToPosition();
                        match.ValidateDestinationPosition(origin, destination);

                        match.ExecutePlay(origin, destination);
                    }
                    catch (BoardException ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.ReadKey();
                    }
                    Console.Clear();
                    Screen.PrintMatch(match);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadLine();
        }