Exemplo 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);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                ChessMatch match = new ChessMatch();

                while (!match.finished)
                {
                    try
                    {
                        Console.Clear();
                        Screen.PrintScreen(match);

                        Console.WriteLine();
                        Console.Write("Piece: ");
                        Position origin = Screen.ReadPosition().ToPosition();
                        match.ValidateOriginPosition(origin);

                        bool[,] possiblePositions = match.chessBoard.Piece(origin).PossibleMovements();

                        Console.Clear();
                        Screen.PrintPossibleMovements(match.chessBoard, possiblePositions, match);

                        Console.WriteLine();
                        Console.Write("Move to: ");
                        Position destiny = Screen.ReadPosition().ToPosition();
                        match.ValidadeDestinyPosition(origin, destiny);

                        match.MoveMade(origin, destiny);
                    }
                    catch (BoardException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }
                Console.Clear();
                Screen.PrintScreen(match);
            }
            catch (BoardException e)
            {
                Console.WriteLine(e.Message);
            }

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

                while (!match.Endgame)
                {
                    try
                    {
                        Console.Clear();
                        Screen.PrintChessMacth(match);

                        Console.WriteLine();

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

                        bool[,] possiblePositions = match.Board.Piece(origin).PossibleMovements();

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

                        Console.WriteLine();
                        Console.Write("Destino: ");
                        Position destination = Screen.ReadChessPosition().ToPosition();
                        match.ValidadeDestinationPosition(origin, destination);

                        match.MakeMove(origin, destination);
                    }
                    catch (GameBoardException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }

                Console.Clear();
                Screen.PrintChessMacth(match);
            }
            catch (GameBoardException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ChessMatch match = new ChessMatch();

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

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

                    bool[,] possiblePositions = match.Board.Piece(origin).PossibleMoves();

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

                    Console.WriteLine();
                    Console.Write("Destiny: ");
                    Position destiny = Screen.ReadChessPosition().ToPosition();
                    match.ValidateDestinyPosition(origin, destiny);

                    match.PerformMove(origin, destiny);
                }
                catch (BoardException e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.Clear();
            Screen.PrintMatch(match);



            Console.ReadLine();
        }
Exemplo n.º 5
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);
            }
        }