Skip to content

Commit fe7743a

Browse files
committed
Fixed timer response and bugs
1 parent a52f6e0 commit fe7743a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

js.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function pillEaten() {
259259
setTimeout( function(){
260260
ghosts.forEach(ghost => ghost.scared = true);
261261
time = 11;
262-
timer(time); }, 120 );
262+
timer(time); }, 12 );
263263
squares[pacCurrent].classList.remove('pill');
264264
foodCount--;
265265
}
@@ -293,21 +293,23 @@ function checkForWin() {
293293
ghosts.forEach(ghost => clearInterval(ghost.ID));
294294
document.removeEventListener('keydown', movePacman);
295295
document.getElementById('something').classList.add('win');
296+
time = 0;
296297
setTimeout( levelup , 3000 );
297298
flag = 1;
298299
}
299300
}
300301
function timer(o){
301-
let timeDisplay = 10*o - 1;
302+
let timeDisplay = 100*o - 1;
302303
let id = setInterval( function(){
303304
if ( timeDisplay == 0 || time == 0) {
304305
ghosts.forEach(ghost => ghost.scared = false);
305306
flag = 0;
306307
time = 0;
308+
document.getElementById('time').innerHTML = 0;
307309
clearInterval(id);}
308-
document.getElementById('time').innerHTML = Math.floor(timeDisplay/10);
310+
document.getElementById('time').innerHTML = Math.floor(timeDisplay/100);
309311
timeDisplay -= 1;
310-
} , 100 );
312+
} , 10 );
311313
}
312314
function scoreD(){
313315
document.getElementById('score').innerHTML = score;
@@ -318,6 +320,7 @@ function levelup(){
318320
levelCurrent++;
319321
level(document.getElementById('b1'));
320322
document.getElementById('something').classList.remove('win');
323+
document.getElementById('time').innerHTML = 0;
321324
score = 0;
322325
scoreD();
323326
if (lives < 5){

0 commit comments

Comments
 (0)