public static List <Tuple <uint, uint> > getCover(src.Board board, src.Piece piece) { // Get cover List <Tuple <uint, uint> > cover = new List <Tuple <uint, uint> >(); int x = (int)piece.getX(); int y = (int)piece.getY(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { // Do not cover self continue; } int nx = x + i; int ny = y + j; if (board.withinBoard(nx, ny)) { Square s = board.getSquareAt((uint)nx, (uint)ny); if ((piece.getColour() == "white" && s.getBlackCover() == 0) || (piece.getColour() == "black" && s.getWhiteCover() == 0)) { Tuple <uint, uint> t = new Tuple <uint, uint>((uint)nx, (uint)ny); if (!getEnemyKingReach(board, piece).Contains(t)) { cover.Add(t); } } } } } return(cover); }
protected override void OnPaint(PaintEventArgs pe) { // we draw the progressbar normally with // the flags sets to our settings // Setup graphics objects //Graphics g = drawControl.CreateGraphics(); Graphics g = pe.Graphics; // Calculate size parameters int squareWidth = this.Width / 9; int squareHeight = this.Height / 9; // Draw numbers and letters SolidBrush brushText = new SolidBrush(Color.Black); for (int i = 1; i <= 8; i++) { g.DrawString((char)(i + 'A' - 1) + "", new Font("Arial", 20), brushText, new Point((int)((i + 0.25) * squareWidth), (int)(squareHeight * 0.3))); g.DrawString((9 - i).ToString(), new Font("Arial", 20), brushText, new Point((int)(squareWidth * 0.3), (int)((i + 0.2) * squareHeight))); } // Draw squares SolidBrush brushWhite = new SolidBrush(Color.LightGray); SolidBrush brushBlack = new SolidBrush(Color.Gray); for (int y = 0; y <= 7; y++) { for (int x = 0; x <= 7; x++) { int drawX = (x + 1) * squareWidth; int drawY = (y + 1) * squareHeight; Rectangle rect = new Rectangle(drawX, drawY, squareWidth, squareHeight); // Draw square if ((y + x) % 2 == 0) { // White g.FillRectangle(brushWhite, rect); } else { // White g.FillRectangle(brushBlack, rect); } src.Square square = board.getSquareAt((uint)x, (uint)(7 - y)); if (square.getPiece() != null) { // Draw piece /*g.DrawString(square.getPiece().getColour().Replace('w', 'W').Replace('b', 'B'), * new Font("Arial", 10), * brushText, * new Point((int)(drawX + squareWidth * 0.2), (int)(drawY + squareHeight * 0.35))); * g.DrawString(square.getPiece().GetType().ToString().Substring(15), * new Font("Arial", 10), * brushText, * new Point((int)(drawX + squareWidth * 0.2), (int)(drawY + squareHeight * 0.55)));*/ src.Piece p = square.getPiece(); string type = p.GetType().Name; string colour = p.getColour().Replace('w', 'W').Replace('b', 'B'); string filename = type + "_" + colour; g.DrawImage(imageHandler.getImage(filename), new Point[] { new Point(drawX + 8, drawY + 8), new Point(drawX + squareWidth - 8, drawY + 8), new Point(drawX + 8, drawY + squareHeight - 8) }); } } } // Selection, moves and cover SolidBrush brushSelect = new SolidBrush(Color.Green); SolidBrush brushMoves = new SolidBrush(Color.Red); src.Move selectedMove = getSelectedMove(); if (selectedMove.hasFrom()) { src.Piece p = board.getPieceAt(selectedMove.FromX, selectedMove.FromY); if (p != null) { int drawX = ((int)selectedMove.FromX + 1) * squareWidth; int drawY = (7 - (int)selectedMove.FromY + 1) * squareHeight; // Mark selected square drawBorder(g, brushSelect, drawX, drawY, squareWidth, squareHeight, 5); foreach (Tuple <uint, uint> t in ChessForms.rules.Rules.getPossibleMoves(board, p)) { drawX = (int)(t.Item1 + 1) * squareWidth; drawY = (int)(7 - t.Item2 + 1) * squareHeight; drawBorder(g, brushMoves, drawX, drawY, squareWidth, squareHeight, 5); } } } brushWhite.Dispose(); brushBlack.Dispose(); //g.Dispose(); }