jsrogue icon indicating copy to clipboard operation
jsrogue copied to clipboard

Bug in `getRandomFloorPosition` for part 4.

Open remcopeereboom opened this issue 10 years ago • 0 comments

Game.Map.prototype.getRandomFloorPosition = function() {
    // Randomly generate a tile which is a floor
    var x, y;
    do {
        x = Math.floor(Math.random() * this._width);
        y = Math.floor(Math.random() * this._width);
    } while(this.getTile(x, y) != Game.Tile.floorTile);
    return {x: x, y: y};
}

You should set the y-coordinate to a random times the map height, not its width.

This may not be the best algorithm for maps with a low ratio of floors, you might want to add a counter to just set a random tile as floor tile if after x tries you still haven't found a spot.

remcopeereboom avatar Aug 14 '15 11:08 remcopeereboom