Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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);
- }
- };
- // 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)];
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement