private bool IsSquareWhite(BoardIndices loc) { //simplified from (row % 2 == 0 && col % 2 == 0 || row % 2 == 1 && col % 2 == 1); return (loc.Row % 2 == 0 ^ loc.Column % 2 == 1); }
private void DrawSquare(Graphics g, BoardIndices loc) { using (Brush b = new SolidBrush(IsSquareWhite(loc) ? Color.LightGray : Color.Gray)) { g.FillRectangle(b, new Rectangle(GetLeftmostX(loc.Column), GetTopmostY(loc.Row), SQUARE_LENGTH, SQUARE_LENGTH)); } }
private void ChangeSquareBorderColor(Graphics g, Color color, BoardIndices loc) { int width = Math.Max(BORDER_WIDTH / 2, 1); using (Pen p = new Pen(color)) { g.DrawRectangle(p, new Rectangle(GetLeftmostX(loc.Column) - width, GetTopmostY(loc.Row) - width, SQUARE_LENGTH + width, SQUARE_LENGTH + width)); } }
private void DrawPiece(Graphics g, BoardIndices loc, bool white, PieceType type) { Image img = white ? ChessPieceImageFactory.GetWhitePiece(type) : ChessPieceImageFactory.GetBlackPiece(type); int iconWidth = img.Width, iconHeight = img.Height; g.DrawImage(img, GetLeftmostX(loc.Column) + SQUARE_LENGTH / 2 - iconWidth / 2, GetTopmostY(loc.Row) + SQUARE_LENGTH / 2 - iconHeight / 2, iconWidth, iconHeight); }
internal SquareCoordinates(bool whiteOnBottom, BoardIndices loc) { file = whiteOnBottom ? loc.Column : (7 - loc.Column); rank = whiteOnBottom ? (7 - loc.Row) : loc.Row; }