pause fonctionnelle en mode "temps" et "survie"

master
adplantade 5 years ago
parent b94437ede1
commit 63f8e77faa

@ -1,33 +1,56 @@
var fin = new Date();
fin.setMinutes(fin.getMinutes()+tpsRem[1]);
document.getElementById("timer").innerHTML = tpsRem[0] + ":" + tpsRem[1] + ":" + tpsRem[2];
// Update the count down every 1 second //---------------
var x = setInterval(function() { var time_in_minutes = tpsRem[1];
var current_time = Date.parse(new Date());
var deadline = new Date(current_time + time_in_minutes*60*1000);
// Get today's date and time
var now = new Date().getTime();;
function time_remaining(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
return {'total':t, 'days':days, 'hours':hours, 'minutes':minutes, 'seconds':seconds};
}
// Find the distance between now and the count down date var timeinterval;
var distance = fin - now; function run_clock(id,endtime){
var clock = document.getElementById(id);
function update_clock(){
var t = time_remaining(endtime);
clock.innerHTML = t.hours + ":" + t.minutes + ":" + t.seconds;
if(t.total<=0)
{
clearInterval(timeinterval);
window.location.replace("./score.php?pts="+points+"&mode="+get['mode']+"&diff="+get['diff']+"&pseudo="+get['pseudo']);
}
}
update_clock(); // run function once at first to avoid delay
timeinterval = setInterval(update_clock,1000);
}
run_clock('timer',deadline);
// Time calculations for days, hours, minutes and seconds
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("timer").innerHTML = hours + ":" + minutes + ":" + seconds; var pausedC = false; // is the clock paused?
var time_left; // time left on the clock when paused
// If the count down is over, write some text function pause_clock(){
if (distance < 0) { if(!pausedC){
clearInterval(x); pausedC = true;
console.log("OUT"); clearInterval(timeinterval); // stop the clock
window.location.replace("./score.php?pts="+points+"&mode="+get['mode']+"&diff="+get['diff']+"&pseudo="+get['pseudo']); time_left = time_remaining(deadline).total; // preserve remaining time
} }
}, 1000); }
function resume_clock(){
if(pausedC){
pausedC = false;
function addTime(secs) // update the deadline to preserve the amount of time remaining
{ deadline = new Date(Date.parse(new Date()) + time_left);
fin.setSeconds(fin.getSeconds()+secs);
// start the clock
run_clock('timer',deadline);
}
} }

@ -550,7 +550,10 @@ function checkAllOK(justChecking=false){
var audio = new Audio('ress/Jewel4.mp3'); var audio = new Audio('ress/Jewel4.mp3');
audio.play(); audio.play();
if(pause) if(pause)
{
chronoStop(); chronoStop();
pause_clock();
}
handleScore(1); handleScore(1);
won=true; won=true;
} }
@ -696,7 +699,11 @@ function mdManager(e){
} }
if(paused) if(paused)
{
chronoContinue(); chronoContinue();
resume_clock();
}
document.getElementById(e.currentTarget.id).classList.add('vitrail-select'); document.getElementById(e.currentTarget.id).classList.add('vitrail-select');
} }

Loading…
Cancel
Save