static void Main(string[] args) { Console.CursorVisible = false; ConsoleGraphics graphics = new ConsoleGraphics(); game = new ChessGame(); do { game.Draw(graphics); graphics.SwapBuffers(); game.Update(); } while (game.Running); Console.Read(); }
/// <summary> /// Draws the game /// </summary> /// <param name="g">ConsoleGraphics object to draw with/to</param> public void Draw(ConsoleGraphics g) { g.FillArea(new CChar(' ', ConsoleColor.Black, ConsoleColor.DarkGray), 10, 5, 8, 8); //7-j everywhere cuz it's reversed in chess for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { //Draw the symbol ChessBoard.Cell cell = board.GetCell(i, j); if (cell.Piece != null) { g.DrawTransparent(cell.Piece.Char, (cell.Piece.Color == PlayerColor.White) ? ConsoleColor.White : ConsoleColor.Black, 10 + i, 5 + (7 - j)); if (cell.Piece.LegalMoves.Count == 0) { g.SetBackground(ConsoleColor.DarkRed, 10 + i, 5 + (7 - j)); } } if (cell.HitBy.Contains(debugPiece)) { g.SetBackground(ConsoleColor.DarkMagenta, 10 + i, 5 + (7 - j)); } } } if (holdedNode != null && playerState == PlayerState.Holding) { //Highlight legal moves foreach (ChessBoard.Cell move in holdedNode.Piece.LegalMoves) { g.SetBackground(ConsoleColor.DarkGreen, 10 + move.X, 5 + (7 - move.Y)); } } //Sets the cursor color -> yellow g.SetBackground(ConsoleColor.DarkYellow, 10 + cursorX, 5 + (7 - cursorY)); //TODO: Remove en passant testing /*if (board.EnPassant != null) * g.SetBackground(ConsoleColor.DarkCyan, 10 + board.EnPassant.X, 5 + (7 - board.EnPassant.Y)); * * if (board.EnPassantCapture != null) * g.SetBackground(ConsoleColor.DarkMagenta, 10 + board.EnPassantCapture.X, 5 + (7 - board.EnPassantCapture.Y));*/ //Lighten for checkerboard pattern for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if ((i + j) % 2 == 1) { g.LightenBackground(10 + i, 5 + j); } } } //Promotion option menu if (playerState == PlayerState.AwaitPromote) { g.DrawTextTrasparent("Queen", promoteOption == PromoteOptions.Queen ? ConsoleColor.Yellow : ConsoleColor.White, 22, 7); g.DrawTextTrasparent("Rook", promoteOption == PromoteOptions.Rook ? ConsoleColor.Yellow : ConsoleColor.White, 22, 9); g.DrawTextTrasparent("Bishop", promoteOption == PromoteOptions.Bishop ? ConsoleColor.Yellow : ConsoleColor.White, 22, 11); g.DrawTextTrasparent("Knight", promoteOption == PromoteOptions.Knight ? ConsoleColor.Yellow : ConsoleColor.White, 22, 13); } else { g.ClearArea(22, 7, 6, 7); } }