/// <summary> /// Connects adjacent(north,east,south,west) cells to eachother(safe pointers) and edges are null /// </summary> public void LinkCells() { Cell current = new Cell(0, 0, ref bucket); start = current; for (int y = 0; y < height - 1; y++) { Cell firstInRow = current; for (int x = 0; x < width - 1; x++) { Cell south, east, southeast; if (y == 0) { east = new Cell(x + 1, y, ref bucket); } else { east = current.adjacentCell(Directions.East); } if (x == 0) { south = new Cell(x, y + 1, ref bucket); } else { south = current.adjacentCell(Directions.South); } southeast = new Cell(x + 1, y + 1, ref bucket); current.ConnectCell(Directions.South, south); current.ConnectCell(Directions.East, east); east.ConnectCell(Directions.West, current); east.ConnectCell(Directions.South, southeast); south.ConnectCell(Directions.East, southeast); south.ConnectCell(Directions.North, current); southeast.ConnectCell(Directions.North, east); southeast.ConnectCell(Directions.West, south); current = east; } current = firstInRow.adjacentCell(Directions.South); } }