Skip to content

Commit

Permalink
面が変わったらundoがリセットされるようにする #22
Browse files Browse the repository at this point in the history
  • Loading branch information
kagomen committed May 7, 2024
1 parent 96eca15 commit 68e5fce
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ function update(e) {

function undo() {
if (moveStack.length > 1) {
systemSound.play();

moveStack.pop();
playerPosXStack.pop();
playerPosYStack.pop();
Expand All @@ -128,7 +126,6 @@ function undo() {
}

function reset() {
systemSound.play();
moveStack = [];
playerPosXStack = [];
playerPosYStack = [];
Expand All @@ -155,18 +152,22 @@ document.getElementById('down-btn').addEventListener('click', () => {
// ====================== その他クリックイベント ======================

document.getElementById('undo-btn').addEventListener('click', () => {
systemSound.play();
undo();
});

window.addEventListener('keydown', (e) => {
if (e.code == 'Backspace') {
systemSound.play();
undo();
} else if (e.code == 'KeyR') {
systemSound.play();
reset();
}
});

document.getElementById('reset-btn').addEventListener('click', () => {
systemSound.play();
reset();
});

Expand All @@ -177,6 +178,7 @@ document.getElementById('next-stage-btn').addEventListener('click', () => {
currentStage++;
stageIndex.textContent = currentStage + 1;
init();
reset();
changeStageSound.play();
}
});
Expand All @@ -186,6 +188,7 @@ document.getElementById('prev-stage-btn').addEventListener('click', () => {
currentStage--;
stageIndex.textContent = currentStage + 1;
init();
reset();
changeStageSound.play();
}
});
Expand All @@ -199,6 +202,7 @@ document.getElementById('clear-next-stage-btn').addEventListener('click', () =>
currentStage++;
stageIndex.textContent = currentStage + 1;
init();
reset();
systemSound.play();
closeClearModal();
});
Expand All @@ -217,6 +221,7 @@ document.getElementById('page-title').addEventListener('click', () => {
currentStage = 0;
stageIndex.textContent = currentStage + 1;
init();
reset();
});

document.getElementById('sound-on-btn').addEventListener('click', () => {
Expand Down

0 comments on commit 68e5fce

Please sign in to comment.