Exemplo n.º 1
0
 public void Init(int maxNum, CellCallback callback)
 {
     sContent     = mainContainer.content;
     this.maxNum  = maxNum;
     cellCallback = callback;
     SetViewNum(true);
     SetCells();
 }
Exemplo n.º 2
0
 public static void EnumerateNeigbours(Cell cell, CellCallback callback)
 {
     for (var k = 0; k < 4; k++)
     {
         var ni = cell.I + _dx[k];
         var nj = cell.J + _dy[k];
         if (ni >= 0 && nj >= 0 && ni < world.Height && nj < world.Width)
         {
             callback(new Cell(ni, nj));
         }
     }
 }
Exemplo n.º 3
0
 public void ForeachCell(CellCallback action)
 {
     for (int y = 0; y < cellsPerYAxis; ++y)
     {
         for (int z = 0; z < cellsPerZAxis; ++z)
         {
             for (int x = 0; x < cellsPerXAxis; ++x)
             {
                 action(x, y, z, cells[x, y, z]);
             }
         }
     }
 }
Exemplo n.º 4
0
        public void ProcessCellFill(int x, int y, int z, CellCallback action, CellPredicate predicate)
        {
            if (!IsValidCell(x, y, z))
            {
                return;
            }

            bool[,,] closed = new bool[CellsPerXAxis, CellsPerYAxis, CellsPerZAxis];

            var baseCell = GetCastInfo(x, y, z);
            var open     = new Queue <CellCastInfo>();

            open.Enqueue(baseCell);
            closed[x, y, z] = true;

            CellCastInfo cell = baseCell;

            if (!predicate(cell.X, cell.Y, cell.Z, cell.Cell))
            {
                return;
            }

            action(cell.X, cell.Y, cell.Z, cell.Cell);

            while (open.Count > 0)
            {
                CellCastInfo next = open.Dequeue();

                int  west, east;
                bool match;

                // Find west
                x     = next.X;
                y     = next.Y;
                z     = next.Z;
                match = true;

                while (match)
                {
                    ++x;
                    if (IsValidCell(x, y, z))
                    {
                        cell  = GetCastInfo(x, y, z);
                        match = predicate(cell.X, cell.Y, cell.Z, cell.Cell);
                    }
                    else
                    {
                        match = false;
                    }
                }
                west = x;
                //

                // Find east
                x     = next.X;
                y     = next.Y;
                z     = next.Z;
                match = true;

                while (match)
                {
                    --x;
                    if (IsValidCell(x, y, z))
                    {
                        cell  = GetCastInfo(x, y, z);
                        match = predicate(cell.X, cell.Y, cell.Z, cell.Cell);
                    }
                    else
                    {
                        match = false;
                    }
                }
                east = x;
                //

                for (x = east + 1; x < west; ++x)
                {
                    if (closed[x, y, z])
                    {
                        continue;
                    }

                    cell  = GetCastInfo(x, y, z);
                    match = predicate(cell.X, cell.Y, cell.Z, cell.Cell);

                    closed[x, y, z] = true;

                    if (IsValidCell(x, y - 1, z))
                    {
                        cell = GetCastInfo(x, y - 1, z);
                        if (predicate(cell.X, cell.Y, cell.Z, cell.Cell))
                        {
                            open.Enqueue(cell);
                        }
                    }
                    if (IsValidCell(x, y + 1, z))
                    {
                        cell = GetCastInfo(x, y + 1, z);
                        if (predicate(cell.X, cell.Y, cell.Z, cell.Cell))
                        {
                            open.Enqueue(cell);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 public static void EnumerateNeigbours(Cell cell, CellCallback callback)
 {
     for (var k = 0; k < 4; k++)
     {
         var ni = cell.I + _dx[k];
         var nj = cell.J + _dy[k];
         if (ni >= 0 && nj >= 0 && ni < world.Height && nj < world.Width)
             callback(new Cell(ni, nj));
     }
 }