public void DrawChessMan(ChessColor p, int XX, int YY) { if (chessMx.isSpace(XX, YY)) { chessMx.ChessDown(p, XX, YY); lock (_lock) { Graphics g = Graphics.FromImage(mybmp); { ChessMan.DrawChessMan(g, p, XX * 40 + 60, YY * 40 + 60); } g.Dispose(); } Invalidate(); ChessColor WinnerColor = chessMx.win(XX, YY); if (WinnerColor != ChessColor.Space) { MessageBox.Show(WinnerColor.ToString() + " win!"); } if (p == ChessColor.Black) { chessState = ChessColor.White; } else { chessState = ChessColor.Black; } } }
private PictureBox LoadPic(ChessColor color, ChessEnum chess, Point point, bool CreateEvent = true) { PictureBox Pic = new PictureBox() { Width = ChessEdge, Height = ChessEdge, Image = Image.FromFile(FolderImage + color.ToString() + "\\" + chess.ToString() + ".png"), BackColor = DefaultColor, BorderStyle = BorderStyle.FixedSingle, Location = point }; if (CreateEvent) { Pic.MouseMove += Pic_MouseMove; Pic.MouseUp += Pic_MouseUp; Pic.MouseDown += Pic_MouseDown; } return(Pic); }
public override string ToString() { return(String.Format("{0} {1}", Color.ToString(), this.GetType().Name)); }
private void Pic_MouseUp(object sender, MouseEventArgs e) { if (isMove) { isMove = false; } else { return; } int _x = 0, _y = 0; Point pos = new Point(); ChessColor lose = ChessColor.Die; if (CheckDropTrueSquare(ref _x, ref _y) && CheckDropTruePosAllow(_x, _y, ref pos)) { //if eat foreach (PictureBox pic in listchess) { if (pic.Location == pos) { pic.Visible = false; pic.Dispose(); ChessBoard.Controls.Remove(pic); listchess.Remove(pic); if (Map_Chess[pos.X / 57, pos.Y / 57].ChessType != ChessEnum.King) { CheckPieceDie(Map_Chess[pos.X / 57, pos.Y / 57]); } break; } } ChessPosition pos_map = GetPosMapsChess(((PictureBox)sender).Location); ChessPiece map = Map_Chess[pos_map.X, pos_map.Y]; ((PictureBox)sender).Location = pos; ChessPosition pos_map_ = GetPosMapsChess(((PictureBox)sender).Location); //check king if (Map_Chess[pos_map_.X, pos_map_.Y].ChessType == ChessEnum.King) { lose = Map_Chess[pos_map_.X, pos_map_.Y].Color; } //check pawn if (Map_Chess[pos_map.X, pos_map.Y].ChessType == ChessEnum.Pawn) { if (pos_map_.Y == 0 || pos_map_.Y == 7) { PawnUnderPromotion nform = new PawnUnderPromotion(Map_Chess[pos_map.X, pos_map.Y].Color); nform.ShowDialog(); switch (nform.chess) { case ChessEnum.Bishop: map = new PieceClass.Bishop(Map_Chess[pos_map.X, pos_map.Y].Color); break; case ChessEnum.Rook: map = new PieceClass.Rook(Map_Chess[pos_map.X, pos_map.Y].Color); break; case ChessEnum.Knight: map = new PieceClass.Knight(Map_Chess[pos_map.X, pos_map.Y].Color); break; case ChessEnum.Queen: map = new PieceClass.Queen(Map_Chess[pos_map.X, pos_map.Y].Color); break; } ((PictureBox)sender).Image = Image.FromFile(FolderImage + Map_Chess[pos_map.X, pos_map.Y].Color.ToString() + "\\" + nform.chess.ToString() + ".png"); ((PictureBox)sender).BringToFront(); } } //overwrite new pos Map_Chess[pos_map_.X, pos_map_.Y] = map; //clear old pos maps Map_Chess[pos_map.X, pos_map.Y] = new PieceClass.None(); reportmove(pos_map.X, pos_map.Y, pos_map_.X, pos_map_.Y, map); //change round round = round == ChessColor.Black ? ChessColor.White : ChessColor.Black; } //clean ((PictureBox)sender).Visible = true; ChessBoard.Controls.Remove(temp_pic); temp_pic.Dispose(); temp_pic = null; foreach (PictureBox pic in listchess) { if (pic.BackColor == canmove_color) { pic.BackColor = DefaultColor; } } foreach (PictureBox pic in listBackground) { if (pic.BackColor == canmove_color) { pic.BackColor = ((pic.Location.X / 57) + (pic.Location.Y / 57)) % 2 == 0 ? Color.Gray : Color.DarkGray; } } if (lose != ChessColor.Die) { MessageBox.Show(lose.ToString() + " lose."); MakeNewRound(); Application.Exit(); return; } playerturn(); GC.Collect(); }