Skip to content

Commit

Permalink
New sounds when multiple right/wrong
Browse files Browse the repository at this point in the history
New "well done" sound (performed by our lad) if you get two in a row
New "Counting not guessing!" sound if you're just whacking number keys
  • Loading branch information
Harry Wood committed Jan 27, 2019
1 parent ef4d81f commit 1cea69c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
var celebrationTimer = null;
var processingKey = false;
var imageNumber = 0;
var wrongAudio;
var correctAudio;
var correctInARow = 0;
var wrongInARow = 0;
var sounds = {};

var images = [
{
Expand Down Expand Up @@ -128,8 +129,17 @@
function correctNumberPressed() {
if (processingKey) return;
processingKey = true;

correctInARow++;
wrongInARow = 0;

clearAll();
correctSound();
if (correctInARow==2) {
playSound("well-done");
correctInARow = 0;
} else {
playSound("correct");
}

document.getElementById('credits').style.display = "none";
celebrationTimer = setInterval( function(){ celebrateCorrect() }, 80);
Expand All @@ -152,7 +162,15 @@
function wrongNumberPressed() {
if (processingKey) return
clearAll();
wrongSound();

wrongInARow++;
correctInARow = 0;
if (wrongInARow==5) {
playSound("not-guessing")
wrongInARow = 0;
} else {
playSound("wrong");
}

// Re-draw images afer 2 seconds
gameTimer = setTimeout(function() {
Expand Down Expand Up @@ -246,14 +264,11 @@
return decodeURIComponent(results[2].replace(/\+/g, " "));
}

function wrongSound() {
if (typeof wrongAudio === 'undefined') wrongAudio = new Audio('wrong.mp3');
wrongAudio.play()
}
function correctSound() {
if (typeof correctAudio === 'undefined') correctAudio = new Audio('correct.mp3');
correctAudio.play()
function playSound(name) {
if (typeof sounds[name] === 'undefined') sounds[name] = new Audio(name + ".mp3");
sounds[name].play()
}

</script>
</html>
<body onLoad="init();">
Expand Down
Binary file added not-guessing.mp3
Binary file not shown.
Binary file added well-done.mp3
Binary file not shown.

0 comments on commit 1cea69c

Please sign in to comment.