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

                while (true)
                {
                    try
                    {
                        Console.Clear();
                        Screen.PrintMatch(match);
                        if (match.IsMatchEnded)
                        {
                            break;
                        }

                        Console.Write("\nOrigin: ");
                        Position origin = Screen.ReadChessPosition().ToPosition();
                        match.ValidateOriginPosition(origin);
                        bool[,] possiblePositions = match.Board.GetPiece(origin).PossibleMoviments();

                        Console.Clear();
                        Screen.PrintBoard(match.Board, possiblePositions);
                        Console.WriteLine("\nTurn: " + match.Turn);
                        Console.WriteLine("Waiting for move: " + match.CurrentPlayer);

                        Console.Write("\nDestination: ");
                        Position destination = Screen.ReadChessPosition().ToPosition();
                        match.ValidateDestinationPosition(origin, destination);

                        match.PerformsMove(origin, destination);
                    }
                    catch (ChessBoardException e)
                    {
                        Console.WriteLine(e.Message + " Press anything to continue!");
                        Console.ReadLine();
                    }
                    catch (IndexOutOfRangeException)
                    {
                        Console.WriteLine("Position out of bounds!");
                        Console.ReadLine();
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Invalid input format!");
                        Console.ReadLine();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Unexpected error!");
                        Console.ReadLine();
                    }
                }
            }
            catch (ChessBoardException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                ChessMatch match = new ChessMatch();

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

                        Console.WriteLine();
                        Console.Write("Original: ");
                        // It is always necessary to transform the position provided by the user (chess position) into a matrix position
                        PositionBoard originalPosition = Screen.ReadChessPosition().ChessPositionToMatrixPosition();
                        match.ValidateOriginalPosition(originalPosition);

                        // pick up the required piece in the original position, check which movements are possible and store it in the matrix
                        bool[,] PossiblePositions = match.Board.Piece(originalPosition).PossibleMoviments();

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

                        Console.WriteLine();
                        Console.Write("Destination: ");
                        PositionBoard destinationPosition = Screen.ReadChessPosition().ChessPositionToMatrixPosition();
                        match.ValidateDestinationPosition(originalPosition, destinationPosition);
                        match.MakeAMove(originalPosition, destinationPosition);
                    }
                    catch (BoardException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }
                Console.Clear();
                Screen.PrintMatch(match);
            }
            catch (BoardException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                ChessMatch chessMatch = new ChessMatch();

                while (!chessMatch.Finished)
                {
                    try
                    {
                        Console.Clear();
                        GameWindow.PrintChessMatch(chessMatch);


                        Console.WriteLine();
                        Console.Write("Origin: ");
                        Position origin = GameWindow.ReadChessPosition().ToPosition();
                        chessMatch.ValidateOriginPosition(origin);

                        bool[,] possiblePositions = chessMatch.Board.piece(origin).PossibleMovements();
                        Console.Clear();
                        GameWindow.PrintBoardGame(chessMatch.Board, possiblePositions);

                        Console.Write("Destination: ");
                        Position destination = GameWindow.ReadChessPosition().ToPosition();
                        chessMatch.ValidateDestinationPosition(origin, destination);
                        chessMatch.MakeTheMovement(origin, destination);
                    }
                    catch (BoardExceptions ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.ReadLine();
                    }
                }
            }
            catch (BoardExceptions e)
            {
                Console.WriteLine(e.Message);
            }
        }