Ejemplo n.º 1
0
        public void MakeMove(int gm)
        {
            animated = true;
            int flags = gm & 0xFF0000;
            int sou   = gm & 0xFF;
            int des   = (gm >> 8) & 0xFF;
            int xs    = (sou & 0xf) - 4;
            int ys    = (sou >> 4) - 4;
            int xd    = (des & 0xf) - 4;
            int yd    = (des >> 4) - 4;

            sou = ys * 8 + xs;
            des = yd * 8 + xd;
            CPiece pd = arrField[des].piece;

            if (pd != null)
            {
                arrField[sou].piece.desImage = pd.image;
            }
            MakeMove(sou, des);
            if ((flags & CChess.moveflagCastleKing) > 0)
            {
                MakeMove(sou + 3, sou + 1);
            }
            if ((flags & CChess.moveflagCastleQueen) > 0)
            {
                MakeMove(sou - 4, sou - 1);
            }
            ClearColors();
        }
Ejemplo n.º 2
0
 public static void UpdatePosition()
 {
     animated = false;
     foreach (CField f in arrField)
     {
         CPiece p = f.piece;
         if (p != null)
         {
             if (p.UpdatePosition())
             {
                 animated = true;
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static void UpdateField(int index)
        {
            int i = CChess.arrField[index];
            int f = FormChess.chess.g_board[i];

            if ((f & CChess.colorEmpty) > 0)
            {
                arrField[index].piece = null;
            }
            else
            {
                CPiece piece = new CPiece();
                arrField[index].piece = piece;
                piece.SetImage(index);
            }
        }
Ejemplo n.º 4
0
 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);
         }
     }
 }
Ejemplo n.º 5
0
        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();
        }