diff --git a/Games/Hole_And_Mole_Game/README.md b/Games/Hole_And_Mole_Game/README.md new file mode 100644 index 0000000000..d4a349a77e --- /dev/null +++ b/Games/Hole_And_Mole_Game/README.md @@ -0,0 +1,6 @@ +# mole-and-hole-game + +this is a simple mole and hole a web based game built using html css js.
+where you have to catch the mole, whenever you click on mole you will get points. + + diff --git a/Games/Hole_And_Mole_Game/img/hole.png b/Games/Hole_And_Mole_Game/img/hole.png new file mode 100644 index 0000000000..b8354ec8ab Binary files /dev/null and b/Games/Hole_And_Mole_Game/img/hole.png differ diff --git a/Games/Hole_And_Mole_Game/img/mole.png b/Games/Hole_And_Mole_Game/img/mole.png new file mode 100644 index 0000000000..c184784eb1 Binary files /dev/null and b/Games/Hole_And_Mole_Game/img/mole.png differ diff --git a/Games/Hole_And_Mole_Game/index.html b/Games/Hole_And_Mole_Game/index.html new file mode 100644 index 0000000000..6415bec5b7 --- /dev/null +++ b/Games/Hole_And_Mole_Game/index.html @@ -0,0 +1,60 @@ + + + + + + + + + Hole and Mole Game + + + +

Catch me, If you can 0

+ + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ + +
+ +
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + diff --git a/Games/Hole_And_Mole_Game/script.js b/Games/Hole_And_Mole_Game/script.js new file mode 100644 index 0000000000..b6d1138db9 --- /dev/null +++ b/Games/Hole_And_Mole_Game/script.js @@ -0,0 +1,95 @@ +// Selecting all the elements from the DOM +const holes = document.querySelectorAll(".hole"); +const scoreBoard = document.querySelector(".score"); +const moles = document.querySelectorAll(".mole"); +const startBtn = document.querySelector(".start-btn"); +const levels = document.querySelector(".levels"); +const game = document.querySelector(".game"); + +let lastHole; +let timeUp = false; +let score = 0; + +function difficultyLevel() { + const ele = document.getElementsByName("level"); + for (let i = 0; i < ele.length; i++) { + if (ele[i].checked) { + return ele[i].id; + } + } +} + +// random time between min and max +function randomTime(min, max) { + return Math.round(Math.random() * (max - min) + min); +} + +// Select a random hole to pop up the mole +function randomHole(holes) { + const idx = Math.floor(Math.random() * holes.length); + const hole = holes[idx]; + if (hole === lastHole) { + return randomHole(holes); + } + lastHole = hole; + return hole; +} + +// make the mole appear and disappear +function peep(show, hide) { + const time = randomTime(show, hide); + const hole = randomHole(holes); + hole.classList.add("up"); + setTimeout(() => { + hole.classList.remove("up"); + if (!timeUp) { + peep(show, hide); + } + }, time); +} + +function startGame() { + let show, hide; + const difficulty = difficultyLevel(); + if (difficulty === "easy") { + show = 500; + hide = 1500; + } else if (difficulty === "medium") { + show = 200; + hide = 1000; + } else { + show = 100; + hide = 800; + } + + // hiding start button while game running + scoreBoard.textContent = 0; + timeUp = false; + startBtn.innerHTML = "running.."; + startBtn.disabled = true; + levels.style.visibility = "hidden"; + score = 0; + + // Start the game by making moles appear + peep(show, hide); + + // Finish the game after 15 seconds + setTimeout(() => { + timeUp = true; + startBtn.innerHTML = "start!"; + startBtn.disabled = false; + levels.style.visibility = "visible"; + }, 15000); +} + +// update the score on clicking the mole +function hitTheMole(e) { + if (!e.isTrusted) { + return; + } + score++; + this.parentNode.classList.remove("up"); + scoreBoard.textContent = score; +} + +moles.forEach((mole) => mole.addEventListener("click", hitTheMole)); diff --git a/Games/Hole_And_Mole_Game/style.css b/Games/Hole_And_Mole_Game/style.css new file mode 100644 index 0000000000..4dcbfe6354 --- /dev/null +++ b/Games/Hole_And_Mole_Game/style.css @@ -0,0 +1,150 @@ +/* Reset default styles */ +* { + margin: 0px; + padding: 0px; + box-sizing: border-box; +} + +/* Global styles */ +body { + font-family: cursive; + background-color: #191919; + color: #fff; +} + +h1 { + text-align: center; + font-size: 5rem; + line-height: 1; + margin-top: 45px; +} + +.score { + color: #4caf50; + background: #302f2fed; + padding: 1rem; + line-height: 1; + border-radius: 1rem; + display: inline-block; +} + +.controls { + margin: 5px; + text-align: center; +} + +/* Buttons */ +.start-btn { + padding: 10px 25px; + outline: none; + font-size: 24px; + background: #c2185b; + color: #fff; + border: 0px; + border-radius: 0.5rem; + box-shadow: 1px 2px 4px #c2185bb0; + cursor: pointer; +} + +.start-btn:hover { + background: #187bc2; + box-shadow: 1px 2px 4px #185fc2b0; +} + +/* Difficulty levels */ +.levels { + font-size: 20px; + display: flex; + align-items: center; + justify-content: center; +} + +/* Style for each difficulty level */ +.levels > div { + margin: 20px; +} + +.levels > div:nth-child(1) { + color: #00ff00; +} +.levels > div:nth-child(2) { + color: #ffd24e; +} +.levels > div:nth-child(3) { + color: #ff0000; +} + +/* game board */ +.game { + width: 600px; + height: 400px; + display: flex; + flex-wrap: wrap; + margin: 0 auto; +} + +/* holes on the game board */ +.hole { + flex: 1 0 33.33%; + overflow: hidden; + position: relative; +} + +/* mole inside hole */ +.hole:after { + background: url("img/hole.png") bottom center no-repeat; + background-size: contain; + content: ""; + width: 100%; + height: 70px; + position: absolute; + z-index: 2; + bottom: -30px; +} + +/* moles */ +.mole { + position: absolute; + top: 100%; + width: 100%; + height: 100%; + background: url("img/mole.png") bottom center no-repeat; + background-size: 60%; + transition: all 0.4s; + cursor: pointer; +} + +/* mole when visible */ +.hole.up .mole { + top: 0; +} + +/* Responsive adjustments for smaller screens */ +@media (max-width: 768px) { + h1 { + padding: 20px; + font-size: 2rem; + } + + .score { + margin: 20px; + } + + .hole::after { + bottom: -22px; + margin: 6px; + } + + .start-btn { + padding: 8px 20px; + } + + .levels > div { + margin: 10px; + } + + .game { + width: 90%; + height: 300px; + } +} diff --git a/README.md b/README.md index ef93715e40..a03221c94b 100644 --- a/README.md +++ b/README.md @@ -1680,8 +1680,10 @@ This repository also provides one such platforms where contributers come over an |[2D_Fighting_Game](https://github.com/kunjgit/GameZone/tree/main/Games/2D_Fighting_Game)| | [Airhockey_game](https://github.com/kunjgit/GameZone/tree/main/Games/Airhockey_game)| +| [Hole_And_Mole_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Hole_And_Mole_Game)| |[Animal_Name_Guessing](https://github.com/kunjgit/GameZone/tree/main/Games/Animal_Name_Guessing)| +
diff --git a/assets/images/Hole_And_Mole_Game.png b/assets/images/Hole_And_Mole_Game.png new file mode 100644 index 0000000000..c184784eb1 Binary files /dev/null and b/assets/images/Hole_And_Mole_Game.png differ