void Load_Game() { if (Board != null) { Board.CancelThinking(); Board.Dispose(); } CreateChessBoard(strFEN); }
bool PreviewFEN(string strFEN) { try { int size = 45; string s = strFEN.Split(' ')[1]; if (s.ToUpper() == "W") { lblWhoMove.Text = "Quân Trắng Đi Trước"; } else { lblWhoMove.Text = " Quân Đen Đi Trước"; } UcChessBoard board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, ChessSide.White, GameMode.VsNetWorkPlayer, size, size, false, strFEN); Bitmap bmp = board.TakePicture(size * 8, size * 8); pictureBox1.Image = bmp; board.Dispose(); return(true); } catch { MessageBox.Show("Dữ Liệu Không Phù Hợp !!!"); return(false); } }
private void CreateChessBoard(string strFEN, GameDifficulty eDifficulty) { if (Board != null) { Board.CancelThinking(); Board.Dispose(); } panel1.Visible = true; panel1.Controls.Clear(); clsOptions obj = new clsOptions(); string s = strFEN.Split(' ')[1].ToUpper(); strFEN += " 0 1"; ChessSide eOwnSide; if (s == "W") { eOwnSide = ChessSide.White; } else { eOwnSide = ChessSide.Black; } int CellSize = 65; int PieceSize = 60; Board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, eOwnSide, GameMode.VsComputer, eDifficulty, CellSize, PieceSize, obj.PlaySound, strFEN); Board.MoveMaked += new UcChessBoard.MoveMakedHandler(MoveMaked); Bitmap bmpBackImage = new Bitmap(Board.Width, Board.Height); Board.DrawToBitmap(bmpBackImage, Board.Bounds); Board.BackgroundImage = bmpBackImage; Board.BoardBitMap = bmpBackImage; intNotationSize = (int)((CellSize * 38) / 100); AddNotation(CellSize, eOwnSide); Board.Location = new Point(intNotationSize, intNotationSize); this.panel1.Controls.Add(Board); this.panel1.ClientSize = new Size(CellSize * 8 + intNotationSize * 2, CellSize * 8 + intNotationSize * 2); }
void Fen2Pic(string strFEN) { int size = pictureBox1.Width / 8; clsOptions obj = new clsOptions(); UcChessBoard board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, ChessSide.White, GameMode.VsNetWorkPlayer, size, size, false, strFEN); Bitmap bmp = board.TakePicture(size * 8, size * 8); pictureBox1.Image = bmp; board.Dispose(); }
private void CreateChessBoard(ChessSide eOwnSide, GameMode eGameMode, string strFEN) { try { if (Board != null) { Board.Dispose(); if (UcMovesHistory1 != null) { UcMovesHistory1.Dispose(); } } panel1.Visible = true; panel1.Controls.Clear(); clsOptions obj = new clsOptions(); UcMovesHistory1 = new UcMovesHistory(); obj.CellSize = 55; Board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, eOwnSide, eGameMode, obj.CellSize, obj.CellSize, obj.PlaySound, strFEN); Board.MoveMaked += new UcChessBoard.MoveMakedHandler(Board_MoveMaked); Bitmap bmpBackImage = new Bitmap(Board.Width, Board.Height); Board.DrawToBitmap(bmpBackImage, Board.Bounds); Board.BackgroundImage = bmpBackImage; Board.BoardBitMap = bmpBackImage; pnlHistory.Visible = true; intNotationSize = (int)((obj.CellSize * 38) / 100); if (this.InvokeRequired) { this.Invoke(new dlgAddItemN(AddNotation), obj.CellSize, eOwnSide); } else { AddNotation(obj.CellSize, eOwnSide); } pnlHistory.Controls.Add(UcMovesHistory1); UcMovesHistory1.LoadMovesHistory(Board.stkWhiteMoves, Board.stkBlackMoves); Board.Location = new Point(intNotationSize, intNotationSize); panel1.Controls.Add(Board); this.panel1.ClientSize = new Size(obj.CellSize * 8 + intNotationSize * 2, obj.CellSize * 8 + intNotationSize * 2); } catch { } }
private void cboBoardStyle_SelectedIndexChanged(object sender, EventArgs e) { if (cboBoardStyle.SelectedIndex == -1 || cboPieceStyle.SelectedIndex == -1) { return; } try { ChessBoardStyle BoardStyle = (ChessBoardStyle)(cboBoardStyle.SelectedIndex + 1); ChessPieceStyle PieceStyle = (ChessPieceStyle)(cboPieceStyle.SelectedIndex + 1); UcChessBoard Board = new UcChessBoard(BoardStyle, PieceStyle, ChessSide.White, GameMode.VsNetWorkPlayer, 48, 48, false, "KQRBNP2/kqrbnp2/8/8/8/8/8/8"); pictureBox1.Image = Board.TakePicture(pictureBox1.Width, pictureBox1.Height); Board.Dispose(); } catch { } }
void Load_Options() { numCellSize.Value = obj.CellSize; numPieceSize.Value = obj.PieceSize; cboBoardStyle.SelectedIndex = ((int)obj.BoardStyle) - 1; cboPieceStyle.SelectedIndex = ((int)obj.PieceStyle) - 1; chkPlaySound.Checked = obj.PlaySound; try { UcChessBoard Board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, ChessSide.White, GameMode.VsNetWorkPlayer, 48, 48, false, "KQRBNP2/kqrbnp2/8/8/8/8/8/8 w - -"); pictureBox1.Image = Board.TakePicture(pictureBox1.Width, pictureBox1.Height); Board.Dispose(); } catch { } }
//Chơi với Người private void CreateChessBoard(ChessSide eOwnSide, GameMode eGameMode, string strFEN) { if (Board != null) { Board.CancelThinking(); Board.Dispose(); UcCountDownTimer1.StopTimer(); UcCountDownTimer2.StopTimer(); UcCountDownTimer1.Minute = TimeLimit; UcCountDownTimer2.Minute = TimeLimit; UcCountDownTimer1.Second = 0; UcCountDownTimer2.Second = 0; } else { ucCapturedPieces1 = new UcCapturedPieces(); ucCapturedPieces2 = new UcCapturedPieces(); UcMovesHistory1 = new UcMovesHistory(); UcCountDownTimer1 = new UcCountDownTimer(); UcCountDownTimer2 = new UcCountDownTimer(); UcCountDownTimer1.StopTimer(); UcCountDownTimer2.StopTimer(); UcCountDownTimer1.Minute = TimeLimit; UcCountDownTimer2.Minute = TimeLimit; UcCountDownTimer1.Second = 1; UcCountDownTimer2.Second = 1; UcCountDownTimer1.TimeOut += new UcCountDownTimer.TimeOutHandler(UcCountDownTimer1_TimeOut); UcCountDownTimer2.TimeOut += new UcCountDownTimer.TimeOutHandler(UcCountDownTimer2_TimeOut); } btnSaveGame.Enabled = true; pnlCapturedPiece1.Controls.Clear(); pnlCapturedPiece2.Controls.Clear(); pnlHistory.Controls.Clear(); pnlTimer1.Controls.Clear(); pnlTimer2.Controls.Clear(); pnlTimer1.Visible = true; pnlTimer2.Visible = true; pnlCapturedPiece1.Visible = true; pnlCapturedPiece2.Visible = true; pnlHistory.Visible = true; panel1.Visible = true; panel1.Controls.Clear(); clsOptions obj = new clsOptions(); Board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, eOwnSide, eGameMode, obj.CellSize, obj.PieceSize, obj.PlaySound, strFEN); //Captured Piece Collector ucCapturedPieces1.PieceColor = Board.OwnSide; //Moves History UcMovesHistory1.LoadMovesHistory(Board.stkWhiteMoves, Board.stkBlackMoves); pnlTimer1.Controls.Add(UcCountDownTimer1); pnlTimer2.Controls.Add(UcCountDownTimer2); if (Board.OwnSide == ChessSide.Black) { ucCapturedPieces2.PieceColor = ChessSide.White; } else { ucCapturedPieces2.PieceColor = ChessSide.Black; } pnlCapturedPiece1.Controls.Add(ucCapturedPieces1); pnlCapturedPiece2.Controls.Add(ucCapturedPieces2); pnlHistory.Controls.Add(UcMovesHistory1); Board.MoveMaked += new UcChessBoard.MoveMakedHandler(MoveMaked); Board.PieceCaptured += new UcChessBoard.PieceCapturedHandler(Board_PieceCaptured); ucCapturedPieces1.LoadPieces(Board.stkCapturedPieces); ucCapturedPieces2.LoadPieces(Board.stkCapturedPieces); if (Board.GameMode == GameMode.VsComputer) { btnHint.Enabled = true; } else { btnHint.Enabled = false; } Bitmap bmpBackImage = new Bitmap(Board.Width, Board.Height); Board.DrawToBitmap(bmpBackImage, Board.Bounds); Board.BackgroundImage = bmpBackImage; Board.BoardBitMap = bmpBackImage; intNotationSize = (int)((obj.CellSize * 38) / 100); AddNotation(obj.CellSize, eOwnSide); Board.Location = new Point(intNotationSize, intNotationSize); this.panel1.Controls.Add(Board); this.panel1.ClientSize = new Size(obj.CellSize * 8 + intNotationSize * 2, obj.CellSize * 8 + intNotationSize * 2); pnlCapturedPiece1.Size = ucCapturedPieces1.Size; pnlCapturedPiece2.Size = ucCapturedPieces2.Size; pnlHistory.Size = UcMovesHistory1.Size; int x = this.ClientSize.Width - pnlHistory.Size.Width; pnlHistory.Location = new Point(x, panel1.Location.Y); UcCountDownTimer1.Size = new Size(110, 35); UcCountDownTimer2.Size = new Size(110, 35); UcCountDownTimer1.Location = new Point(8, 8); UcCountDownTimer2.Location = new Point(8, 8); pnlTimer1.Size = new Size(UcCountDownTimer1.Width + 16, UcCountDownTimer1.Height + 16); pnlTimer2.Size = pnlTimer1.Size; pnlPlayer1.Visible = true; pnlPlayer2.Visible = true; pnlPlayer1.Location = new Point(5, 3); int w = this.ribbonClientPanel1.Height - pnlPlayer2.Height - 10; pnlPlayer2.Location = new Point(pnlPlayer1.Location.X, w); panel1.Location = new Point(pnlPlayer1.Location.X + pnlPlayer1.Width + 5, pnlPlayer1.Location.Y); pnlCapturedPiece1.Location = new Point(panel1.Location.X + panel1.Size.Width + 3, panel1.Location.Y + 2); pnlCapturedPiece2.Location = new Point(panel1.Location.X + panel1.Size.Width + 3, this.ribbonClientPanel1.Height - pnlCapturedPiece2.Height - 2); if (Board.OwnSide == ChessSide.White) { UcCountDownTimer2.StartTimer(); } else { UcCountDownTimer1.StartTimer(); } }
//Chơi với Người private void CreateChessBoard(ChessSide eOwnSide, GameMode eGameMode, string strFEN) { if (Board != null) { Board.CancelThinking(); Board.Dispose(); UcCountDownTimer1.StopTimer(); UcCountDownTimer2.StopTimer(); UcCountDownTimer1.Minute = TimeLimit; UcCountDownTimer2.Minute = TimeLimit; UcCountDownTimer1.Second = 0; UcCountDownTimer2.Second = 0; } else { ucCapturedPieces1 = new UcCapturedPieces(); ucCapturedPieces2 = new UcCapturedPieces(); UcCountDownTimer1 = new UcCountDownTimer(); UcCountDownTimer2 = new UcCountDownTimer(); UcCountDownTimer1.StopTimer(); UcCountDownTimer2.StopTimer(); UcCountDownTimer1.Minute = TimeLimit; UcCountDownTimer2.Minute = TimeLimit; UcCountDownTimer1.Second = 1; UcCountDownTimer2.Second = 1; UcCountDownTimer1.TimeOut += new UcCountDownTimer.TimeOutHandler(UcCountDownTimer1_TimeOut); UcCountDownTimer2.TimeOut += new UcCountDownTimer.TimeOutHandler(UcCountDownTimer2_TimeOut); } pnlCapturedPiece1.Controls.Clear(); pnlCapturedPiece2.Controls.Clear(); pnlTimer1.Controls.Clear(); pnlTimer2.Controls.Clear(); pnlTimer1.Visible = true; pnlTimer2.Visible = true; pnlCapturedPiece1.Visible = true; pnlCapturedPiece2.Visible = true; panel1.Visible = true; panel1.Controls.Clear(); Board = new UcChessBoard(ChessBoardStyle.Wooden, ChessPieceStyle.Wooden3D, eOwnSide, eGameMode, 75, 66, true, strFEN); ucCapturedPieces1.PieceColor = Board.OwnSide; pnlTimer1.Controls.Add(UcCountDownTimer1); pnlTimer2.Controls.Add(UcCountDownTimer2); if (Board.OwnSide == ChessSide.Black) { ucCapturedPieces2.PieceColor = ChessSide.White; } else { ucCapturedPieces2.PieceColor = ChessSide.Black; } pnlCapturedPiece1.Controls.Add(ucCapturedPieces1); pnlCapturedPiece2.Controls.Add(ucCapturedPieces2); Board.MoveMaked += new UcChessBoard.MoveMakedHandler(MoveMaked); Board.PieceCaptured += new UcChessBoard.PieceCapturedHandler(Board_PieceCaptured); ucCapturedPieces1.LoadPieces(Board.stkCapturedPieces); ucCapturedPieces2.LoadPieces(Board.stkCapturedPieces); Bitmap bmpBackImage = new Bitmap(Board.Width, Board.Height); Board.DrawToBitmap(bmpBackImage, Board.Bounds); Board.BackgroundImage = bmpBackImage; Board.BoardBitMap = bmpBackImage; intNotationSize = (int)((75 * 38) / 100); AddNotation(75, eOwnSide); Board.Location = new Point(intNotationSize, intNotationSize); this.panel1.Controls.Add(Board); this.panel1.ClientSize = new Size(75 * 8 + intNotationSize * 2, 75 * 8 + intNotationSize * 2); pnlCapturedPiece1.Size = ucCapturedPieces1.Size; pnlCapturedPiece2.Size = ucCapturedPieces2.Size; UcCountDownTimer1.Size = new Size(110, 35); UcCountDownTimer2.Size = new Size(110, 35); UcCountDownTimer1.Location = new Point(8, 8); UcCountDownTimer2.Location = new Point(8, 8); pnlTimer1.Size = new Size(UcCountDownTimer1.Width + 16, UcCountDownTimer1.Height + 16); pnlTimer2.Size = pnlTimer1.Size; pnlPlayer1.Visible = true; pnlPlayer2.Visible = true; pnlPlayer1.Location = new Point(105, 13); int w = this.ribbonClientPanel1.Height - pnlPlayer2.Height - 10; pnlPlayer2.Location = new Point(pnlPlayer1.Location.X, w - 30); panel1.Location = new Point(pnlPlayer1.Location.X + pnlPlayer1.Width + 355, pnlPlayer1.Location.Y); pnlCapturedPiece1.Location = new Point(panel1.Location.X + panel1.Size.Width + 323, panel1.Location.Y + 2); pnlCapturedPiece2.Location = new Point(panel1.Location.X + panel1.Size.Width + 323, this.ribbonClientPanel1.Height - pnlCapturedPiece2.Height - 2); if (Board.OwnSide == ChessSide.White) { UcCountDownTimer2.StartTimer(); } else { UcCountDownTimer1.StartTimer(); } }