Esempio n. 1
0
        private void CreateChessBoard(string strFEN)
        {
            if (Board != null)
            {
                Board.CancelThinking();
                Board.Dispose();
            }
            panel1.Visible = true;
            panel1.Controls.Clear();
            clsOptions obj = new clsOptions();

            strFEN += " 0 1";

            int CellSize  = 60;
            int PieceSize = 55;

            Board = new UcChessBoard(obj.BoardStyle, obj.PieceStyle, eOwnSide, GameMode.VsHuman, CellSize, PieceSize, obj.PlaySound, strFEN);

            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);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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
            {
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        //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();
            }
        }
Esempio n. 6
0
        private void btnOptions_Click(object sender, EventArgs e)
        {
            string strFEN = "";

            if (Board != null)
            {
                strFEN = clsFEN.GetFEN(Board);
            }

            frmOptions frm = new frmOptions();

            if (frm.ShowDialog() == DialogResult.OK && Board != null)
            {
                this._OwnSide  = Board.OwnSide;
                this._GameMode = Board.GameMode;
                Stack Black, White, State;

                Black = (Stack)Board.stkBlackMoves.Clone();
                White = (Stack)Board.stkWhiteMoves.Clone();
                State = (Stack)Board.stkState.Clone();

                Stack Captured = new Stack();
                foreach (UcChessPiece piece in Board.stkCapturedPieces)
                {
                    UcChessPiece p = new UcChessPiece();
                    p.PositionX = piece.PositionX;
                    p.PositionY = piece.PositionY;
                    p.Location  = piece.Location;
                    p.Side      = piece.Side;
                    p.Type      = piece.Type;
                    Captured.Push(p);
                }

                if (this._GameMode == GameMode.VsComputer)
                {
                    GameDifficulty diff = Board.Difficulty;

                    short m1, s1, m2, s2;
                    m1 = UcCountDownTimer1.Minute;
                    m2 = UcCountDownTimer2.Minute;
                    s1 = UcCountDownTimer1.Second;
                    s2 = UcCountDownTimer2.Second;
                    CreateChessBoard(this._OwnSide, this._GameMode, diff, strFEN);
                    UcCountDownTimer1.Minute = m1;
                    UcCountDownTimer2.Minute = m2;
                    UcCountDownTimer1.Second = s1;
                    UcCountDownTimer2.Second = s2;
                }
                else
                {
                    short m1, s1, m2, s2;
                    m1 = UcCountDownTimer1.Minute;
                    m2 = UcCountDownTimer2.Minute;
                    s1 = UcCountDownTimer1.Second;
                    s2 = UcCountDownTimer2.Second;
                    CreateChessBoard(this._OwnSide, this._GameMode, strFEN);
                    UcCountDownTimer1.Minute = m1;
                    UcCountDownTimer2.Minute = m2;
                    UcCountDownTimer1.Second = s1;
                    UcCountDownTimer2.Second = s2;
                }
                Board.stkBlackMoves = Black;
                Board.stkWhiteMoves = White;
                Board.stkState      = State;
                clsOptions obj = new clsOptions();
                foreach (UcChessPiece piece in Captured)
                {
                    UcChessPiece p = new UcChessPiece(piece.Side, piece.Type, obj.PieceStyle, obj.CellSize, obj.PieceSize, piece.PositionX, piece.PositionY, Board.arrChessCell[piece.PositionX, piece.PositionY]);
                    Board.stkCapturedPieces.Push(p);
                }

                ucCapturedPieces1.LoadPieces(Board.stkCapturedPieces);
                ucCapturedPieces2.LoadPieces(Board.stkCapturedPieces);
                UcMovesHistory1.LoadMovesHistory(Board.stkWhiteMoves, Board.stkBlackMoves);
            }
        }
Esempio n. 7
0
 private void frmOptions_Load(object sender, EventArgs e)
 {
     obj = new clsOptions();
     Load_Options();
 }