这个问题是关于热门游戏2048。我想知道每个转弯处新瓷砖外观的细节:
答案 0 :(得分:2)
https://github.com/gabrielecirulli/2048/blob/master/js/game_manager.js#L72
// Adds a tile in a random position
GameManager.prototype.addRandomTile = function () {
if (this.grid.cellsAvailable()) {
var value = Math.random() < 0.9 ? 2 : 4;
var tile = new Tile(this.grid.randomAvailableCell(), value);
this.grid.insertTile(tile);
}
};
https://github.com/gabrielecirulli/2048/blob/master/js/grid.js#L36
// Find the first available random position
Grid.prototype.randomAvailableCell = function () {
var cells = this.availableCells();
if (cells.length) {
return cells[Math.floor(Math.random() * cells.length)];
}
};