I've been building a game using Visual Studio 2012 ultimate. The aim of the game is to click as many coins as you can which fly from the bottom of the screen to the top. I want to have a timer displayed on the screen so when it reaches zero the game is over.
So far i have achieved in making a countdown timer which counts to zero but then loops back to its starting time and counts down again.
I was wondering how i could stop the looping of this timer, and also when the timer reaches to zero i would like to have a game over screen pop up.
If anyone has any code that achieves a count down timer with game over that would be awesome.
What I have tried:
-This is the HTML-
<p id="demo"></p>
-This is the CSS-
#demo {
font-family: 'Arizonia-Regular';
position: absolute;
font-size: 35px;
color: #ff0000;
bottom: 50px;
right: 70px;
background-color: black;
width: 135px;
border: 4px solid red;
border-left-color: black;
padding: 5px;
margin: 5px;
}
-This is the script-
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2018 15:37:25").getTime();
// Update the count down every 1 second
var x = setInterval(function () {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for minutes and seconds
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);