public void SetPosition() { for (int y = 0; y < 8; y++) { int yr = FormChess.boardRotate ? 7 - y : y; int y2 = frame + yr * field; for (int x = 0; x < 8; x++) { int i = y * 8 + x; int xr = FormChess.boardRotate ? 7 - x : x; int x2 = frame + xr * field; arrField[i].x = x2; arrField[i].y = y2; CPiece piece = arrField[i].piece; if (piece == null) { continue; } piece.SetPositionSta(x2, y2); } } }
public void RenderBoard() { bmpBoard = new Bitmap(background[FormChess.boardRotate ? 1 : 0]); Graphics g = Graphics.FromImage(bmpBoard); Brush brushRed = new SolidBrush(Color.FromArgb(0x80, 0xff, 0x00, 0x00)); Brush brushYellow = new SolidBrush(Color.FromArgb(0xa0, 0xff, 0xff, 0xff)); Brush brushWhite = new SolidBrush(Color.White); Brush brushBlack = new SolidBrush(Color.Black); Font fontPiece = new Font(FormChess.pfc.Families[0], field); Pen penW = new Pen(Color.Black, 4); Pen penB = new Pen(Color.White, 4); GraphicsPath gpW = new GraphicsPath(); GraphicsPath gpB = new GraphicsPath(); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; g.SmoothingMode = SmoothingMode.HighQuality; Rectangle rec = new Rectangle(); for (int y = 0; y < 8; y++) { int yr = FormChess.boardRotate ? 7 - y : y; int y2 = frame + yr * field; for (int x = 0; x < 8; x++) { int i = y * 8 + x; int xr = FormChess.boardRotate ? 7 - x : x; int x2 = frame + xr * field; rec.X = x2; rec.Y = y2; rec.Width = field; rec.Height = field; if ((i == CDrag.lastSou) || (i == CDrag.lastDes) || (arrField[i].color != Color.Empty)) { g.FillRectangle(brushYellow, rec); } else if (arrField[i].attacked && (CData.gameMode != CGameMode.edit)) { g.FillRectangle(brushRed, rec); } CPiece piece = arrField[i].piece; if (piece == null) { continue; } if (piece.image < 0) { continue; } GraphicsPath gp1; int image; if (piece.desImage >= 0) { gp1 = piece.desImage > 5 ? gpB : gpW; image = piece.desImage % 6; gp1.AddString("pnbrqk"[image].ToString(), fontPiece.FontFamily, (int)fontPiece.Style, fontPiece.Size, rec, sf); } arrField[i].x = x2; arrField[i].y = y2; piece.SetPositionAni(x2, y2); if ((i == CDrag.lastDes) && CDrag.dragged) { piece.SetPositionSta(CDrag.mouseX - frame - bmpX, CDrag.mouseY - frame - bmpY); } rec.X = piece.curXY.X; rec.Y = piece.curXY.Y; gp1 = piece.image > 5 ? gpB : gpW; image = piece.image % 6; gp1.AddString("pnbrqk"[image].ToString(), fontPiece.FontFamily, (int)fontPiece.Style, fontPiece.Size, rec, sf); } } if (FormChess.chess.whiteTurn) { g.DrawPath(penB, gpB); g.FillPath(brushBlack, gpB); g.DrawPath(penW, gpW); g.FillPath(brushWhite, gpW); } else { g.DrawPath(penW, gpW); g.FillPath(brushWhite, gpW); g.DrawPath(penB, gpB); g.FillPath(brushBlack, gpB); } sf.Dispose(); penW.Dispose(); penB.Dispose(); brushRed.Dispose(); brushYellow.Dispose(); brushWhite.Dispose(); brushBlack.Dispose(); fontPiece.Dispose(); g.Dispose(); }