Skip to content
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
31 changes: 19 additions & 12 deletions 2048/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
<head>
<title>2048</title>
<link rel="stylesheet" type="text/css" href="stylesheet/style.css">
<link rel="stylesheet" type="text/css" href="stylesheet/reset.css">
</head>
<body>
<div class="screen">
<div id='title'>2048</div>
<button type='button' id='restartGame'>Restart</button>
<button type='button' id='undo'>Undo</button>
<div class ='score'>Score</div>
<div class='container default'>

</div>
<div id ="info">
<p><b>How to play:</b> Use your arrows to move left, right, up and down. When two tiles with the same number touch, they merge into one!</p>
<hr>
<p><b>Note: </b> The game is in developing phase. You may experience some problems, but we are going to update the game as sun as we can!</p>
</div>
</div>
<script type="text/javascript" src="scripts/jquery-1.11.1.js"></script>
<script type="text/javascript" src="scripts/main.js"></script>
<script type="text/javascript" src="scripts/variables.js"></script>
<script type="text/javascript" src="scripts/tiles.js"></script>
<script type="text/javascript" src="scripts/util.js"></script>
<script type="text/javascript" src="scripts/matrix.js"></script>
<script type="text/javascript" src="scripts/box.js"></script>

</head>


<body>
<div class="screen">
<div class="container"></div>


</div>
</body>


</html>
72 changes: 43 additions & 29 deletions 2048/scripts/box.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
// see matrix in browser
var Go = function(direction) {
move(matrix, direction);
};

$(document).ready(function(){
Go('startGame');
$(document).keydown(function(key){

startGame();
draw(gameMatrix.matrix);
var undoMatrix = clone(gameMatrix.matrix);
undoTag.html('Undo ('+x+')');
$('#restartGame').click(function(){
gameMatrix.matrix = restartGame();
startGame();
draw(gameMatrix.matrix);
x = 3;
totalScore = 0;
$('.score').html('Score' + '<p>'+totalScore+'</p>');
undoTag.html('Undo ('+x+')');
undoMatrix = new Array();
});
$('#undo').click(function(){
if(x>0){
gameMatrix.matrix = undo();
draw(gameMatrix.matrix);
x--;
undoTag.html('Undo ('+x+')');
}
});

switch(parseInt(key.which,10)) {
$(document).keydown(function(key){
switch(parseInt(key.which,10)) {
// left Arrow
case 37:
Go('left');
stopScroll();
undoMatrix = clone(gameMatrix.matrix);
moveLeft(gameMatrix.matrix);
break;
case 38:
Go('up');
stopScroll();
undoMatrix = clone(gameMatrix.matrix);
moveUp(gameMatrix.matrix);
break;
case 39:
Go('right');
break;
stopScroll();
undoMatrix = clone(gameMatrix.matrix);
moveRight(gameMatrix.matrix);
break;
case 40:
Go('down');
stopScroll();
undoMatrix = clone(gameMatrix.matrix);
moveDown(gameMatrix.matrix);
break;

case 27:
gameMatrix.matrix = restartGame();
startGame();
draw(gameMatrix.matrix);
}
gameOver(gameMatrix.matrix);

});
});


var ar=new Array(37,38,39,40);

// $(document).keydown(function(e) {
// var key = e.which;
// //console.log(key);
// //if(key==35 || key == 36 || key == 37 || key == 39)
// if($.inArray(key,ar) > -1) {
// e.preventDefault();
// return false;
// }
// return true;
// });
3 changes: 3 additions & 0 deletions 2048/scripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(document).ready(function(){

});
Loading