fix hold disable
This commit is contained in:
parent
209f48699d
commit
2d41f0ecf2
@ -57,6 +57,8 @@ canvas {
|
|||||||
|
|
||||||
.hold {
|
.hold {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
|
flex-grow: 0;
|
||||||
|
justify-content: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats {
|
.stats {
|
||||||
@ -64,7 +66,6 @@ canvas {
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
margin: 10% 0;
|
margin: 10% 0;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
width: 120px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.stats-names {
|
.stats-names {
|
||||||
@ -75,6 +76,7 @@ canvas {
|
|||||||
.stats-values {
|
.stats-values {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
font-family: 'Share Tech Mono';
|
font-family: 'Share Tech Mono';
|
||||||
|
min-width: 90px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.matrix {
|
.matrix {
|
||||||
|
@ -249,8 +249,8 @@ function drawMino(context, pos, color1, color2=null, spotlight=[0, 0]) {
|
|||||||
|
|
||||||
|
|
||||||
class HoldQueue {
|
class HoldQueue {
|
||||||
constructor(context) {
|
constructor() {
|
||||||
this.context = context
|
this.context = document.getElementById("hold").getContext("2d")
|
||||||
this.piece = null
|
this.piece = null
|
||||||
this.width = HOLD_COLUMNS*MINO_SIZE
|
this.width = HOLD_COLUMNS*MINO_SIZE
|
||||||
this.height = HOLD_ROWS*MINO_SIZE
|
this.height = HOLD_ROWS*MINO_SIZE
|
||||||
@ -266,16 +266,17 @@ class HoldQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
timeFormat = new Intl.DateTimeFormat("en-US", {
|
timeFormat = new Intl.DateTimeFormat("fr-FR", {
|
||||||
hour: "numeric", minute: "2-digit", second: "2-digit", hourCycle: "h24", timeZone: "UTC"
|
minute: "2-digit", second: "2-digit", hourCycle: "h24", timeZone: "UTC"
|
||||||
}).format
|
}).format
|
||||||
|
|
||||||
|
|
||||||
class Stats {
|
class Stats {
|
||||||
constructor (div) {
|
constructor () {
|
||||||
this.div = div
|
this.div = document.getElementById("stats-values")
|
||||||
this._score = 0
|
this._score = 0
|
||||||
this.highScore = 0
|
this.lastHighScore = localStorage.getItem('highScore') || 0
|
||||||
|
this.highScore = this.lastHighScore
|
||||||
this.goal = 0
|
this.goal = 0
|
||||||
this.linesCleared = 0
|
this.linesCleared = 0
|
||||||
this.startTime = Date.now()
|
this.startTime = Date.now()
|
||||||
@ -340,14 +341,19 @@ class Stats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print() {
|
print() {
|
||||||
this.div.innerHTML = `${this.score}<br/>${this.highScore}<br/>${this.level}<br/>${this.goal}<br/>${this.linesCleared}<br/>${timeFormat(Date.now() - this.startTime)}`
|
this.div.innerHTML = `${this.score}<br/>
|
||||||
|
${this.highScore}<br/>
|
||||||
|
${timeFormat(Date.now() - this.startTime)}<br/>
|
||||||
|
${this.level}<br/>
|
||||||
|
${this.goal}<br/>
|
||||||
|
${this.linesCleared}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Matrix {
|
class Matrix {
|
||||||
constructor(context) {
|
constructor() {
|
||||||
this.context = context
|
this.context = document.getElementById("matrix").getContext("2d")
|
||||||
this.context.textAlign = "center"
|
this.context.textAlign = "center"
|
||||||
this.context.textBaseline = "center"
|
this.context.textBaseline = "center"
|
||||||
this.context.font = "3vw 'Share Tech', sans-serif"
|
this.context.font = "3vw 'Share Tech', sans-serif"
|
||||||
@ -458,8 +464,8 @@ class Matrix {
|
|||||||
|
|
||||||
|
|
||||||
class NextQueue {
|
class NextQueue {
|
||||||
constructor(context) {
|
constructor() {
|
||||||
this.context = context
|
this.context = document.getElementById("next").getContext("2d")
|
||||||
this.pieces = Array.from({length: NEXT_PIECES}, (v, k) => new Tetromino(NEXT_PIECES_POSITIONS[k]))
|
this.pieces = Array.from({length: NEXT_PIECES}, (v, k) => new Tetromino(NEXT_PIECES_POSITIONS[k]))
|
||||||
this.width = NEXT_COLUMNS*MINO_SIZE
|
this.width = NEXT_COLUMNS*MINO_SIZE
|
||||||
this.height = NEXT_ROWS*MINO_SIZE
|
this.height = NEXT_ROWS*MINO_SIZE
|
||||||
@ -598,6 +604,11 @@ function gameOver() {
|
|||||||
scheduler.clearTimeout(locksDown)
|
scheduler.clearTimeout(locksDown)
|
||||||
scheduler.clearInterval(clock)
|
scheduler.clearInterval(clock)
|
||||||
requestAnimationFrame(draw)
|
requestAnimationFrame(draw)
|
||||||
|
|
||||||
|
if (stats.score > stats.lastHighScore) {
|
||||||
|
alert("Bravo ! Vous avez battu votre meilleur score.")
|
||||||
|
localStorage.setItem('highScore', stats.highScore)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function autorepeat() {
|
function autorepeat() {
|
||||||
@ -692,12 +703,12 @@ function rotateCCW() {
|
|||||||
|
|
||||||
function hold() {
|
function hold() {
|
||||||
if (this.matrix.piece.holdEnabled) {
|
if (this.matrix.piece.holdEnabled) {
|
||||||
this.matrix.piece.holdEnabled = false
|
|
||||||
scheduler.clearInterval(move)
|
scheduler.clearInterval(move)
|
||||||
scheduler.clearInterval(locksDown)
|
scheduler.clearInterval(locksDown)
|
||||||
var shape = this.matrix.piece.shape
|
var shape = this.matrix.piece.shape
|
||||||
this.matrix.piece = this.holdQueue.piece
|
this.matrix.piece = this.holdQueue.piece
|
||||||
this.holdQueue.piece = new Tetromino(HELD_PIECE_POSITION, shape)
|
this.holdQueue.piece = new Tetromino(HELD_PIECE_POSITION, shape)
|
||||||
|
this.holdQueue.piece.holdEnabled = false
|
||||||
this.generationPhase(this.matrix.piece)
|
this.generationPhase(this.matrix.piece)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -748,10 +759,10 @@ function draw() {
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
tempTexts = []
|
tempTexts = []
|
||||||
|
|
||||||
holdQueue = new HoldQueue(document.getElementById("hold").getContext("2d"))
|
holdQueue = new HoldQueue()
|
||||||
stats = new Stats(document.getElementById("stats-values"))
|
stats = new Stats()
|
||||||
matrix = new Matrix(document.getElementById("matrix").getContext("2d"))
|
matrix = new Matrix()
|
||||||
nextQueue = new NextQueue(document.getElementById("next").getContext("2d"))
|
nextQueue = new NextQueue()
|
||||||
|
|
||||||
pressedKeys = new Set()
|
pressedKeys = new Set()
|
||||||
actionsToRepeat = []
|
actionsToRepeat = []
|
||||||
|
10
webtris.html
10
webtris.html
@ -19,11 +19,11 @@
|
|||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="stats-names">
|
<div class="stats-names">
|
||||||
SCORE<br/>
|
SCORE<br/>
|
||||||
HIGH<br/>
|
MEILLEUR<br/>
|
||||||
LEVEL<br/>
|
TEMPS<br/>
|
||||||
GOAL<br/>
|
NIVEAU<br/>
|
||||||
LINES<br/>
|
OBJECTIF<br/>
|
||||||
TIME<br/>
|
LIGNES<br/>
|
||||||
</div>
|
</div>
|
||||||
<div id="stats-values" class="stats-values"></div>
|
<div id="stats-values" class="stats-values"></div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user