Skip to content

Commit

Permalink
Merge pull request #3688 from ShristiiSharma/shristi/main
Browse files Browse the repository at this point in the history
Added 10 sec alert and improved UI of Aim Training game
  • Loading branch information
kunjgit committed May 24, 2024
2 parents 4312384 + c8485a9 commit 9f793b0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions Games/Aim_Training/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
font-size: 30px; "><a href="https://kunjgit.github.io/GameZone/"><i style="color:black;" class="fas fa-home home-icon"></i></a></div>
<h1>Aim training</h1>
<div id="gameContainer">
<div id="countdown-alert"></div>
<div id="score">Score: <span id="scoreValue">0</span></div>
<div id="highScore">High Score: <span id="highScoreValue">0</span></div>
<div id="timer">Time Left: <span id="timerValue">30</span> seconds</div>
Expand Down
21 changes: 21 additions & 0 deletions Games/Aim_Training/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function startGame() {
timeLeft--;
timerElement.textContent = timeLeft;

if (timeLeft === 10) {
showAlert(timeLeft);
}

if (timeLeft === 0) {
clearInterval(timerId);
endGame();
Expand Down Expand Up @@ -135,5 +139,22 @@ function playEndSound() {
endSound.play();
}

// Function to show alert message
function showAlert(secondsLeft) {
const alertMessage = document.getElementById("countdown-alert");
alertMessage.textContent = `${secondsLeft} seconds left!`;
alertMessage.style.display = 'block';

// Update the countdown every second until the game ends
const updateInterval = setInterval(() => {
secondsLeft--;
alertMessage.textContent = `${secondsLeft} seconds left!`;
if (secondsLeft <= 0) {
clearInterval(updateInterval);
alertMessage.style.display = 'none';
}
}, 1000);
}

// Event listener for start button
document.getElementById("startButton").addEventListener("click", startGame);
30 changes: 30 additions & 0 deletions Games/Aim_Training/styles.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
body {
text-align: center;
background-color: #d3d3d3;
}

h1 {
color: #333;
font-size: 3em; /* Increase font size */
font-weight: bold; /* Make the text bold */
text-transform: uppercase; /* Uppercase letters */
letter-spacing: 5px; /* Add letter spacing */
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2); /* Add text shadow */
margin: 20px 0; /* Add some margin */
}

#gameContainer {
margin-top: 50px;
position: relative;
border-radius: 20px; /* Add border radius */
}

#score,
Expand Down Expand Up @@ -38,11 +46,15 @@ h1 {
background-color: #f00;
cursor: pointer;
transition: top 0.5s ease-in-out, left 0.5s ease-in-out;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); /* Add box shadow */
}

.bubble:hover {
background-color: #f00;
transform: scale(1.2);
transform: scale(1.2);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5); /* Increase shadow on hover */
transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out; /* Add transition */
}

#scoreValue,
Expand All @@ -63,6 +75,24 @@ h1 {
border: none;
cursor: pointer;
margin-top: 20px;
transition: transform 0.2s ease-in-out; /* Add transition */
}
.start-button:hover {
transform: scale(1.1); /* Scale up on hover */
}

#countdown-alert {
position: fixed;
top: 10px;
left: 50%;
transform: translateX(-50%);
background-color: red;
color: white;
padding: 10px 20px;
border-radius: 10px;
font-size: 1.2em;
display: none;
z-index: 1000; /* Ensure it's on top */
}

@keyframes countdown {
Expand Down

0 comments on commit 9f793b0

Please sign in to comment.