Example #1
0
  /**
   * Sets the seencells bit for all cells of a segment
   *
   * @param seg
   */
  private void udpateSeenCellsForSegment(Seg seg) {
    seg.seen = true; // updates the segment

    int sdx = seg.dx / map_unit; // constant, only set once here
    int sdy = seg.dy / map_unit; // constant, only set once here

    // get initial position right on loop variables sx, sy
    int sx = seg.x / map_unit;
    if (sdx < 0) sx--;
    int sy = seg.y / map_unit;
    if (sdy < 0) sy--;

    // define constants to avoid method calls in following loop
    int sdsx = MazeBuilder.getSign(sdx);
    int sdsy = MazeBuilder.getSign(sdy);
    int bit = (sdx != 0) ? Cells.CW_TOP : Cells.CW_LEFT;
    int len = Math.abs(sdx + sdy);
    // true loop variables are (sx,sy),
    for (int i = 0; i != len; i++) {
      // seencells[sx][sy] |= bit;
      seencells.setBitToOne(sx, sy, bit); // updates the cell
      sx += sdsx;
      sy += sdsy;
    }
  }
 /**
  * Method obtains a new Mazebuilder and has it compute new maze, it is only used in keyDown()
  *
  * @param skill level determines the width, height and number of rooms for the new maze
  */
 public void build(int skill) {
   percentdone = 0;
   // select generation method
   switch (method) {
     case 2:
       mazebuilder = new MazeBuilderEller(); // generate with Eller's algorithm.
       break;
     case 1:
       mazebuilder = new MazeBuilderPrim(); // generate with Prim's algorithm
       break;
     case 0: // generate with Falstad's original algorithm (0 and default), note the missing break
             // statement
     default:
       mazebuilder = new MazeBuilder();
       break;
   }
   // adjust settings and launch generation in a separate thread
   mazew = Constants.SKILL_X[skill];
   mazeh = Constants.SKILL_Y[skill];
   mazebuilder.build(
       this, mazew, mazeh, Constants.SKILL_ROOMS[skill], Constants.SKILL_PARTCT[skill]);
   // mazebuilder performs in a separate thread and calls back by calling newMaze() to return newly
   // generated maze
 }