public Maze CreateMaze(int Row, int Col, object info) { maze = new CommonMaze(Row, Col); Random random = new Random(); int Sets = Row * Col; Cell CurrentCell; int row, col, NextId = 1; while (Sets > 1) { row = random.Next(0, maze.Rows); col = random.Next(0, maze.Columns); CurrentCell = maze[row, col]; if (CurrentCell.IsWalls()) { int WallId; Cell cell; do { WallId = random.Next(0, 4); cell = GetNextCell(new CellPoint(row, col), (Direction)WallId); if (CurrentCell.GetRelatedCell(WallId) == null && cell is Cell) { break; } } while (true); if (ConnectCells(CurrentCell, (Direction)WallId, cell)) { UniteAllID(CurrentCell, CurrentCell.GetRelatedCell(WallId), ref NextId); --Sets; } } else { continue; } } CreateCharacters(); return(maze); }