Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. // Adds a tile in a random position
  2. GameManager.prototype.addRandomTile = function () {
  3. if (this.grid.cellsAvailable()) {
  4. var value = Math.random() < 0.9 ? 2 : 4;
  5. var tile = new Tile(this.grid.randomAvailableCell(), value);
  6.  
  7. this.grid.insertTile(tile);
  8. }
  9. };
  10.  
  11. // Find the first available random position
  12. Grid.prototype.randomAvailableCell = function () {
  13. var cells = this.availableCells();
  14.  
  15. if (cells.length) {
  16. return cells[Math.floor(Math.random() * cells.length)];
  17. }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement