- * Initially, every cell has four normal walls, W, S, E, and N. - *

- * Some of these may be changed to borders depending on the position of the - * cell on the board. - *

- * If the cell is the leftmost cell in a row, it has a 'W' border. - * If the cell is the topmost cell in a column, it has a 'N' border. - * etc. - */ - private int wall; - private int border; - - final private int N = 1; - final private int E = 2; - final private int S = 4; - final private int W = 8; - - public Cell(int x, int y, int width, int height) { - border = 0; - - /** - * |= is used to set up a flag. - * e.g. 0000 | 1010 = 1010 - */ - if (0 == x) { - border |= W; - } else if (width - 1 == x) { - border |= E; - } - - if (0 == y) { - border |= N; - } else if (height - 1 == y) { - border |= S; - } - - /** - * e.g. If the border is 1001, the wall should be: - * 1111(15) - 1001 = 0110 - */ - wall = 15 - border; - } + /** + * x and y are the relative coordinates of the cell on the board whose central cell has the + * coordinate of (0, 0). + */ + private float x, y; + private float sideLength; + + private boolean visited; + private int direction; + + /** + * There are two types of walls: normal walls and borders. Normal walls are those that can be + * pushed down. Borders are the border of the board, which cannot be pushed down.

+ * Initially, every cell has four normal walls, W, S, E, and N.

Some of these may be + * changed to borders depending on the position of the cell on the board.

- * Randomly picks an adjacent cell and moves to it. - *

- * It will move if: - * 1. The move will not be out-of-range. - * 2. the cell to which it moves has not been visited. - * - * @param cx x-coordinate of the cell from where the program starts to - * visit its adjacent cells. - * @param cy y-coordinate of the cell from where the program starts to - * visit its adjacent cells. - */ - public void visitFrom(int cx, int cy) { - Collections.shuffle(directions); - for (Integer direction : directions) { - int nx = cx + dX(direction); - int ny = cy + dY(direction); - if ((nx >= 0) && - (nx <= width - 1) && - (ny >= 0) && - (ny <= height - 1) && - (grid[ny][nx].isNotVisited())) { - grid[cy][cx].visit(direction); - grid[ny][nx].visit(opposite(direction)); - visitFrom(nx, ny); - } - } + } + + /** + * Generates a random maze.

Randomly picks an adjacent cell and moves to it.