Пример #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++;
                    }
                }
            }
        }
Пример #2
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);
         }
     }
 }