Example #1
0
 DungeonCell[,] InitialiseMap(int width, int height)
 {
     DungeonCell[,] dungeon = new DungeonCell[width, height];
     for (int i = 0; i < dungeon.GetLength(0); i++)
     {
         for (int j = 0; j < dungeon.GetLength(1); j++)
         {
             float randomValue = rnd.Next(0, 100);
             dungeon[i, j] = new DungeonCell(randomValue < chanceToStartAlive ? DungeonCellType.PATH : DungeonCellType.WALL);
         }
     }
     return(dungeon);
 }
Example #2
0
 public DungeonCell[,] SimulationStep(DungeonCell[,] oldDungeon)
 {
     DungeonCell[,] newDungeon = new DungeonCell[oldDungeon.GetLength(0), oldDungeon.GetLength(1)];
     for (int i = 0; i < oldDungeon.GetLength(0); i++)
     {
         for (int j = 0; j < oldDungeon.GetLength(1); j++)
         {
             int neightboursCount = CountAliveNeightbours(oldDungeon, i, j);
             if (oldDungeon[i, j].cellType == DungeonCellType.PATH)
             {
                 newDungeon[i, j] = new DungeonCell(neightboursCount >= overpopLimit && neightboursCount <= starvationLimit ? DungeonCellType.PATH : DungeonCellType.WALL);
             }
             else if (oldDungeon[i, j].cellType == DungeonCellType.WALL)
             {
                 newDungeon[i, j] = new DungeonCell(neightboursCount <= birthLimit ? DungeonCellType.PATH : DungeonCellType.WALL);
             }
         }
     }
     dungeonGrid = newDungeon;
     return(newDungeon);
 }