Skip to content

Commit

Permalink
fixed??? (i cannot type)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongbin99 committed Jan 23, 2024
1 parent 3256af3 commit 509e529
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions 2048.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,20 @@ function updateTile(tile, number) {
document.addEventListener("keydown", (a) => {
if ((a.code == "ArrowLeft") || (a.code == "KeyA")) {
moveLeft();
spawnTwo();
}
else if ((a.code == "ArrowRight") || (a.code == "KeyD")) {
moveRight();
spawnTwo();
}
else if ((a.code == "ArrowUp") || (a.code == "KeyW")) {
moveUp();
spawnTwo();
}
else if ((a.code == "ArrowDown") || (a.code == "KeyS")) {
moveDown();
spawnTwo();
}
spawnTwo();
updateScore();
});

Expand Down Expand Up @@ -258,8 +261,8 @@ replayButton.addEventListener("click", () => {
//touch event variables
var touchStartX, touchStartY;
//touch listeners
document.getElementById("gane").addEventListener("touchstart", handleTouchStart, false);
document.getElementById("gane").addEventListener("touchmove", handleTouchMove, false);
document.getElementById("game").addEventListener("touchstart", handleTouchStart, false);
document.getElementById("game").addEventListener("touchmove", handleTouchMove, false);

function handleTouchStart(event) {//setting initial touch position
touchStartX = event.touches[0].clientX;
Expand All @@ -280,24 +283,27 @@ function handleTouchMove(event) {
if (Math.abs(dX) > Math.abs(dY)) {//X movement > than Y
if (dX > 0) {
moveRight(); //swipe right
spawnTwo();
}
else {
moveLeft(); //swipe left
spawnTwo();
}
}
else if (Math.abs(dX) < Math.abs(dY)) {//otherwise, must be Y movement
if (dY > 0) {
moveDown(); //swipe down
spawnTwo();
}
else {
moveUp(); //swipe up
spawnTwo();
}
}
//update starting touch positions to reset
touchStartX = touchEndX;
touchStartY = touchEndY;

spawnTwo();
updateScore();
}
}

0 comments on commit 509e529

Please sign in to comment.