forked from Kushal997-das/Project-Guidance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a37ee9c
commit 140c447
Showing
9 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The game involves clicking on randomly appearing moles to score points while avoiding randomly appearing piranha plants, as clicking on a plant ends the game. Moles and plants appear at random intervals on a 3x3 grid, and the score updates dynamically based on player actions. | ||
|
||
# How to run ? | ||
Just run the index.html file | ||
|
||
# Output | ||
![image](https://github.com/user-attachments/assets/6ba2bd26-89ad-4cf6-92e8-c87155302272) |
17 changes: 17 additions & 0 deletions
17
Web Development/Basic/Smash-Monty-mole-master-main/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Whac a Mole</title> | ||
<link rel="stylesheet" href="mole.css"> | ||
<script src="mole.js"></script> | ||
</head> | ||
<body> | ||
<h1>Smash Monty-Mole</h1> | ||
<h2 id="score">0</h2> | ||
<!-- 3x3 --> | ||
<div id="board"> | ||
</div> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
Web Development/Basic/Smash-Monty-mole-master-main/mole.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
text-align: center; | ||
background: url("./mario-bg.jpg"); | ||
background-size: cover; | ||
} | ||
|
||
#board { | ||
width: 540px; | ||
height: 540px; | ||
/* background-color: green; */ | ||
|
||
margin: 0 auto; | ||
display: flex; | ||
flex-wrap: wrap; | ||
|
||
background: url("./soil.png"); | ||
background-size: cover; | ||
border: 3px solid white; | ||
border-radius: 25px; | ||
} | ||
|
||
#board div { | ||
/* board = 540 x 540, divide into 3x3 tiles --> 180 x 180 per div */ | ||
width: 180px; | ||
height: 180px; | ||
background-image: url("./pipe.png"); | ||
background-size: cover; | ||
} | ||
|
||
#board div img { | ||
/* all img tags inside tiles */ | ||
width: 100px; | ||
height: 100px; | ||
|
||
user-select: none; | ||
-moz-user-select: none; | ||
-webkit-user-drag: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
} |
77 changes: 77 additions & 0 deletions
77
Web Development/Basic/Smash-Monty-mole-master-main/mole.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
let currMoleTile; | ||
let currPlantTile; | ||
let score = 0; | ||
let gameOver = false; | ||
|
||
window.onload = function() { | ||
setGame(); | ||
} | ||
|
||
function setGame() { | ||
//set up the grid in html | ||
for (let i = 0; i < 9; i++) { //i goes from 0 to 8, stops at 9 | ||
//<div id="0-8"></div> | ||
let tile = document.createElement("div"); | ||
tile.id = i.toString(); | ||
tile.addEventListener("click", selectTile); | ||
document.getElementById("board").appendChild(tile); | ||
} | ||
setInterval(setMole, 1000); // 1000 miliseconds = 1 second, every 1 second call setMole | ||
setInterval(setPlant, 2000); // 2000 miliseconds = 2 seconds, every 2 second call setPlant | ||
} | ||
|
||
function getRandomTile() { | ||
//math.random --> 0-1 --> (0-1) * 9 = (0-9) --> round down to (0-8) integers | ||
let num = Math.floor(Math.random() * 9); | ||
return num.toString(); | ||
} | ||
|
||
function setMole() { | ||
if (gameOver) { | ||
return; | ||
} | ||
if (currMoleTile) { | ||
currMoleTile.innerHTML = ""; | ||
} | ||
let mole = document.createElement("img"); | ||
mole.src = "./monty-mole.png"; | ||
|
||
let num = getRandomTile(); | ||
if (currPlantTile && currPlantTile.id == num) { | ||
return; | ||
} | ||
currMoleTile = document.getElementById(num); | ||
currMoleTile.appendChild(mole); | ||
} | ||
|
||
function setPlant() { | ||
if (gameOver) { | ||
return; | ||
} | ||
if (currPlantTile) { | ||
currPlantTile.innerHTML = ""; | ||
} | ||
let plant = document.createElement("img"); | ||
plant.src = "./piranha-plant.png"; | ||
|
||
let num = getRandomTile(); | ||
if (currMoleTile && currMoleTile.id == num) { | ||
return; | ||
} | ||
currPlantTile = document.getElementById(num); | ||
currPlantTile.appendChild(plant); | ||
} | ||
|
||
function selectTile() { | ||
if (gameOver) { | ||
return; | ||
} | ||
if (this == currMoleTile) { | ||
score += 10; | ||
document.getElementById("score").innerText = score.toString(); //update score html | ||
} | ||
else if (this == currPlantTile) { | ||
document.getElementById("score").innerText = "GAME OVER: " + score.toString(); //update score html | ||
gameOver = true; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.