This commit is contained in:
Adrien MALINGREY 2023-04-24 01:00:02 +02:00
parent c4e269481d
commit 89d0ef98f9
2 changed files with 16 additions and 12 deletions

26
app.js
View File

@ -50,11 +50,13 @@ const KEY_NAMES = {
["ArrowUp"]: "↑", ["ArrowUp"]: "↑",
["ArrowDown"]: "↓", ["ArrowDown"]: "↓",
[" "]: "Espace", [" "]: "Espace",
["Escape"]: "Échap",
["←"]: "ArrowLeft", ["←"]: "ArrowLeft",
["→"]: "ArrowRight", ["→"]: "ArrowRight",
["↑"]: "ArrowUp", ["↑"]: "ArrowUp",
["↓"]: "ArrowDown", ["↓"]: "ArrowDown",
["Espace"]: " ", ["Espace"]: " ",
["Échap"]: "Escape",
} }
/* Customize Array to be use as coord */ /* Customize Array to be use as coord */
@ -419,7 +421,7 @@ class Stats {
this.highScore = Number(localStorage["highScore"]) || 0 this.highScore = Number(localStorage["highScore"]) || 0
this.combo = -1 this.combo = -1
this.b2b = -1 this.b2b = -1
this._time = 0 this.startTime = new Date()
} }
set score(score) { set score(score) {
@ -470,11 +472,12 @@ class Stats {
} }
set time(time) { set time(time) {
this._time = time - this._time this.startTime = new Date() - time
ticktack()
} }
get time() { get time() {
return this.timeFormat.format(new Date() - this._time) return new Date() - this.startTime
} }
lockDown(nbClearedLines, tSpin) { lockDown(nbClearedLines, tSpin) {
@ -572,8 +575,8 @@ function pause() {
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
scheduler.clearTimeout(repeat) scheduler.clearTimeout(repeat)
scheduler.clearInterval(autorepeat) scheduler.clearInterval(autorepeat)
scheduler.clearInterval(clock) scheduler.clearInterval(ticktack)
stats.time = new Date() stats.pauseTime = stats.time
resumeButton.disabled = false resumeButton.disabled = false
settings.modal.show() settings.modal.show()
} }
@ -586,6 +589,7 @@ function newGame(event) {
resume(event) resume(event)
levelInput.name = "level" levelInput.name = "level"
levelInput.disabled = true levelInput.disabled = true
titleHeader.innerHTML = "PAUSE"
resumeButton.innerHTML = "Reprendre" resumeButton.innerHTML = "Reprendre"
event.target.onsubmit = resume event.target.onsubmit = resume
stats.score = 0 stats.score = 0
@ -603,13 +607,13 @@ function resume(event) {
document.onkeydown = onkeydown document.onkeydown = onkeydown
document.onkeyup = onkeyup document.onkeyup = onkeyup
stats.time = new Date() stats.time = stats.pauseTime
scheduler.setInterval(clock, 1000) scheduler.setInterval(ticktack, 1000)
if (stats.fallPeriod) scheduler.setInterval(fall, stats.fallPeriod) if (stats.fallPeriod) scheduler.setInterval(fall, stats.fallPeriod)
} }
function clock() { function ticktack() {
timeCell.innerText = stats.time timeCell.innerText = stats.timeFormat.format(stats.time)
} }
function generate(piece) { function generate(piece) {
@ -767,7 +771,7 @@ function gameOver() {
document.onkeydown = null document.onkeydown = null
document.onkeyup = null document.onkeyup = null
onblur = null onblur = null
scheduler.clearInterval(clock) scheduler.clearInterval(ticktack)
messagesSpan.onanimationend = null messagesSpan.onanimationend = null
messagesSpan.addNewChild("div", { messagesSpan.addNewChild("div", {

View File

@ -19,7 +19,7 @@
<div class="modal-dialog modal-dialog-centered"> <div class="modal-dialog modal-dialog-centered">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h1 class="modal-title w-100 text-center">QUATRIS</h1> <h1 id="titleHeader" class="modal-title w-100 text-center">QUATRIS</h1>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form name="settingsForm"> <form name="settingsForm">