Compare commits

..

No commits in common. "44684fe4592983ba7bf1833f6ec526e95e2b466c" and "e924ad101a1768ae543991b4474aa73aa175d5f1" have entirely different histories.

5 changed files with 30 additions and 47 deletions

71
app.js
View File

@ -17,11 +17,11 @@ const T_SPIN = {
T_SPIN: "PIROUETTE" T_SPIN: "PIROUETTE"
} }
// score = AWARDED_LINE_CLEARS[tSpin][nbClearedLines] // score = SCORES[tSpin][nbClearedLines]
const AWARDED_LINE_CLEARS = { const SCORES = {
[T_SPIN.NONE]: [0, 1, 3, 5, 8], [T_SPIN.NONE]: [0, 100, 300, 500, 800],
[T_SPIN.MINI]: [1, 2], [T_SPIN.MINI]: [100, 200],
[T_SPIN.T_SPIN]: [4, 8, 12, 16] [T_SPIN.T_SPIN]: [400, 800, 1200, 1600]
} }
const CLEARED_LINES_NAMES = [ const CLEARED_LINES_NAMES = [
@ -159,8 +159,8 @@ MinoesTable.prototype.init_center = [2, 2]
class NextQueue extends MinoesTable { class NextQueue extends MinoesTable {
constructor() { constructor(id) {
super("nextTable") super(id)
this.pieces = this.init_centers.map(center => { this.pieces = this.init_centers.map(center => {
let piece = new Tetromino.pick() let piece = new Tetromino.pick()
piece.center = Array.from(center) piece.center = Array.from(center)
@ -188,9 +188,9 @@ class NextQueue extends MinoesTable {
NextQueue.prototype.init_centers = [[2, 2], [2, 5], [2, 8], [2, 11], [2, 14]] NextQueue.prototype.init_centers = [[2, 2], [2, 5], [2, 8], [2, 11], [2, 14]]
class Matrix extends MinoesTable { class PlayfieldMatrix extends MinoesTable {
constructor() { constructor(id, piece_init_position) {
super("matrixTable") super(id, piece_init_position)
this.blocks = Array(this.rows).fill().map(() => Array(this.columns)) this.blocks = Array(this.rows).fill().map(() => Array(this.columns))
} }
@ -226,7 +226,7 @@ class Matrix extends MinoesTable {
} }
} }
} }
Matrix.prototype.init_center = [5, 4] PlayfieldMatrix.prototype.init_center = [5, 4]
class Tetromino { class Tetromino {
@ -377,7 +377,9 @@ Z.prototype.minoesPosition = [
class Settings { class Settings {
constructor() { constructor() {
this.form = settingsForm this.form = settingsForm
this.load() for (let input of this.form.getElementsByTagName("input")) {
if (localStorage[input.name]) input.value = localStorage[input.name]
}
this.form.onsubmit = newGame this.form.onsubmit = newGame
this.modal = new bootstrap.Modal('#settingsModal') this.modal = new bootstrap.Modal('#settingsModal')
document.getElementById('settingsModal').addEventListener('shown.bs.modal', () => { document.getElementById('settingsModal').addEventListener('shown.bs.modal', () => {
@ -386,19 +388,6 @@ class Settings {
} }
load() { load() {
for (let input of this.form.getElementsByTagName("input")) {
if (localStorage[input.name]) input.value = localStorage[input.name]
}
}
show() {
resumeButton.disabled = false
settings.form.classList.remove('was-validated')
settings.modal.show()
settings.form.reportValidity()
}
getInputs() {
for (let input of keyBindFielset.getElementsByTagName("input")) { for (let input of keyBindFielset.getElementsByTagName("input")) {
this[input.name] = KEY_NAMES[input.value] || input.value this[input.name] = KEY_NAMES[input.value] || input.value
} }
@ -495,8 +484,7 @@ class Stats {
lockDown(nbClearedLines, tSpin) { lockDown(nbClearedLines, tSpin) {
// Cleared lines & T-Spin // Cleared lines & T-Spin
let awardedLineClears = AWARDED_LINE_CLEARS[tSpin][nbClearedLines] let patternScore = SCORES[tSpin][nbClearedLines] * this.level
let patternScore = 100 * this.level * awardedLineClears
if (tSpin) messagesSpan.addNewChild("div", { if (tSpin) messagesSpan.addNewChild("div", {
className: "rotate-in-animation", className: "rotate-in-animation",
innerHTML: tSpin innerHTML: tSpin
@ -569,7 +557,7 @@ class Stats {
this.b2b = -1 this.b2b = -1
} }
this.goal -= awardedLineClears this.goal -= nbClearedLines
if (this.goal <= 0) this.level++ if (this.goal <= 0) this.level++
} }
} }
@ -593,16 +581,12 @@ let scheduler = new Scheduler()
let settings = new Settings() let settings = new Settings()
let stats = new Stats() let stats = new Stats()
let holdQueue = new MinoesTable("holdTable") let holdQueue = new MinoesTable("holdTable")
let matrix = new Matrix() let matrix = new PlayfieldMatrix("matrixTable")
let nextQueue = new NextQueue() let nextQueue = new NextQueue("nextTable")
let playing = false let playing = false
function init() {
} function pause() {
function pauseSettings() {
scheduler.clearInterval(fall) scheduler.clearInterval(fall)
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
scheduler.clearTimeout(repeat) scheduler.clearTimeout(repeat)
@ -612,11 +596,14 @@ function pauseSettings() {
document.onkeydown = null document.onkeydown = null
settings.show() resumeButton.disabled = false
settings.form.classList.remove('was-validated')
settings.modal.show()
settings.form.reportValidity()
} }
onblur = pauseSettings onblur = pause
pauseSettings() pause()
function newGame(event) { function newGame(event) {
if (!settings.form.checkValidity()) { if (!settings.form.checkValidity()) {
@ -643,20 +630,17 @@ function newGame(event) {
function resume(event) { function resume(event) {
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
settings.form.reportValidity() settings.form.reportValidity()
settings.form.classList.add('was-validated') settings.form.classList.add('was-validated')
if (settings.form.checkValidity()) { if (settings.form.checkValidity()) {
settings.load()
settings.modal.hide() settings.modal.hide()
settings.getInputs()
document.onkeydown = onkeydown document.onkeydown = onkeydown
document.onkeyup = onkeyup document.onkeyup = onkeyup
stats.time = stats.pauseTime stats.time = stats.pauseTime
scheduler.setInterval(ticktack, 1000) scheduler.setInterval(ticktack, 1000)
if (matrix.piece) scheduler.setInterval(fall, stats.fallPeriod) if (matrix.piece) scheduler.setInterval(fall, stats.fallPeriod)
else generate() else generate()
} }
@ -710,7 +694,7 @@ let playerActions = {
} }
}, },
pause: pauseSettings, pause: pause,
} }
// Handle player inputs // Handle player inputs
@ -840,7 +824,6 @@ window.onbeforeunload = function(event) {
if (playing) return false; if (playing) return false;
} }
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js'); navigator.serviceWorker.register('service-worker.js');
} }

View File

@ -7,9 +7,9 @@
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.4/font/bootstrap-icons.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.4/font/bootstrap-icons.css">
<link href="css/common.css" rel="stylesheet"> <link href="css/common.css" rel="stylesheet">
<link href="css/classic.css" rel="stylesheet" title="Classique"> <link href="css/99.css" rel="stylesheet" title="99">
<link href="css/electro.css" rel="alternate stylesheet" title="Électro"> <link href="css/effect.css" rel="alternate stylesheet" title="Effet">
<link href="css/new-wave.css" rel="alternate stylesheet" title="New Wave"> <link href="css/neon.css" rel="alternate stylesheet" title="Néon">
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png"> <link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png">