Beispiel #1
0
        private new void Click(object sender, EventArgs e)
        {
            Button Btn = (Button)sender;
            int    x, y;

            //Subtract 48 to convert Char to Int
            x = Convert.ToInt16(Btn.Name[3]) - 48;
            y = Convert.ToInt16(Btn.Name[4]) - 48;

            if (selected && Piece_Selected[0] == x && Piece_Selected[1] == y)
            {
                selected = false;
                SetUpColours();
            }
            else if (!selected)
            {
                if (Board[x, y] != null)
                {
                    selected                = true;
                    Piece_Selected          = new int[] { x, y };
                    Buttons[x, y].BackColor = SelectedColour;
                    Highlightpossiblemoves();
                }
            }
            else if (selected)
            {
                int from_x, from_y, to_x, to_y;

                if (Buttons[x, y].BackColor == SelectedColour)
                {
                    from_x = Piece_Selected[0];
                    from_y = Piece_Selected[1];

                    to_x = x;
                    to_y = y;

                    Board    = Piece.Move(Board, from_x, from_y, to_x, to_y);
                    selected = false;

                    UpdatePiecesTaken();
                    SetUpColours();
                    ShowPieces();
                }
            }

            //Buttons[x, y].BackColor = Buttons[x, y].BackColor == FirstColour ? SecondColour : FirstColour;
        }
Beispiel #2
0
        /// <summary>
        /// Function tries to make move selected piece to selected location.
        /// </summary>
        /// <param name="board">Current board</param>
        /// <param name="enemy"></param>
        /// <param name="piece">Selected piece</param>
        /// <param name="destination">Selected destination</param>
        /// <returns>Returns true if player finished his move</returns>
        public bool Turn(CheckerBoard board, Player enemy, Piece piece, Position destination)
        {
            bool attackFlag = IsPossibleAttack(board);

            if (!IsCorrectPiece(piece))
            {
                return(false);
            }
            if (!piece.IsCorrectDestination(attackFlag, destination, board))
            {
                return(false);
            }
            if (attackPiece != null && piece != attackPiece)
            {
                return(false);
            }
            if (piece.CanAttack(board))
            {
                numberOfMovementsWithoutAttack = 0;
                Piece deletePiece = piece.FunkcjaCudzika(board, destination);
                deletePiece.RemovePiece(board, enemy.pieces);
            }
            else
            {
                if (piece.GetType() == typeof(Queen))
                {
                    numberOfMovementsWithoutAttack++;
                }
            }
            piece.Move(board, destination);
            if (attackFlag && piece.CanAttack(board))
            {
                attackPiece = piece;
                return(false);
            }
            attackPiece = null;
            if (piece.IsBecomeQueen())
            {
                piece.ChangePieceToQueen(board, this.pieces);
            }
            return(true);
        }