Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only one merger per traversal #4

Open
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions cache.appcache
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Updated: 2014-08-10T02:22:05+02:00
CACHE MANIFEST

# Adds the ability to play the game online.
# The following comment needs to be updated whenever a change is made.
# Run `rake appcache:update` to do so
# Updated: 2014-08-10T02:20:58+02:00

# Main page
index.html

# CSS
style/main.css

# Fonts
style/fonts/clear-sans.css
style/fonts/ClearSans-Bold-webfont.eot
style/fonts/ClearSans-Bold-webfont.svg
style/fonts/ClearSans-Bold-webfont.woff
style/fonts/ClearSans-Light-webfont.eot
style/fonts/ClearSans-Light-webfont.svg
style/fonts/ClearSans-Light-webfont.woff
style/fonts/ClearSans-Regular-webfont.eot
style/fonts/ClearSans-Regular-webfont.svg
style/fonts/ClearSans-Regular-webfont.woff

# Other resources
meta/apple-touch-icon.png
meta/icon_bitcoin.svg
meta/icon_pp.svg
meta/og_image.png

# JavaScript
js/animframe_polyfill.js
js/application.js
js/game_manager.js
js/grid.js
js/html_actuator.js
js/keyboard_input_manager.js
js/local_score_manager.js
js/tile.js

favicon.ico

NETWORK:
*
Binary file modified favicon.ico
Binary file not shown.
40 changes: 17 additions & 23 deletions js/game_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,51 +121,45 @@ GameManager.prototype.move = function (direction) {
cell = { x: x, y: y };
tile = self.grid.cellContent(cell);

if(tile && tile.merged) {
self.grid.removeTile(tile);
}
else if (tile) {
if (tile && tile.merged) {
self.grid.removeTile(tile);
} else if (tile) {
var positions = self.findFarthestPosition(cell, vector);
var next = self.grid.cellContent(positions.next);
var pos2 = null;
var next2 = null;
if(next)
{
pos2 = self.findFarthestPosition({x: next.x, y: next.y}, vector);
next2 = self.grid.cellContent(pos2.next);
if (next) {
pos2 = self.findFarthestPosition({x: next.x, y: next.y}, vector);
next2 = self.grid.cellContent(pos2.next);
}
// Only one merger per row traversal?
if (next && next.value === tile.value && next2 && next2.value === tile.value && !next.mergedFrom && next != next2) {
if (next && next.value === tile.value && next2 && next2.value === tile.value && !next.mergedFrom && !next2.mergedFrom && next != next2) {
var merged = new Tile(pos2.next, tile.value * 3);
merged.mergedFrom = [next2, next, tile];
tile.merged = true;
next.merged = true;
next2.merged = true;
tile.merged = true;
next.merged = true;
next2.merged = true;

self.grid.removeTile(tile);
self.grid.removeTile(next);
self.grid.removeTile(next2);
self.grid.removeTile(next);
self.grid.removeTile(next2);

self.grid.insertTile(merged);
self.grid.insertTile(merged);
// Converge the two tiles' positions
tile.updatePosition(pos2.next);
next.updatePosition(pos2.next);
next.updatePosition(pos2.next);
// Update the score
self.score += merged.value;

// The mighty 2048 tile
if (merged.value === 243) self.won = true;
}

else if (!tile.merged){
} else if (!tile.merged){
self.moveTile(tile, positions.farthest);
}

if (tile && !self.positionsEqual(cell, tile)) {
moved = true; // The tile moved from its original cell!
}
}

}
});
});

Expand Down
Binary file modified meta/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.