Esempio n. 1
0
        private void TrySpreadEnvironment(Point position, Direction direction, IAreaMapCellInternal cell, CellPairsStorage mergedCells)
        {
            var nextPosition = Point.GetPointInDirection(position, direction);

            if (!ContainsCell(nextPosition))
            {
                return;
            }

            var nextCell = GetOriginalCell(nextPosition.X, nextPosition.Y);

            if (mergedCells.ContainsPair(position, direction))
            {
                return;
            }
            mergedCells.RegisterPair(position, direction);

            if (nextCell.BlocksEnvironment)
            {
                return;
            }

            cell.CheckSpreading(nextCell);
            cell.Environment.Balance(cell, nextCell);
        }
Esempio n. 2
0
        public AreaMap(
            int level,
            Func <IAreaMapCellInternal> cellFactory,
            int width,
            int height,
            IMapLightLevelProcessor mapLightLevelProcessor = null)
        {
            this.mapLightLevelProcessor = mapLightLevelProcessor ?? new MapLightLevelProcessor();

            objectPositionCache = new Dictionary <Type, Point>();
            destroyableObjects  = new Dictionary <string, IDestroyableObject>();

            Level  = level;
            Width  = width;
            Height = height;

            cells = new IAreaMapCellInternal[height][];
            for (var y = 0; y < height; y++)
            {
                cells[y] = new IAreaMapCellInternal[width];
                for (var x = 0; x < width; x++)
                {
                    cells[y][x] = cellFactory();
                }
            }
        }
Esempio n. 3
0
 private void SpreadEnvironment(Point position, IAreaMapCellInternal cell, CellPairsStorage mergedCells)
 {
     TrySpreadEnvironment(position, Direction.North, cell, mergedCells);
     TrySpreadEnvironment(position, Direction.South, cell, mergedCells);
     TrySpreadEnvironment(position, Direction.West, cell, mergedCells);
     TrySpreadEnvironment(position, Direction.East, cell, mergedCells);
 }
Esempio n. 4
0
        private void SpreadObject(ISpreadingObject liquid, IAreaMapCellInternal target)
        {
            var spreadAmount = Math.Min(liquid.MaxSpreadVolume, liquid.Volume - liquid.MaxVolumeBeforeSpread);
            var separated    = liquid.Separate(spreadAmount);

            target.ObjectsCollection.AddVolumeObject(separated);
        }
Esempio n. 5
0
 private void MergeCellEnvironment(Point position, IAreaMapCellInternal cell, CellPairsStorage mergedCells)
 {
     if (cell.BlocksEnvironment)
     {
         return;
     }
     SpreadEnvironment(position, cell, mergedCells);
 }
Esempio n. 6
0
        private void CheckSpreadingObjects(IAreaMapCellInternal other)
        {
            var localSpreadingObjects = ObjectsCollection.OfType <ISpreadingObject>().ToArray();
            var otherSpreadingObjects = other.ObjectsCollection.OfType <ISpreadingObject>().ToArray();

            foreach (var spreadingObject in localSpreadingObjects)
            {
                if (spreadingObject.Volume >= spreadingObject.MaxVolumeBeforeSpread)
                {
                    SpreadObject(spreadingObject, other);
                }
            }

            foreach (var otherSpreadingObject in otherSpreadingObjects)
            {
                if (otherSpreadingObject.Volume >= otherSpreadingObject.MaxVolumeBeforeSpread)
                {
                    SpreadObject(otherSpreadingObject, this);
                }
            }
        }
Esempio n. 7
0
 public void CheckSpreading(IAreaMapCellInternal other)
 {
     CheckSpreadingObjects(other);
 }