diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ccc9fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.DS_Store \ No newline at end of file diff --git a/static/audio/error.ogg b/static/audio/error.ogg new file mode 100644 index 0000000..8ed96e4 Binary files /dev/null and b/static/audio/error.ogg differ diff --git a/static/audio/fail_streak.ogg b/static/audio/fail_streak.ogg new file mode 100644 index 0000000..f7e4137 Binary files /dev/null and b/static/audio/fail_streak.ogg differ diff --git a/static/audio/off_board.ogg b/static/audio/off_board.ogg new file mode 100644 index 0000000..12697e5 Binary files /dev/null and b/static/audio/off_board.ogg differ diff --git a/static/audio/place.ogg b/static/audio/place.ogg new file mode 100644 index 0000000..562ddb3 Binary files /dev/null and b/static/audio/place.ogg differ diff --git a/static/audio/take_piece.ogg b/static/audio/take_piece.ogg new file mode 100644 index 0000000..78f119c Binary files /dev/null and b/static/audio/take_piece.ogg differ diff --git a/static/audio/win.ogg b/static/audio/win.ogg new file mode 100644 index 0000000..4e01396 Binary files /dev/null and b/static/audio/win.ogg differ diff --git a/static/js/script.js b/static/js/script.js index 95d54ab..5a84a40 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -1,6 +1,13 @@ document.addEventListener('DOMContentLoaded', () => { // Constants for adjusting game const MAX_SNAP_DISTANCE = 90; + const placeSound = new Audio("static/audio/place.ogg"); + const errorSound = new Audio("static/audio/error.ogg"); + const offBoardSound = new Audio("static/audio/off_board.ogg"); + const takePieceSound = new Audio("static/audio/take_piece.ogg"); + const winSound = new Audio("static/audio/wind.ogg"); + const failStreakSound = new Audio("static/audio/fail_streak.ogg"); + // Track game state let tokensRemaining = 5; @@ -131,12 +138,16 @@ document.addEventListener('DOMContentLoaded', () => { function captureCell(cell) { const existingToken = cell.querySelector('.token') if (existingToken && existingToken.dataset.captured == 'false') { + takePieceSound.currentTime = 0; // rewind so it can play repeatedly + takePieceSound.play(); existingToken.dataset.captured = 'true'; existingToken.style.display = 'none'; tokensRemaining--; inStreak = true; } else { if (inStreak) { + failStreakSound.currentTime = 0; // rewind so it can play repeatedly + failStreakSound.play(); return false } } @@ -151,11 +162,15 @@ document.addEventListener('DOMContentLoaded', () => { const {cell: closestCell, distance} = getClosestCellByDistance(e.pageX, e.pageY); if (distance > MAX_SNAP_DISTANCE) { + offBoardSound.currentTime = 0; // rewind so it can play repeatedly + offBoardSound.play(); resetToken(player_token.parentElement); return; } if (!checkMoveValid(player_token.parentElement, closestCell)) { + errorSound.currentTime = 0; // rewind so it can play repeatedly + errorSound.play(); resetBoard() return; } @@ -172,9 +187,15 @@ document.addEventListener('DOMContentLoaded', () => { player_token.style.zIndex = ''; closestCell.appendChild(player_token); + placeSound.currentTime = 0; // rewind so it can play repeatedly + placeSound.play(); + + if (tokensRemaining == 0) { alert("You win!") + winSound.currentTime = 0; // rewind so it can play repeatedly + winSound.play(); } });