Пример #1
0
  @Override
  public Maze generateMaze(int rows, int cols) {
    this.cols = cols;
    this.rows = rows;

    Cell[][] cells = new Cell[rows][cols];

    for (int j = 0; j < cols; j++) {
      for (int i = 0; i < rows; i++) {
        Cell nc = new Cell(i, j);
        if (j == 0) {
          nc.right = false;
          nc.left = false;
          nc.up = true;
        } else {
          nc.up = true;
          nc.down = true;
          nc.right = true;
          if (getRandomBoolean() || i == 0) {
            nc.up = false;
            nc.left = true;
            cells[i][j - 1].down = false;
          } else {
            nc.left = false;
            cells[i - 1][j].right = false;
          }
        }

        if (j == rows - 1) {
          nc.down = true;
        }

        if (i == cols - 1) {
          nc.right = true;
        }

        cells[i][j] = nc;
      }
    }

    Maze maze = new Maze(rows, cols);
    for (int x = 0; x < rows; x++) {
      for (int y = 0; y < cols; y++) {
        maze.data[x][y] = cells[x][y].getValue();
      }
    }

    return maze;
  }