public override void Generate() { int j=0; Random rand = new Random(); while (j < height - 1) { for (int i = 0; i < width; i++) { if ((maze[i][j] as MazeCellEller).Set == -1) (maze[i][j] as MazeCellEller).Set = _set++; } Dictionary<int, int> uniqueInt = new Dictionary<int, int>(); for (int k = 0; k < width; k++) uniqueInt[(maze[k][j] as MazeCellEller).Set] = 1; int toBeJoined = rand.Next(1, uniqueInt.Count); for (int i = 0; i < toBeJoined; i++) { int nextJoin = rand.Next(0, width - 1); while (maze[nextJoin][j].East != null && (maze[nextJoin][j] as MazeCellEller).Set == (maze[nextJoin + 1][j] as MazeCellEller).Set) nextJoin = rand.Next(0, width - 1); maze[nextJoin][j].East = maze[nextJoin + 1][j]; maze[nextJoin + 1][j].West = maze[nextJoin][j]; } for (int i = 0; i < width - 1; i++) { if (maze[i][j].East != null) { (maze[i][j].East as MazeCellEller).Set = (maze[i][j] as MazeCellEller).Set; } } int ii = 0; while (ii < width) { MazeCellEller current = maze[ii][j] as MazeCellEller; setStruct sStruct = new setStruct(); sStruct.setNum = current.Set; sStruct.startPos = current.X; MazeCellEller next = current.East as MazeCellEller; MazeCellEller last = current; while (next != null) { last = next; next = next.East as MazeCellEller; } sStruct.endPos = last.X; setList.Add(sStruct); ii = last.X + 1; } for (int i = 0; i < setList.Count; i++) { int timesOpen = rand.Next(1, setList[i].endPos - setList[i].startPos + 1); for (int jj = 0; jj < timesOpen; jj++) { int southPos = rand.Next(setList[i].startPos, setList[i].endPos); while (maze[southPos][j].South != null) southPos = rand.Next(setList[i].startPos, setList[i].endPos); maze[southPos][j].South = maze[southPos][j + 1]; maze[southPos][j + 1].North = maze[southPos][j]; (maze[southPos][j + 1] as MazeCellEller).Set = (maze[southPos][j] as MazeCellEller).Set; } } setList.Clear(); j++; } for (int i = 0; i < width; i++) { if ((maze[i][j] as MazeCellEller).Set == -1) (maze[i][j] as MazeCellEller).Set = _set++; } for (int i = 0; i < width - 1; i++) { if ((maze[i][j] as MazeCellEller).Set != (maze[i + 1][j] as MazeCellEller).Set) { maze[i][j].East = maze[i + 1][j]; maze[i + 1][j].West = maze[i][j]; } } }
public override void Generate() { int j = 0; Random rand = new Random(); while (j < height - 1) { for (int i = 0; i < width; i++) { if ((maze[i][j] as MazeCellEller).Set == -1) { (maze[i][j] as MazeCellEller).Set = _set++; } } Dictionary <int, int> uniqueInt = new Dictionary <int, int>(); for (int k = 0; k < width; k++) { uniqueInt[(maze[k][j] as MazeCellEller).Set] = 1; } int toBeJoined = rand.Next(1, uniqueInt.Count); for (int i = 0; i < toBeJoined; i++) { int nextJoin = rand.Next(0, width - 1); while (maze[nextJoin][j].East != null && (maze[nextJoin][j] as MazeCellEller).Set == (maze[nextJoin + 1][j] as MazeCellEller).Set) { nextJoin = rand.Next(0, width - 1); } maze[nextJoin][j].East = maze[nextJoin + 1][j]; maze[nextJoin + 1][j].West = maze[nextJoin][j]; } for (int i = 0; i < width - 1; i++) { if (maze[i][j].East != null) { (maze[i][j].East as MazeCellEller).Set = (maze[i][j] as MazeCellEller).Set; } } int ii = 0; while (ii < width) { MazeCellEller current = maze[ii][j] as MazeCellEller; setStruct sStruct = new setStruct(); sStruct.setNum = current.Set; sStruct.startPos = current.X; MazeCellEller next = current.East as MazeCellEller; MazeCellEller last = current; while (next != null) { last = next; next = next.East as MazeCellEller; } sStruct.endPos = last.X; setList.Add(sStruct); ii = last.X + 1; } for (int i = 0; i < setList.Count; i++) { int timesOpen = rand.Next(1, setList[i].endPos - setList[i].startPos + 1); for (int jj = 0; jj < timesOpen; jj++) { int southPos = rand.Next(setList[i].startPos, setList[i].endPos); while (maze[southPos][j].South != null) { southPos = rand.Next(setList[i].startPos, setList[i].endPos); } maze[southPos][j].South = maze[southPos][j + 1]; maze[southPos][j + 1].North = maze[southPos][j]; (maze[southPos][j + 1] as MazeCellEller).Set = (maze[southPos][j] as MazeCellEller).Set; } } setList.Clear(); j++; } for (int i = 0; i < width; i++) { if ((maze[i][j] as MazeCellEller).Set == -1) { (maze[i][j] as MazeCellEller).Set = _set++; } } for (int i = 0; i < width - 1; i++) { if ((maze[i][j] as MazeCellEller).Set != (maze[i + 1][j] as MazeCellEller).Set) { maze[i][j].East = maze[i + 1][j]; maze[i + 1][j].West = maze[i][j]; } } }