You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

function initTimer() {
var TimerElem = document.querySelector(".timer_bar");
TimerElem.style.width = "0%";
let seconds = timeEnd;
document.getElementById("timerend").innerHTML = " / " + seconds + " s";
}
function move() {
var lapsPerSecond = 100 / timeEnd;
var TimerElem = document.querySelector(".timer_bar");
TimerElem.style.width = (parseInt(TimerElem.style.width) + lapsPerSecond) + "%";
}
var timer = new easytimer.Timer();
timer.start();
timer.addEventListener('secondsUpdated', function (e) {
if (timer.getTimeValues().seconds <= timeEnd) {
document.getElementById("timer").innerHTML = timer.getTimeValues().seconds.toString() + " s";
move();
} else {
timeTot = timeTot + timer.getTimeValues().seconds;
endTime();
timer.stop();
}
});
function endTime() {
if(!isTuto){
document.querySelector("#mainPage").style.display = 'block';
var score = (niveauActuel * (50 / timeTot)).toFixed(2);
document.querySelector("#playPage").style.display = 'none';
document.querySelector("#scoreTotGameOver").innerHTML = score;
document.querySelector("#niveauGameOver").innerHTML = niveauActuel;
document.querySelector("#TempsTotGameOver").innerHTML = timeTot;
//calcul stars
if(score < 10){
document.querySelector("#star1").style.color = "#fe8a71";
}else if(score > 10 || score < 50){
document.querySelector("#star2").style.color = "#fe8a71";
}else if(score > 10 || score < 50){
document.querySelector("#star2").style.color = "#fe8a71";
}
openModal('gameOver');
}
}