/** * @class Icey's Maze generator * See http://www.roguebasin.roguelikedevelopment.org/index.php?title=Simple_maze for explanation * @augments ROT.Map */ ROT.Map.IceyMaze = function(width, height, regularity) { ROT.Map.call(this, width, height); this._regularity = regularity || 0; } ROT.Map.IceyMaze.extend(ROT.Map); ROT.Map.IceyMaze.prototype.create = function(callback) { var width = this._width; var height = this._height; var map = this._fillMap(1); width -= (width % 2 ? 1 : 2); height -= (height % 2 ? 1 : 2); var cx = 0; var cy = 0; var nx = 0; var ny = 0; var done = 0; var blocked = false; var dirs = [ [0, 0], [0, 0], [0, 0], [0, 0] ]; do { cx = 1 + 2*Math.floor(ROT.RNG.getUniform()*(width-1) / 2); cy = 1 + 2*Math.floor(ROT.RNG.getUniform()*(height-1) / 2); if (!done) { map[cx][cy] = 0; } if (!map[cx][cy]) { this._randomize(dirs); do { if (Math.floor(ROT.RNG.getUniform()*(this._regularity+1)) == 0) { this._randomize(dirs); } blocked = true; for (var i=0;i<4;i++) { nx = cx + dirs[i][0]*2; ny = cy + dirs[i][1]*2; if (this._isFree(map, nx, ny, width, height)) { map[nx][ny] = 0; map[cx + dirs[i][0]][cy + dirs[i][1]] = 0; cx = nx; cy = ny; blocked = false; done++; break; } } } while (!blocked); } } while (done+1 < width*height/4); for (var i=0;i= width || y >= height) { return false; } return map[x][y]; }