fix conflict
This commit is contained in:
+5
-1
@@ -20,7 +20,10 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
<h1 class="title">2048</h1>
|
<h1 class="title">2048</h1>
|
||||||
<div class="score-container">0</div>
|
<div class="scores-container">
|
||||||
|
<div class="score-container">0</div>
|
||||||
|
<div class="best-container">0</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="game-intro">Join the numbers and get to the <strong>2048 tile!</strong></p>
|
<p class="game-intro">Join the numbers and get to the <strong>2048 tile!</strong></p>
|
||||||
|
|
||||||
@@ -89,6 +92,7 @@
|
|||||||
<script src="js/html_actuator.js"></script>
|
<script src="js/html_actuator.js"></script>
|
||||||
<script src="js/grid.js"></script>
|
<script src="js/grid.js"></script>
|
||||||
<script src="js/tile.js"></script>
|
<script src="js/tile.js"></script>
|
||||||
|
<script src="js/local_score_manager.js"></script>
|
||||||
<script src="js/game_manager.js"></script>
|
<script src="js/game_manager.js"></script>
|
||||||
<script src="js/application.js"></script>
|
<script src="js/application.js"></script>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Wait till the browser is ready to render the game (avoids glitches)
|
// Wait till the browser is ready to render the game (avoids glitches)
|
||||||
window.requestAnimationFrame(function () {
|
window.requestAnimationFrame(function () {
|
||||||
var manager = new GameManager(4, KeyboardInputManager, HTMLActuator);
|
new GameManager(4, KeyboardInputManager, HTMLActuator, LocalScoreManager);
|
||||||
});
|
});
|
||||||
|
|||||||
+11
-6
@@ -1,6 +1,7 @@
|
|||||||
function GameManager(size, InputManager, Actuator) {
|
function GameManager(size, InputManager, Actuator, ScoreManager) {
|
||||||
this.size = size; // Size of the grid
|
this.size = size; // Size of the grid
|
||||||
this.inputManager = new InputManager;
|
this.inputManager = new InputManager;
|
||||||
|
this.scoreManager = new ScoreManager;
|
||||||
this.actuator = new Actuator;
|
this.actuator = new Actuator;
|
||||||
|
|
||||||
this.startTiles = 2;
|
this.startTiles = 2;
|
||||||
@@ -51,11 +52,17 @@ GameManager.prototype.addRandomTile = function () {
|
|||||||
|
|
||||||
// Sends the updated grid to the actuator
|
// Sends the updated grid to the actuator
|
||||||
GameManager.prototype.actuate = function () {
|
GameManager.prototype.actuate = function () {
|
||||||
|
if (this.scoreManager.get() < this.score) {
|
||||||
|
this.scoreManager.set(this.score);
|
||||||
|
}
|
||||||
|
|
||||||
this.actuator.actuate(this.grid, {
|
this.actuator.actuate(this.grid, {
|
||||||
score: this.score,
|
score: this.score,
|
||||||
over: this.over,
|
over: this.over,
|
||||||
won: this.won
|
won: this.won,
|
||||||
|
bestScore: this.scoreManager.get()
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save all tile positions and remove merger info
|
// Save all tile positions and remove merger info
|
||||||
@@ -204,8 +211,6 @@ GameManager.prototype.tileMatchesAvailable = function () {
|
|||||||
var cell = { x: x + vector.x, y: y + vector.y };
|
var cell = { x: x + vector.x, y: y + vector.y };
|
||||||
|
|
||||||
var other = self.grid.cellContent(cell);
|
var other = self.grid.cellContent(cell);
|
||||||
if (other) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (other && other.value === tile.value) {
|
if (other && other.value === tile.value) {
|
||||||
return true; // These two tiles can be merged
|
return true; // These two tiles can be merged
|
||||||
|
|||||||
+17
-7
@@ -1,8 +1,9 @@
|
|||||||
function HTMLActuator() {
|
function HTMLActuator() {
|
||||||
this.tileContainer = document.getElementsByClassName("tile-container")[0];
|
this.tileContainer = document.querySelector(".tile-container");
|
||||||
this.scoreContainer = document.getElementsByClassName("score-container")[0];
|
this.scoreContainer = document.querySelector(".score-container");
|
||||||
this.messageContainer = document.getElementsByClassName("game-message")[0];
|
this.bestContainer = document.querySelector(".best-container");
|
||||||
this.sharingContainer = document.getElementsByClassName("score-sharing")[0];
|
this.messageContainer = document.querySelector(".game-message");
|
||||||
|
this.sharingContainer = document.querySelector(".score-sharing");
|
||||||
|
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
}
|
}
|
||||||
@@ -22,6 +23,7 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.updateScore(metadata.score);
|
self.updateScore(metadata.score);
|
||||||
|
self.updateBestScore(metadata.bestScore);
|
||||||
|
|
||||||
if (metadata.over) self.message(false); // You lose
|
if (metadata.over) self.message(false); // You lose
|
||||||
if (metadata.won) self.message(true); // You win!
|
if (metadata.won) self.message(true); // You win!
|
||||||
@@ -29,7 +31,9 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
HTMLActuator.prototype.restart = function () {
|
HTMLActuator.prototype.restart = function () {
|
||||||
if (ga) ga("send", "event", "game", "restart");
|
if (typeof ga !== "undefined") {
|
||||||
|
ga("send", "event", "game", "restart");
|
||||||
|
}
|
||||||
this.clearMessage();
|
this.clearMessage();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,11 +109,17 @@ HTMLActuator.prototype.updateScore = function (score) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HTMLActuator.prototype.updateBestScore = function (bestScore) {
|
||||||
|
this.bestContainer.textContent = bestScore;
|
||||||
|
};
|
||||||
|
|
||||||
HTMLActuator.prototype.message = function (won) {
|
HTMLActuator.prototype.message = function (won) {
|
||||||
var type = won ? "game-won" : "game-over";
|
var type = won ? "game-won" : "game-over";
|
||||||
var message = won ? "You win!" : "Game over!"
|
var message = won ? "You win!" : "Game over!";
|
||||||
|
|
||||||
if (ga) ga("send", "event", "game", "end", type, this.score);
|
if (typeof ga !== "undefined") {
|
||||||
|
ga("send", "event", "game", "end", type, this.score);
|
||||||
|
}
|
||||||
|
|
||||||
this.messageContainer.classList.add(type);
|
this.messageContainer.classList.add(type);
|
||||||
this.messageContainer.getElementsByTagName("p")[0].textContent = message;
|
this.messageContainer.getElementsByTagName("p")[0].textContent = message;
|
||||||
|
|||||||
@@ -59,20 +59,22 @@ KeyboardInputManager.prototype.listen = function () {
|
|||||||
// Listen to swipe events
|
// Listen to swipe events
|
||||||
var touchStartClientX, touchStartClientY;
|
var touchStartClientX, touchStartClientY;
|
||||||
var gameContainer = document.getElementsByClassName("game-container")[0];
|
var gameContainer = document.getElementsByClassName("game-container")[0];
|
||||||
gameContainer.addEventListener("touchstart", function(event) {
|
|
||||||
|
gameContainer.addEventListener("touchstart", function (event) {
|
||||||
if (event.touches.length > 1) return;
|
if (event.touches.length > 1) return;
|
||||||
|
|
||||||
touchStartClientX = event.touches[0].clientX;
|
touchStartClientX = event.touches[0].clientX;
|
||||||
touchStartClientY = event.touches[0].clientY;
|
touchStartClientY = event.touches[0].clientY;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
gameContainer.addEventListener("touchmove", function(event) {
|
|
||||||
|
gameContainer.addEventListener("touchmove", function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
gameContainer.addEventListener("touchend", function(event) {
|
|
||||||
if (event.touches.length > 0) {
|
gameContainer.addEventListener("touchend", function (event) {
|
||||||
return;
|
if (event.touches.length > 0) return;
|
||||||
}
|
|
||||||
var dx = event.changedTouches[0].clientX - touchStartClientX;
|
var dx = event.changedTouches[0].clientX - touchStartClientX;
|
||||||
var absDx = Math.abs(dx);
|
var absDx = Math.abs(dx);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
window.fakeStorage = {
|
||||||
|
_data : {},
|
||||||
|
setItem : function (id, val) {
|
||||||
|
console.log("set");
|
||||||
|
return this._data[id] = String(val);
|
||||||
|
},
|
||||||
|
getItem : function (id) {
|
||||||
|
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
|
||||||
|
},
|
||||||
|
removeItem : function (id) { return delete this._data[id]; },
|
||||||
|
clear : function () { return this._data = {}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
function LocalScoreManager() {
|
||||||
|
var localSupported = !!window.localStorage;
|
||||||
|
|
||||||
|
this.key = "bestScore";
|
||||||
|
this.storage = localSupported ? window.localStorage : window.fakeStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalScoreManager.prototype.get = function () {
|
||||||
|
var score = this.storage.getItem(this.key);
|
||||||
|
if (typeof score === "undefined" || score === null) {
|
||||||
|
score = 0;
|
||||||
|
}
|
||||||
|
return score;
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalScoreManager.prototype.set = function (score) {
|
||||||
|
this.storage.setItem(this.key, score);
|
||||||
|
};
|
||||||
|
|
||||||
+22
-9
@@ -49,9 +49,13 @@ h1.title {
|
|||||||
top: -50px;
|
top: -50px;
|
||||||
opacity: 0; } }
|
opacity: 0; } }
|
||||||
|
|
||||||
.score-container {
|
.scores-container {
|
||||||
position: relative;
|
|
||||||
float: right;
|
float: right;
|
||||||
|
text-align: right; }
|
||||||
|
|
||||||
|
.score-container, .best-container {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
background: #bbada0;
|
background: #bbada0;
|
||||||
padding: 15px 25px;
|
padding: 15px 25px;
|
||||||
font-size: 25px;
|
font-size: 25px;
|
||||||
@@ -60,19 +64,19 @@ h1.title {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
color: white;
|
color: white;
|
||||||
margin-top: 8px; }
|
margin-top: 8px;
|
||||||
.score-container:after {
|
text-align: center; }
|
||||||
|
.score-container:after, .best-container:after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
left: 0;
|
left: 0;
|
||||||
content: "Score";
|
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
line-height: 13px;
|
line-height: 13px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #eee4da; }
|
color: #eee4da; }
|
||||||
.score-container .score-addition {
|
.score-container .score-addition, .best-container .score-addition {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 30px;
|
right: 30px;
|
||||||
color: red;
|
color: red;
|
||||||
@@ -86,6 +90,12 @@ h1.title {
|
|||||||
-webkit-animation-fill-mode: both;
|
-webkit-animation-fill-mode: both;
|
||||||
-moz-animation-fill-mode: both; }
|
-moz-animation-fill-mode: both; }
|
||||||
|
|
||||||
|
.score-container:after {
|
||||||
|
content: "Score"; }
|
||||||
|
|
||||||
|
.best-container:after {
|
||||||
|
content: "Best"; }
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
@@ -462,14 +472,17 @@ hr {
|
|||||||
padding: 0 20px; }
|
padding: 0 20px; }
|
||||||
|
|
||||||
h1.title {
|
h1.title {
|
||||||
font-size: 50px; }
|
font-size: 27px;
|
||||||
|
margin-top: 15px; }
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 280px;
|
width: 280px;
|
||||||
margin: 0 auto; }
|
margin: 0 auto; }
|
||||||
|
|
||||||
.score-container {
|
.score-container, .best-container {
|
||||||
margin-top: 0; }
|
margin-top: 0;
|
||||||
|
padding: 15px 10px;
|
||||||
|
min-width: 40px; }
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
margin-bottom: 10px; }
|
margin-bottom: 10px; }
|
||||||
|
|||||||
+26
-5
@@ -58,11 +58,16 @@ h1.title {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.score-container {
|
.scores-container {
|
||||||
|
float: right;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.score-container, .best-container {
|
||||||
$height: 25px;
|
$height: 25px;
|
||||||
|
|
||||||
position: relative;
|
position: relative;
|
||||||
float: right;
|
display: inline-block;
|
||||||
background: $game-container-background;
|
background: $game-container-background;
|
||||||
padding: 15px 25px;
|
padding: 15px 25px;
|
||||||
font-size: $height;
|
font-size: $height;
|
||||||
@@ -72,13 +77,13 @@ h1.title {
|
|||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
color: white;
|
color: white;
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
&:after {
|
&:after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
left: 0;
|
left: 0;
|
||||||
content: "Score";
|
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
line-height: 13px;
|
line-height: 13px;
|
||||||
@@ -100,6 +105,14 @@ h1.title {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.score-container:after {
|
||||||
|
content: "Score";
|
||||||
|
}
|
||||||
|
|
||||||
|
.best-container:after {
|
||||||
|
content: "Best"
|
||||||
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
@@ -449,7 +462,8 @@ hr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h1.title {
|
h1.title {
|
||||||
font-size: 50px;
|
font-size: 27px;
|
||||||
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
@@ -457,8 +471,15 @@ hr {
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.score-container {
|
// .scores-container {
|
||||||
|
// float: left;
|
||||||
|
// clear: left;
|
||||||
|
// }
|
||||||
|
|
||||||
|
.score-container, .best-container {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
padding: 15px 10px;
|
||||||
|
min-width: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.heading {
|
.heading {
|
||||||
|
|||||||
Reference in New Issue
Block a user