Exemple #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);
            }
        }
Exemple #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();
        }