From 2700d8e2a2bf387066ba2841448f826e4a73b0e1 Mon Sep 17 00:00:00 2001 From: adrien Date: Fri, 21 Apr 2023 22:13:23 +0200 Subject: [PATCH] time --- app.js | 33 +++++++++++++++++++++++++++++---- index.html | 9 +++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index fcb3021..7bb7216 100644 --- a/app.js +++ b/app.js @@ -413,11 +413,12 @@ class Stats { this.highScore = Number(localStorage["highScore"]) || 0 this.combo = -1 this.b2b = -1 + this.time = 0 } set score(score) { this._score = score - scoreTd.innerText = score.toLocaleString() + scoreCell.innerText = score.toLocaleString() if (score > this.highScore) { this.highScore = score } @@ -429,7 +430,7 @@ class Stats { set highScore(highScore) { this._highScore = highScore - highScoreTd.innerText = highScore.toLocaleString() + highScoreCell.innerText = highScore.toLocaleString() } get highScore() { @@ -445,7 +446,7 @@ class Stats { if (level > 15) this.lockDelay = 500 * Math.pow(0.9, level - 15) levelInput.value = level - levelTd.innerText = level + levelCell.innerText = level levelSpan.innerHTML = `

LEVEL
${this.level}

` levelSpan.classList.add("show-level-animation") } @@ -456,13 +457,22 @@ class Stats { set goal(goal) { this._goal = goal - goalTd.innerText = goal + goalCell.innerText = goal } get goal() { return this._goal } + set time(time) { + this._time = time + timeCell.innerText = this.timeFormat.format(1000 * time) + } + + get time() { + return this._time + } + lockDown(nbClearedLines, tSpin) { // Cleared lines & T-Spin let patternScore = SCORES[tSpin][nbClearedLines] * this.level @@ -523,6 +533,11 @@ class Stats { if (this.goal <= 0) this.level++ } } +Stats.prototype.timeFormat = new Intl.DateTimeFormat("fr-FR", { + minute: "2-digit", + second: "2-digit", + timeZone: "UTC" +}) /* Game */ @@ -550,6 +565,7 @@ function pause() { scheduler.clearTimeout(lockDown) scheduler.clearTimeout(repeat) scheduler.clearInterval(autorepeat) + scheduler.clearInterval(clock) resumeButton.disabled = false settings.modal.show() } @@ -581,9 +597,14 @@ function resume(event) { document.onkeydown = onkeydown document.onkeyup = onkeyup + scheduler.setInterval(clock, 1000) if (stats.fallPeriod) scheduler.setInterval(fall, stats.fallPeriod) } +function clock() { + stats.time++ +} + function generate(piece=nextQueue.shift()) { matrix.piece = piece @@ -740,8 +761,12 @@ function lockDown() { function gameOver() { matrix.piece.locked = false matrix.drawPiece() + document.onkeydown = null document.onkeyup = null + + scheduler.clearInterval(clock) + localStorage["highScore"] = stats.highScore levelSpan.innerHTML = "

GAME
OVER

" levelSpan.classList.add("show-level-animation") diff --git a/index.html b/index.html index f67a094..a9aae51 100644 --- a/index.html +++ b/index.html @@ -119,10 +119,11 @@
- - - - + + + + +
Score0
Meilleur score0
Niveau0
But0
Score0
Meilleur score0
Niveau0
But0
Temps00:00