public void BuildMaze <T>(int x_size, int y_size) where T : IMazeCell { this.size_x = x_size; this.size_y = y_size; cells.Capacity = size_x * size_y; int group_id = 0; //FIRST PASS for (int iy = 0; iy < size_y; iy++) { for (int ix = 0; ix < size_x; ix++) { if (maze_mask_cells != null && maze_mask_cells.Contains(SharedUtil.PointHash(ix, iy))) { cells.Add(null); } else { T cell = System.Activator.CreateInstance <T>(); cell.X = ix; cell.Y = iy; cell.GroupID = group_id++; cells.Add(cell); } } } //SECOND PASS for (int iy = 0; iy < size_y; iy++) { for (int ix = 0; ix < size_x; ix++) { IMazeCell cell = GetAt(ix, iy); if (cell != null) { IMazeCell[] neighbours = new IMazeCell[4]; neighbours[(int)EMazeDirection.North] = GetAt(ix, iy + 1); neighbours[(int)EMazeDirection.South] = GetAt(ix, iy - 1); neighbours[(int)EMazeDirection.West] = GetAt(ix - 1, iy); neighbours[(int)EMazeDirection.East] = GetAt(ix + 1, iy); cell.SetNeighbours(neighbours); } } } Generate(); for (int i = 0; i < post_processer.Count; i++) { if (post_processer[i] != null) { post_processer[i].PostProcess(this); } } }