Skip to content

Commit

Permalink
Quick_Click Game Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshitmishra001 committed Jun 2, 2024
1 parent 8e31ead commit a753892
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

assets/images/Pixel_Painter.png
33 changes: 33 additions & 0 deletions Games/Quick_Click/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quick Click</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<h1>Quick Click</h1>
<div class="scoreboard">
<span>Score: <span id="score">0</span></span>
<span>Time: <span id="time">60</span>s</span>
</div>
<div class="grid">
<div class="circle" id="circle0"></div>
<div class="circle" id="circle1"></div>
<div class="circle" id="circle2"></div>
<div class="circle" id="circle3"></div>
<div class="circle" id="circle4"></div>
<div class="circle" id="circle5"></div>
<div class="circle" id="circle6"></div>
<div class="circle" id="circle7"></div>
<div class="circle" id="circle8"></div>
</div>
<button id="start">Start Game</button>

<script src="script.js"></script>
</body>

</html>
61 changes: 61 additions & 0 deletions Games/Quick_Click/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const circles = document.querySelectorAll('.circle');
const scoreDisplay = document.getElementById('score');
const timeDisplay = document.getElementById('time');
const startButton = document.getElementById('start');
let score = 0;
let activeCircle = null;
let gameTimer = null;
let countdownTimer = null;
let timeLeft = 60;

function randomCircle() {
circles.forEach(circle => circle.classList.remove('active'));
const randomIndex = Math.floor(Math.random() * circles.length);
activeCircle = circles[randomIndex];
activeCircle.classList.add('active');
console.log("Random Circle Selected:", activeCircle);
}

function startGame() {
score = 0;
timeLeft = 60;
scoreDisplay.textContent = score;
timeDisplay.textContent = timeLeft;
startButton.disabled = true;
randomCircle();
gameTimer = setInterval(randomCircle, 1000);
countdownTimer = setInterval(countDown, 1000);
circles.forEach(circle => circle.addEventListener('click', whack));
console.log("Game Started");
}

function whack(event) {
if (event.target === activeCircle) {
score++;
scoreDisplay.textContent = score;
activeCircle.classList.remove('active');
randomCircle();
} else {
endGame('You Lose!');
}
}

function countDown() {
timeLeft--;
timeDisplay.textContent = timeLeft;
if (timeLeft <= 0) {
endGame('Time\'s Up! Game Over!');
}
}

function endGame(message) {
console.log("Game Ended:", message);
clearInterval(gameTimer);
clearInterval(countdownTimer);
circles.forEach(circle => circle.classList.remove('active'));
circles.forEach(circle => circle.removeEventListener('click', whack));
startButton.disabled = false;
alert(`${message} Your final score is ${score}`);
}

startButton.addEventListener('click', startGame);
48 changes: 48 additions & 0 deletions Games/Quick_Click/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

h1 {
margin-top: 20px;
}

.scoreboard {
margin: 20px 0;
font-size: 1.5em;
}

.grid {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-gap: 10px;
justify-content: center;
margin: 20px auto;
}

.circle {
width: 100px;
height: 100px;
background-color: #ccc;
border-radius: 50%;
position: relative;
cursor: pointer;
}

.circle.active {
background-image: url('GameZone\Games\Reflex_text\Mole2.jpg');
background-size: cover;
background-position: center;
background-color: #ffd700;
/* Fallback background color */
}

button {
margin-top: 20px;
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
}
Binary file modified assets/images/Pixel_Painter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a753892

Please sign in to comment.