Exemplo n.º 1
0
        private void PrintBoardOverlay(Chesspiece piece)
        {
            Console.Write("───────────────────────────┬");
            Console.Write("\n");
            List <int[]> LegalMoves = piece.LegalMoves();

            for (int i = 0; i < 8; i++)
            {
                Console.Write("{0} ", 8 - i);
                for (int j = 0; j < 8; j++)
                {
                    if (i == piece.row && j == piece.column)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                    }

                    foreach (int[] legalMove in LegalMoves)
                    {
                        if (legalMove[0] == i && legalMove[1] == j)
                        {
                            if (board[i, j] != null)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                            }
                        }
                    }

                    if (board[i, j] != null)
                    {
                        Console.Write("[#]");
                    }
                    else if (board[i, j] == null)
                    {
                        Console.Write("[ ]");
                    }

                    Console.ResetColor();
                }
                Console.Write("\n");
            }
            Console.Write("   ");
            for (int i = 0; i < 8; i++)
            {
                Console.Write("{0}  ", Convert.ToChar(i + 65));
            }
            Console.Write("\n");
            Console.Write("───────────────────────────┴");
            Console.Write("\n");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Chesspiece selectedPiece = null;
            Chessboard chessboard    = new Chessboard();

            while (!chessboard.isGameOver)
            {
                Console.WriteLine("1 = GetPiece(row, column)");
                Console.WriteLine("2 = Move(initRow, initCol, toRow, toCol)");
                Console.WriteLine("3 = PrintBoard()");
                Console.WriteLine("───────────────────────────┼");
                Console.Write("Choice: ");
                if (int.TryParse(Console.ReadLine(), out int choice))
                {
                    int selectedRow;
                    int selectedCol;
                    switch (choice)
                    {
                    case 1:
                        Console.Write("Enter Row: ");
                        selectedRow = int.Parse(Console.ReadLine());
                        Console.Write("Enter Column: ");
                        selectedCol = int.Parse(Console.ReadLine());

                        selectedPiece = chessboard.GetPiece(selectedRow, selectedCol);
                        break;

                    case 2:
                        Console.Write("Enter initial Row: ");
                        selectedRow = int.Parse(Console.ReadLine());
                        Console.Write("Enter initial Column: ");
                        selectedCol = int.Parse(Console.ReadLine());

                        Console.Write("Enter final Row: ");
                        int finalRow = int.Parse(Console.ReadLine());
                        Console.Write("Enter final Column:");
                        int finalCol = int.Parse(Console.ReadLine());

                        chessboard.move(selectedRow, selectedCol, finalRow, finalCol);
                        break;

                    case 3:
                        chessboard.PrintBoard();
                        break;
                    }
                }
            }


            Console.ReadKey();
        }