From: Elias Fleckenstein Date: Fri, 31 Dec 2021 18:30:40 +0000 (+0100) Subject: Initial commit X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2d9e2082732f4a497fdb5f953b8b431199b7fae1;p=whack-a-mole.git Initial commit --- 2d9e2082732f4a497fdb5f953b8b431199b7fae1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2f8b9d --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# whack-a-mole +A game created in 5 minutes. + +## Context + +I made this a few years ago and it was one of the first pieces of code I wrote, so please be gentle when reading a code. diff --git a/image.png b/image.png new file mode 100755 index 0000000..c9f12c7 Binary files /dev/null and b/image.png differ diff --git a/index.html b/index.html new file mode 100755 index 0000000..4d313a6 --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + + + + Whack a mole + + + + +
+

Whack a mole

+
+
+
+
+
+
+
+
+
+ +
+ + diff --git a/maulwurf.js b/maulwurf.js new file mode 100755 index 0000000..653dc24 --- /dev/null +++ b/maulwurf.js @@ -0,0 +1,32 @@ +var zeit = 1000; +var huegel = document.getElementsByName("huegel"); +var maulwurf = document.getElementsByName("maulwurf"); +var scoreDisplay = document.getElementById("score"); +var failTimeout = null; +var aktuellerHuegel = 0; +var score = -1; +for(let i in huegel){ + if(huegel[i].style){ + huegel[i].style.left = (5 + i * 100) + "px"; + maulwurf[i].addEventListener("click",_=>check(i)) + } + } +next(); +function check(nr){ + if(nr == aktuellerHuegel){ + next(); + } + } +function next(){ + score++; + scoreDisplay.innerHTML = score; + maulwurf[aktuellerHuegel].style.visibility = "hidden"; + aktuellerHuegel = Math.floor(Math.random()*huegel.length); + maulwurf[aktuellerHuegel].style.visibility = "visible"; + clearTimeout(failTimeout); + failTimeout = setTimeout(fail,zeit); + } +function fail(){ + alert("Game Over! Score: "+score); + location.reload(); + }