Skip to content

Commit

Permalink
fix: hints being sent multiple time
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenil committed Apr 30, 2024
1 parent f09fe30 commit a178182
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h2>Chat</h2>
<script>
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var hintSent = false;
var lastHintTime = 0; // Store the last time a hint was sent

var timerInterval = setInterval(function() {
minutes = parseInt(timer / 60, 10);
Expand All @@ -124,18 +124,19 @@ <h2>Chat</h2>

display.textContent = minutes + ":" + seconds;


if (timer > 0 && timer % 30 === 0 && !hintSent) {
sendHintRequest();
hintSent = true;
} else if (timer % 30 !== 0) {
hintSent = false;
// Get current time in seconds since the timer started
var currentTime = duration - timer;

// Send a hint request every 30 seconds
if (currentTime >= lastHintTime + 30) {
sendHintRequest();
lastHintTime = currentTime; // Update the last hint time
}

if (--timer < 0) {
clearInterval(timerInterval);
alert("Time's up!");
display.textContent = "00:00";
display.textContent = "00:00"; // Reset timer display
}
}, 1000);
}
Expand All @@ -156,7 +157,7 @@ <h2>Chat</h2>
}

window.onload = function() {
startGameTimer();
startGameTimer(); // Start the game timer when the window loads
};
</script>

Expand Down

0 comments on commit a178182

Please sign in to comment.