Beispiel #1
0
        internal void GenerateGroups(MapLayerBuilder layer)
        {
            int nextGroup = 0;

            for (int y = 0; y < layer.Height; y++)
            {
                for (int x = 0; x < layer.Width; x++)
                {
                    var value = layer.GetValue(x, y);

                    //Ignore "Air" and "Obstracle" cells
                    if (value == 0 || value == 63)
                    {
                        continue;
                    }

                    var currentGroup = GetValue(x, y);

                    //Check if group already set (processed)
                    if (currentGroup == MapLayerModel.UNSET_CELL)
                    {
                        Flood(layer, x, y, value, nextGroup);
                        nextGroup++;
                    }
                }
            }
        }
Beispiel #2
0
 internal MapLayerModel(MapLayerBuilder builder)
 {
     cellValues = builder.CellValues.ToArray();
     LayerType  = builder.LayerType;
     Width      = builder.Width;
     Height     = builder.Height;
     IsVisible  = builder.IsVisible;
 }
Beispiel #3
0
        public MapLayerBuilder AddLayer(MapLayerType layerType)
        {
            if (Width == 0 || Height == 0)
            {
                throw new InvalidOperationException("Width and Height must have non zero positive values");
            }

            var layerBuilder = new MapLayerBuilder(Width, Height, layerType);

            Layers.Add(layerBuilder);
            return(layerBuilder);
        }
Beispiel #4
0
 private void Flood(MapLayerBuilder layer, int x, int y, int valueToFind, int groupId)
 {
     //Check if group already set (processed)
     if (GetValue(x, y) == MapLayerModel.UNSET_CELL && layer.GetValue(x, y) == valueToFind)
     {
         SetValue(x, y, groupId);
         if (x + 1 < Width)
         {
             Flood(layer, x + 1, y, valueToFind, groupId);
         }
         if (y + 1 < Height)
         {
             Flood(layer, x, y + 1, valueToFind, groupId);
         }
         if (x - 1 >= 0)
         {
             Flood(layer, x - 1, y, valueToFind, groupId);
         }
         if (y - 1 >= 0)
         {
             Flood(layer, x, y - 1, valueToFind, groupId);
         }
     }
 }