add sounds and a gitignore for temp sound files.

This commit is contained in:
taylor berukoff 2025-11-14 09:35:50 -10:00
parent 07a8bdca8d
commit e1cdd4ea1f
8 changed files with 22 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.DS_Store

BIN
static/audio/error.ogg Normal file

Binary file not shown.

Binary file not shown.

BIN
static/audio/off_board.ogg Normal file

Binary file not shown.

BIN
static/audio/place.ogg Normal file

Binary file not shown.

BIN
static/audio/take_piece.ogg Normal file

Binary file not shown.

BIN
static/audio/win.ogg Normal file

Binary file not shown.

View File

@ -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();
}
});