Exemple #1
0
        /// <summary>
        /// Function that will determine all possible moves for the piece
        /// </summary>
        /// <param name="gameBoard">The gameboard</param>
        /// <param name="gameState">The current state of the game</param>
        /// <param name="noShow">Whether or not to mark the board</param>
        /// <returns>Type of move the piece has (NONE, MOVE, JUMP)</returns>
        public TileStatus determineMoves(CheckersBoard gameBoard, CheckersGameState gameState, bool noShow = false)
        {
            TileStatus foundMove = TileStatus.NONE;

            possibleMoves.Clear();

            Vector2 tilePosition = new Vector2(position.X, position.Y);

            List <GameMove> jumps = getJumps(tilePosition, gameBoard, gameState);

            //Look for any jumps by the piece
            if (jumps.Count != 0)
            {
                foundMove            = TileStatus.JUMP;
                possibleMoves        = jumps;
                gameState.jumpExists = true;
                //Reset that the piece was just jumped over
                //Necessary for multi-jumps
                if (color == PieceColor.Black)
                {
                    foreach (CheckersPiece piece in gameState.whiteGamePieces)
                    {
                        piece.justJumpedOver = false;
                    }
                }
                else if (color == PieceColor.White)
                {
                    foreach (CheckersPiece piece in gameState.blackGamePieces)
                    {
                        piece.justJumpedOver = false;
                    }
                }
            }
            //If no jump was found in the context of the turn find possible regular moves for the piece
            else if (gameState.jumpExists == false)
            {
                List <GameMove> regularMoves = getRegularMoves(tilePosition, gameBoard, gameState);
                if (regularMoves.Count != 0)
                {
                    foundMove     = TileStatus.MOVE;
                    possibleMoves = regularMoves;
                }
            }
            if (noShow == false)
            {
                gameBoard.clearMarkings();
                if (foundMove != TileStatus.NONE)
                {
                    foreach (GameMove move in possibleMoves)
                    {
                        gameBoard.getTileAt(move.destinationPosition).setStatus(foundMove);
                    }
                }
            }
            return(foundMove);
        }
Exemple #2
0
        /// <summary>
        /// This function is for handling any tile actions.
        /// Function takes a tile as a parameter. If the tile is marked as a possible move,
        /// then the function will apply the logic necessary for the move.
        /// </summary>
        /// <param name="tile">A tile to do an action on</param>
        /// <returns>Whether or not the tile was valid for move</returns>
        public bool doTileAction(BoardTile tile)
        {
            bool            actionDone     = false;
            List <GameMove> availableMoves = new List <GameMove>();

            //Apply logic only if the tile is marked for a possible action (i.e. MOVE, JUMP)
            if (tile.getStatus() != TileStatus.NONE)
            {
                //Get the moves for the active piece
                availableMoves = activeGamePiece.getPossibleMoves();
                //The below loop finds the move that the tile correlates to
                foreach (GameMove move in availableMoves)
                {
                    //Below is the logic for when the move is found
                    if (tile.position == move.destinationPosition)
                    {
                        //If the tile is marked for jump, also capture the pieces
                        //  specified in the move and remove them
                        if (tile.getStatus() == TileStatus.JUMP)
                        {
                            //Capture the pieces specified in the move
                            foreach (CheckersPiece capturedPiece in move.capturedPieces)
                            {
                                var piece = getPiece(capturedPiece.getColor(), capturedPiece.position);
                                activeGamePiece.Capture(piece, gameBoard.getTileAt(capturedPiece.position));
                            }
                            //Remove captured pieces from the game
                            removeCapturedPieces();
                        }

                        //Move the active piece to the destination tile
                        activeGamePiece.moveTo(tile);
                        //Unoccupy the tile the active piece came from
                        gameBoard.getTileAt((int)(activeGamePiece.position.X), (int)(activeGamePiece.position.Y)).unOccupy();
                        //Remove all marking of tiles
                        gameBoard.clearMarkings();
                        actionDone = true;
                        break;
                    }
                }
            }
            return(actionDone);
        }