add sounds and a gitignore for temp sound files.
This commit is contained in:
parent
07a8bdca8d
commit
e1cdd4ea1f
|
|
@ -0,0 +1 @@
|
||||||
|
*.DS_Store
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,6 +1,13 @@
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
// Constants for adjusting game
|
// Constants for adjusting game
|
||||||
const MAX_SNAP_DISTANCE = 90;
|
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
|
// Track game state
|
||||||
let tokensRemaining = 5;
|
let tokensRemaining = 5;
|
||||||
|
|
@ -131,12 +138,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
function captureCell(cell) {
|
function captureCell(cell) {
|
||||||
const existingToken = cell.querySelector('.token')
|
const existingToken = cell.querySelector('.token')
|
||||||
if (existingToken && existingToken.dataset.captured == 'false') {
|
if (existingToken && existingToken.dataset.captured == 'false') {
|
||||||
|
takePieceSound.currentTime = 0; // rewind so it can play repeatedly
|
||||||
|
takePieceSound.play();
|
||||||
existingToken.dataset.captured = 'true';
|
existingToken.dataset.captured = 'true';
|
||||||
existingToken.style.display = 'none';
|
existingToken.style.display = 'none';
|
||||||
tokensRemaining--;
|
tokensRemaining--;
|
||||||
inStreak = true;
|
inStreak = true;
|
||||||
} else {
|
} else {
|
||||||
if (inStreak) {
|
if (inStreak) {
|
||||||
|
failStreakSound.currentTime = 0; // rewind so it can play repeatedly
|
||||||
|
failStreakSound.play();
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -151,11 +162,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
const {cell: closestCell, distance} = getClosestCellByDistance(e.pageX, e.pageY);
|
const {cell: closestCell, distance} = getClosestCellByDistance(e.pageX, e.pageY);
|
||||||
|
|
||||||
if (distance > MAX_SNAP_DISTANCE) {
|
if (distance > MAX_SNAP_DISTANCE) {
|
||||||
|
offBoardSound.currentTime = 0; // rewind so it can play repeatedly
|
||||||
|
offBoardSound.play();
|
||||||
resetToken(player_token.parentElement);
|
resetToken(player_token.parentElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkMoveValid(player_token.parentElement, closestCell)) {
|
if (!checkMoveValid(player_token.parentElement, closestCell)) {
|
||||||
|
errorSound.currentTime = 0; // rewind so it can play repeatedly
|
||||||
|
errorSound.play();
|
||||||
resetBoard()
|
resetBoard()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -172,9 +187,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
player_token.style.zIndex = '';
|
player_token.style.zIndex = '';
|
||||||
|
|
||||||
closestCell.appendChild(player_token);
|
closestCell.appendChild(player_token);
|
||||||
|
placeSound.currentTime = 0; // rewind so it can play repeatedly
|
||||||
|
placeSound.play();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (tokensRemaining == 0) {
|
if (tokensRemaining == 0) {
|
||||||
alert("You win!")
|
alert("You win!")
|
||||||
|
winSound.currentTime = 0; // rewind so it can play repeatedly
|
||||||
|
winSound.play();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue