private void Uc_ChessCell_Click(object sender, EventArgs e)
        {
            // if we are in capturing Mode then exit
            if (Uc_ChessBoard._isCapturingMode)
            {
                return;
            }

            //Get the present Uc_ChessBoard
            Uc_ChessBoard uc_chessboard = (Uc_ChessBoard)this.Parent;

            //If this cell is clicked and highlighted => will be eated by uc_chessboard.PositionChoosen cell
            if (uc_chessboard.PositionChoosen.X != 0 && uc_chessboard.PositionChoosen.Y != 0)
            {
                foreach (ChessMove p in uc_chessboard.arrCanMove)
                {
                    if (this._position.X == p.MoveTo.X && this._position.Y == p.MoveTo.Y)
                    {
                        uc_chessboard.DoMove(p);
                        uc_chessboard.PositionChoosen = new Point(0, 0); //this cell was eated so there's no Position Choosen

                        if (uc_chessboard.GameMode == eGameMode.VsComputer)
                        {
                            uc_chessboard.IsThinking = true;
                            if (uc_chessboard.GameStatus == eGameStatus.Playing)
                            {
                                uc_chessboard.Computer_Move();
                            }
                        }
                        return;
                    }
                }

                //If this Point wasn't eated => reset PositionChoosen and Unhighlight
                uc_chessboard.UnHighLightMoves();
                uc_chessboard.HighLightWhoCheckAndKingChecked();
                uc_chessboard.PositionChoosen = new Point(0, 0);
            }
        }
Exemple #2
0
        public Save_Load_ChessBoard(Uc_ChessBoard board, Uc_CountDownTimer timer1, Uc_CountDownTimer timer2)
        {
            //Save Chess Board
            this.SaveThisState = new ChessState[10, 10];

            int i, j;

            for (i = 0; i < 10; i++)
            {
                for (j = 0; j < 10; j++)
                {
                    SaveThisState[i, j] = new ChessState(board.arrState[i, j].Type, board.arrState[i, j].Side, board.arrState[i, j].Moves);
                }
            }

            this.GameStatus         = board.GameStatus;
            this.GameStatusReason   = board.GameStatusReason;
            this.WhoTurn            = board.WhoTurn;
            this.arrWhoCheck        = board.arrWhoCheck;
            this.stkUndo            = board.stkUndo;
            this.stkRedo            = board.stkRedo;
            this.stkChessMoveString = board.stkChessMoveString;
            this.stkChessPieceEated = board.stkChessPieceEated;
            this.clear_Stack_Redo   = board.clear_Stack_Redo;
            this.PositionLastMove   = new Point(Uc_ChessBoard.PositionLastMove.X, Uc_ChessBoard.PositionLastMove.Y);
            this.PositionChoosen    = new Point(board.PositionChoosen.X, board.PositionChoosen.Y);
            this.arrPosition        = board.arrPosition;
            this.OwnSide            = board.OwnSide;
            this.GameMode           = board.GameMode;
            this.GameDifficulty     = board.GameDifficulty;

            //Save Timer
            this.Min1 = timer1.Min;
            this.Sec1 = timer1.Sec;
            this.Min2 = timer2.Min;
            this.Sec2 = timer2.Sec;
        }
Exemple #3
0
        private void Uc_ChessPiece_Click(object sender, EventArgs e)
        {
            // if we are in capturing Mode then exit
            if (Uc_ChessBoard._isCapturingMode)
            {
                return;
            }

            //Get the present Uc_ChessBoard
            Uc_ChessBoard uc_chessboard = (Uc_ChessBoard)this.Parent;

            //If this cell is clicked and highlighted => will be eated by uc_chessboard.PositionChoosen cell
            if (uc_chessboard.PositionChoosen.X != 0 && uc_chessboard.PositionChoosen.Y != 0)
            {
                //if choose this position again -> remove choose
                if (uc_chessboard.PositionChoosen.X == this.Position.X && uc_chessboard.PositionChoosen.Y == this.Position.Y)
                {
                    uc_chessboard.UnHighLightMoves();
                    uc_chessboard.HighLightWhoCheckAndKingChecked();
                    uc_chessboard.PositionChoosen = new Point(0, 0);
                    return;
                }

                foreach (ChessMove p in uc_chessboard.arrCanMove)
                {
                    if (this._position.X == p.MoveTo.X && this._position.Y == p.MoveTo.Y)
                    {
                        uc_chessboard.DoMove(p);
                        uc_chessboard.PositionChoosen = new Point(0, 0); //this cell was eated so there's no Position Choosen

                        //Computer's move
                        if (uc_chessboard.GameMode == eGameMode.VsComputer)
                        {
                            uc_chessboard.IsThinking = true;
                            if (uc_chessboard.GameStatus == eGameStatus.Playing)
                            {
                                uc_chessboard.Computer_Move();
                            }
                        }
                        return;
                    }
                }

                //If this Point wasn't eated => reset PositionChoosen and Unhighlight
                uc_chessboard.UnHighLightMoves();
                uc_chessboard.PositionChoosen = new Point(0, 0);

                //Make this Point -> Position Choosen
                uc_chessboard.arrCanMove.Clear();

                //if this point = position choosen -> return

                if ((uc_chessboard.OwnSide == this._side || uc_chessboard.GameMode == eGameMode.VsHuman) &&
                    uc_chessboard.GameStatus == eGameStatus.Playing)
                {
                    if ((uc_chessboard.WhoTurn == eChessSide.White && this._side == eChessSide.White) ||
                        (uc_chessboard.WhoTurn == eChessSide.Black && this._side == eChessSide.Black))
                    {
                        uc_chessboard.arrCanMove = Chess_Engine.FindAllPosibleMoves(uc_chessboard.arrState, this._position, uc_chessboard.OwnSide);

                        uc_chessboard.PositionChoosen = new Point(_position.X, _position.Y);
                        uc_chessboard.UnHighLightWhoCheckAndKingChecked();
                        uc_chessboard.UnHighLightLastMove();
                        uc_chessboard.HighLightAllPosibleMoves();
                    }
                }
            }
            else
            {
                //If this Point isn't highlighted

                //Make this Point -> Position Choosen
                uc_chessboard.arrCanMove.Clear();

                //if this point = position choosen -> return

                if ((uc_chessboard.OwnSide == this._side || uc_chessboard.GameMode == eGameMode.VsHuman) &&
                    uc_chessboard.GameStatus == eGameStatus.Playing)
                {
                    if ((uc_chessboard.WhoTurn == eChessSide.White && this._side == eChessSide.White) ||
                        (uc_chessboard.WhoTurn == eChessSide.Black && this._side == eChessSide.Black))
                    {
                        uc_chessboard.arrCanMove = Chess_Engine.FindAllPosibleMoves(uc_chessboard.arrState, this._position, uc_chessboard.OwnSide);

                        uc_chessboard.PositionChoosen = new Point(_position.X, _position.Y);
                        uc_chessboard.UnHighLightWhoCheckAndKingChecked();
                        uc_chessboard.UnHighLightLastMove();
                        uc_chessboard.HighLightAllPosibleMoves();
                    }
                }
            }
        }