Skip to content

Commit

Permalink
elite version
Browse files Browse the repository at this point in the history
Signed-off-by: farteryhr <[email protected]>
  • Loading branch information
farteryhr committed May 1, 2022
1 parent fc1ef4f commit 629260b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<body>
<div class="container">
<div class="heading">
<h1 class="title">2048</h1>
<h1 class="title">2048 Elite</h1>
<div class="scores-container">
<div class="score-container">0</div>
<div class="best-container">0</div>
Expand Down Expand Up @@ -77,11 +77,11 @@ <h1 class="title">2048</h1>
</p>
<hr>
<p>
<strong class="important">Note:</strong> This site is the official version of 2048. You can play it on your phone via <a href="http://git.io/2048">http://git.io/2048.</a> All other apps or sites are derivatives or fakes, and should be used with caution.
<strong class="important">Note:</strong> This site is the official version of 2048 Elite. It's different from the original 2048 only by a small tweak on the mechanics to determine what tile to spawn.
</p>
<hr>
<p>
Created by <a href="http://gabrielecirulli.com" target="_blank">Gabriele Cirulli.</a> Based on <a href="https://itunes.apple.com/us/app/1024!/id823499224" target="_blank">1024 by Veewo Studio</a> and conceptually similar to <a href="http://asherv.com/threes/" target="_blank">Threes by Asher Vollmer.</a>
Modded by <a href="http://farter.cn">farter</a>, Created by <a href="http://gabrielecirulli.com" target="_blank">Gabriele Cirulli</a>, Based on <a href="https://itunes.apple.com/us/app/1024!/id823499224" target="_blank">1024 by Veewo Studio</a> and conceptually similar to <a href="http://asherv.com/threes/" target="_blank">Threes by Asher Vollmer.</a>
</p>
</div>

Expand Down
20 changes: 19 additions & 1 deletion js/game_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ GameManager.prototype.addRandomTile = function () {
}
};

// Adds a tile in a random position according to current tiles
GameManager.prototype.addRandomTileElite = function () {
if (this.grid.cellsAvailable()) {
var tiles = [];
this.grid.eachCell(function (x, y, tile) {
if (tile) {
tiles.push(tile);
}
});
if (tiles.length) {
var value = tiles[~~(Math.random() * tiles.length)].value;
var tile = new Tile(this.grid.randomAvailableCell(), value);

this.grid.insertTile(tile);
}
}
};

// Sends the updated grid to the actuator
GameManager.prototype.actuate = function () {
if (this.storageManager.getBestScore() < this.score) {
Expand Down Expand Up @@ -180,7 +198,7 @@ GameManager.prototype.move = function (direction) {
});

if (moved) {
this.addRandomTile();
this.addRandomTileElite();

if (!this.movesAvailable()) {
this.over = true; // Game over!
Expand Down

0 comments on commit 629260b

Please sign in to comment.