Exemplo n.º 1
0
        public static List <Field> getExplodedFields(Bomb explodedBomb, GameBoard gameBoard, IGameController gameController)
        {
            Field place = explodedBomb.getOwner().Field;

            List <Field> retVals = new List <Field>();

            for (int iX = place.X; iX >= gameBoard.MinX && place.X - iX <= explodedBomb.getExplosiveRadius(); --iX)
            {
                Field currentField = gameBoard.getField(iX, place.Y);
                if (currentField != null && gameController.isExplodable(currentField))
                {
                    retVals.Add(currentField);
                }
                if (!gameController.isExplodable(currentField))
                {
                    break;
                }
            }
            for (int iX = place.X + 1; iX <= gameBoard.MaxX && iX - place.X <= explodedBomb.getExplosiveRadius(); ++iX)
            {
                Field currentField = gameBoard.getField(iX, place.Y);
                if (currentField != null && gameController.isExplodable(currentField))
                {
                    retVals.Add(currentField);
                }
                if (!gameController.isExplodable(currentField))
                {
                    break;
                }
            }

            for (int iY = place.Y - 1; iY >= gameBoard.MinY && place.Y - iY <= explodedBomb.getExplosiveRadius(); --iY)
            {
                Field currentField = gameBoard.getField(place.X, iY);
                if (currentField != null && gameController.isExplodable(currentField))
                {
                    retVals.Add(currentField);
                }
                if (!gameController.isExplodable(currentField))
                {
                    break;
                }
            }
            for (int iY = place.Y + 1; iY <= gameBoard.MaxY && iY - place.Y <= explodedBomb.getExplosiveRadius(); ++iY)
            {
                Field currentField = gameBoard.getField(place.X, iY);
                if (currentField != null && gameController.isExplodable(currentField))
                {
                    retVals.Add(currentField);
                }
                if (!gameController.isExplodable(currentField))
                {
                    break;
                }
            }

            return(retVals);
        }
Exemplo n.º 2
0
        /// <summary>
        /// applies 'applyFieldExplosion' in the order of explosions and explodes the bombs in the radius recursively.
        /// </summary>
        /// <param name=""></param>
        public void explodeFields(IGameController gameController, Bomb bomb, ExplosionFieldCollector explodedFields, int recursionCounter = 0)
        {
            if (bomb == null)
            {
                return;
            }
            Explosion    explosion = new Explosion(this, bomb);
            List <Field> fields    = explosion.getExplodedFields(gameController);

            foreach (Field currentField in fields)
            {
                if (!bomb.IsExploded)
                {
                    //add all of the exploded fields to the collection
                    explodedFields.addExplodedField(recursionCounter, explosion.getDistanceFactor(currentField), currentField);
                    currentField.IsExploding = true;
                }
            }
            Field fieldOfBomb = bomb.Field;

            fieldOfBomb.removeBomb(bomb);
            bomb.getOwner().removeBomb(bomb);
            bomb.IsExploded = true;

            //explode the recursively activated bombs
            foreach (Field currentField in fields)
            {
                if (currentField.isBombed())    //if there is a bomb on a field inside the radius of the original bomb
                {
                    Bomb[] currentFieldBombs = currentField.getBombs();
                    for (int i = 0; i < currentFieldBombs.Length; ++i)
                    {
                        if (currentFieldBombs[i] != null)
                        {
                            explodeFields(gameController, currentFieldBombs[i], explodedFields, recursionCounter + 1);
                        }
                    }
                }
            }
        }