Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();

                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();
            }
        }