v2
This commit is contained in:
parent
0f1093541e
commit
5d7795b3da
@ -29,12 +29,12 @@ const THEME = {
|
|||||||
PIECE_POSITION: [1, 1]
|
PIECE_POSITION: [1, 1]
|
||||||
}
|
}
|
||||||
const CLASSNAME = {
|
const CLASSNAME = {
|
||||||
EMPTY_CELL: "empty-cell",
|
EMPTY_CELL: "",
|
||||||
MINO: "mino",
|
MINO: "mino",
|
||||||
LOCKED: "locked-mino",
|
LOCKED: "locked",
|
||||||
TRAIL: "trail",
|
TRAIL: "mino trail",
|
||||||
GHOST: "ghost",
|
GHOST: "ghost",
|
||||||
CLEARED_LINE: "mino cleared-line"
|
CLEARED_LINE: "cleared-line"
|
||||||
}
|
}
|
||||||
const DELAY = {
|
const DELAY = {
|
||||||
LOCK: 500,
|
LOCK: 500,
|
||||||
@ -97,6 +97,8 @@ const actionsDefaultKeys = {
|
|||||||
const RETRIES = 3
|
const RETRIES = 3
|
||||||
const DEFAULT_THEME = "light-relief"
|
const DEFAULT_THEME = "light-relief"
|
||||||
|
|
||||||
|
var theme = null
|
||||||
|
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
class Scheduler {
|
class Scheduler {
|
||||||
@ -246,7 +248,7 @@ class HoldQueue extends MinoesTable {
|
|||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
this.clearTable()
|
this.clearTable()
|
||||||
if (this.piece && state != STATE.PAUSED)
|
if (this.piece)
|
||||||
this.drawPiece(this.piece)
|
this.drawPiece(this.piece)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,36 +279,31 @@ class Matrix extends MinoesTable {
|
|||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
// grid
|
// grid
|
||||||
if (state == STATE.PAUSED) {
|
for (var y = 0; y < this.rows; y++) {
|
||||||
this.clearTable()
|
for (var x = 0; x < this.columns; x++) {
|
||||||
} else {
|
if (this.clearedLines.includes(y))
|
||||||
for (var y = 0; y < this.rows; y++) {
|
var className = CLASSNAME.CLEARED_LINE
|
||||||
for (var x = 0; x < this.columns; x++) {
|
else
|
||||||
if (this.clearedLines.includes(y))
|
var className = this.lockedMinoes[y][x] || CLASSNAME.EMPTY_CELL
|
||||||
var className = CLASSNAME.CLEARED_LINE
|
this.drawMino(x, y, className)
|
||||||
else
|
|
||||||
var className = this.lockedMinoes[y][x] || CLASSNAME.EMPTY_CELL
|
|
||||||
this.drawMino(x, y, className)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ghost
|
|
||||||
if (showGhost && !this.piece.locked && state != STATE.GAME_OVER) {
|
|
||||||
for (var ghost = this.piece.ghost; this.spaceToMove(ghost.minoesAbsPos); ghost.pos.y++) {}
|
|
||||||
ghost.pos.y--
|
|
||||||
this.drawPiece(ghost)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ghost
|
||||||
|
if (showGhostCheckbox.value && !this.piece.locked && state != STATE.GAME_OVER) {
|
||||||
|
for (var ghost = this.piece.ghost; this.spaceToMove(ghost.minoesAbsPos); ghost.pos.y++) {}
|
||||||
|
ghost.pos.y--
|
||||||
|
this.drawPiece(ghost)
|
||||||
|
}
|
||||||
|
|
||||||
this.drawPiece(this.piece)
|
this.drawPiece(this.piece)
|
||||||
|
|
||||||
// trail
|
// trail
|
||||||
if (this.trail.height) {
|
if (this.trail.height) {
|
||||||
this.trail.minoesPos.forEach(pos => {
|
this.trail.minoesPos.forEach(pos => {
|
||||||
for (var y = pos.y; y < pos.y + this.trail.height; y++)
|
for (var y = pos.y; y < pos.y + this.trail.height; y++)
|
||||||
if (this.table.rows[y].cells[pos.x].className == CLASSNAME.EMPTY_CELL)
|
this.drawMino(pos.x, y, CLASSNAME.TRAIL)
|
||||||
this.drawMino(pos.x, y, CLASSNAME.TRAIL)
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,17 +320,7 @@ class NextQueue extends MinoesTable {
|
|||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
this.clearTable()
|
this.clearTable()
|
||||||
if (state != STATE.PAUSED) {
|
this.pieces.forEach(piece => this.drawPiece(piece))
|
||||||
this.pieces.forEach(piece => this.drawPiece(piece))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ThemePreview extends MinoesTable {
|
|
||||||
constructor() {
|
|
||||||
super("themePreviewTable")
|
|
||||||
this.piece = new Tetromino(THEME.PIECE_POSITION, "T")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +427,6 @@ function newGame(startLevel) {
|
|||||||
startSection.style.display = "none"
|
startSection.style.display = "none"
|
||||||
gameSection.style.display = "block"
|
gameSection.style.display = "block"
|
||||||
settingsSection.style.display = "none"
|
settingsSection.style.display = "none"
|
||||||
leaderboardLinkSection.style.display = "none"
|
|
||||||
|
|
||||||
state = STATE.PLAYING
|
state = STATE.PLAYING
|
||||||
pressedKeys = new Set()
|
pressedKeys = new Set()
|
||||||
@ -611,8 +597,7 @@ function gameOver() {
|
|||||||
}
|
}
|
||||||
request.open('POST', 'publish.php')
|
request.open('POST', 'publish.php')
|
||||||
request.send(fd)
|
request.send(fd)
|
||||||
}
|
} else
|
||||||
} else {
|
|
||||||
alert(info)
|
alert(info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -632,7 +617,6 @@ function gameOver() {
|
|||||||
startSection.style.display = "block"
|
startSection.style.display = "block"
|
||||||
gameSection.style.display = "block"
|
gameSection.style.display = "block"
|
||||||
settingsSection.style.display = "none"
|
settingsSection.style.display = "none"
|
||||||
leaderboardLinkSection.style.display = "block"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function autorepeat() {
|
function autorepeat() {
|
||||||
@ -848,29 +832,8 @@ function loadSettings() {
|
|||||||
autorepeatPeriodRangeLabel.innerText = `Période : ${autorepeatPeriod}ms`
|
autorepeatPeriodRangeLabel.innerText = `Période : ${autorepeatPeriod}ms`
|
||||||
|
|
||||||
themeSelect.value=themeName;
|
themeSelect.value=themeName;
|
||||||
themePreview.drawPiece(themePreview.piece)
|
|
||||||
|
|
||||||
showGhostCheckbox.checked = showGhost
|
showGhostCheckbox.checked = showGhost
|
||||||
|
|
||||||
/*startSection.style.display = "grid"
|
|
||||||
gameSection.style.display = "grid"
|
|
||||||
settingsSection.style.display = "block"
|
|
||||||
settingsButtonSection.style.display = "flex"
|
|
||||||
|
|
||||||
switch(state) {
|
|
||||||
case STATE.WAITING:
|
|
||||||
document.getElementById("start").style.display = "block"
|
|
||||||
document.getElementById("hideSettingsButton").style.display = "none"
|
|
||||||
break
|
|
||||||
case STATE.GAME_OVER:
|
|
||||||
document.getElementById("start").style.display = "block"
|
|
||||||
document.getElementById("hideSettingsButton").style.display = "flex"
|
|
||||||
break
|
|
||||||
case STATE.PAUSED:
|
|
||||||
document.getElementById("start").style.display = "none"
|
|
||||||
document.getElementById("hideSettingsButton").style.display = "flex"
|
|
||||||
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitKey(button, action) {
|
function waitKey(button, action) {
|
||||||
@ -907,14 +870,13 @@ function themeChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadTheme() {
|
function loadTheme() {
|
||||||
theme = document.getElementById("theme")
|
|
||||||
if (theme) document.head.removeChild(theme)
|
|
||||||
var link = document.createElement('link')
|
var link = document.createElement('link')
|
||||||
link.id = "theme";
|
link.id = "theme";
|
||||||
link.rel = 'stylesheet'
|
link.rel = 'stylesheet'
|
||||||
link.type = 'text/css'
|
link.type = 'text/css'
|
||||||
link.href = 'themes/' + themeName+ '/style.css'
|
link.href = 'themes/' + themeName+ '/style.css'
|
||||||
link.media = 'all'
|
link.media = 'all'
|
||||||
|
if (theme) document.head.removeChild(theme)
|
||||||
document.head.appendChild(link);
|
document.head.appendChild(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,7 +907,6 @@ window.onload = function() {
|
|||||||
stats = new Stats()
|
stats = new Stats()
|
||||||
matrix = new Matrix()
|
matrix = new Matrix()
|
||||||
nextQueue = new NextQueue()
|
nextQueue = new NextQueue()
|
||||||
themePreview = new ThemePreview()
|
|
||||||
|
|
||||||
applySettings()
|
applySettings()
|
||||||
loadSettings()
|
loadSettings()
|
127
index.php
127
index.php
@ -15,7 +15,7 @@
|
|||||||
for ($y = 0; $y < $invisibleRows; $y++) {
|
for ($y = 0; $y < $invisibleRows; $y++) {
|
||||||
echo " <tr>";
|
echo " <tr>";
|
||||||
for ($x = 0; $x < $columns; $x++) {
|
for ($x = 0; $x < $columns; $x++) {
|
||||||
echo "<th class=empty-cell></td>";
|
echo "<th></td>";
|
||||||
}
|
}
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
}
|
}
|
||||||
@ -35,44 +35,11 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Webtris</title>
|
<title>Webtris</title>
|
||||||
<link rel="icon" type="image/png" href="favicon.png">
|
<link rel="icon" type="image/png" href="favicon.png">
|
||||||
<link id="theme" rel="stylesheet" type="text/css" href="themes/default/style.css" />
|
<script type="text/javascript" src="app.js"></script>
|
||||||
<script type="text/javascript" src="webtris.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<section id="gameSection" style="display: none">
|
|
||||||
<div>
|
|
||||||
<?php
|
|
||||||
echoTable("holdTable", 6, 0, 6);
|
|
||||||
echoTable("matrixTable", 4, 20, 10);
|
|
||||||
echoTable("nextTable", 24, 0, 6);
|
|
||||||
?>
|
|
||||||
<table id="statsTable">
|
|
||||||
<tr><th class="name" colspan=2>SCORE</th></tr>
|
|
||||||
<tr><td class="value" id="score" colspan=2>0</td></tr>
|
|
||||||
<tr><th class="name" colspan=2>RECORD</th></tr>
|
|
||||||
<tr><td class="value" id="highScore" colspan=2>0</td></tr>
|
|
||||||
<tr><th class="name" colspan=2>TEMPS</th></tr>
|
|
||||||
<tr><td class="value" id="time" colspan=2>00:00</td></tr>
|
|
||||||
<tr><td colspan=2><br/></td class="name"></tr>
|
|
||||||
<tr><th class="name">NIVEAU</th><td class="value" id="level">0</td></tr>
|
|
||||||
<tr><th class="name">OBJECTIF</th><td class="value" id="goal">0</td></tr>
|
|
||||||
<tr><th class="name">LIGNES</th><td class="value" id="clearedLines">0</td></tr>
|
|
||||||
</table>
|
|
||||||
<span id="messageSpan"></span>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section id="startSection">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Nouvelle partie</legend>
|
|
||||||
<div>
|
|
||||||
<div></div>
|
|
||||||
<button id="startButton" type="button" onclick="newGame(Number(startLevelInput.value))" disabled>JOUER</button>
|
|
||||||
<label for="startLevel">Niveau</label>
|
|
||||||
<input type="number" id="startLevelInput" min="1" max="15" step="1">
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
</section>
|
|
||||||
<section id="settingsSection">
|
<section id="settingsSection">
|
||||||
|
<h1>WEBTRIS</h1>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Clavier</legend>
|
<legend>Clavier</legend>
|
||||||
<div>
|
<div>
|
||||||
@ -107,20 +74,98 @@
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
<?php
|
<table id="themePreviewTable" class=minoes-table>
|
||||||
echoTable("themePreviewTable", 2, 0, 3);
|
<tr>
|
||||||
?>
|
<th class="mino I"></th>
|
||||||
<div>
|
<th></th>
|
||||||
|
<th class="mino J"></th>
|
||||||
|
<th class="mino J"></th>
|
||||||
|
<th class="mino J"></th>
|
||||||
|
<th></th>
|
||||||
|
<th class="mino S"></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th class="mino I"></th>
|
||||||
|
<th class="mino O"></th>
|
||||||
|
<th class="mino O"></th>
|
||||||
|
<th></th>
|
||||||
|
<th class="mino J"></th>
|
||||||
|
<th class="mino Z"></th>
|
||||||
|
<th class="mino S"></th>
|
||||||
|
<th class="mino S"></th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th class="mino I"></th>
|
||||||
|
<th class="mino O"></th>
|
||||||
|
<th class="mino O"></th>
|
||||||
|
<th class="mino L"></th>
|
||||||
|
<th class="mino Z"></th>
|
||||||
|
<th class="mino Z"></th>
|
||||||
|
<th class="mino T"></th>
|
||||||
|
<th class="mino S"></th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th class="mino I"></th>
|
||||||
|
<th class="mino L"></th>
|
||||||
|
<th class="mino L"></th>
|
||||||
|
<th class="mino L"></th>
|
||||||
|
<th class="mino Z"></th>
|
||||||
|
<th class="mino T"></th>
|
||||||
|
<th class="mino T"></th>
|
||||||
|
<th class="mino T"></th>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div id="showGhostDiv">
|
||||||
<input id="showGhostCheckbox" type="checkbox" checked onchange="showGhostChanged()"/>
|
<input id="showGhostCheckbox" type="checkbox" checked onchange="showGhostChanged()"/>
|
||||||
<label for="showGhostCheckbox">Afficher le fantôme</label>
|
<label for="showGhostCheckbox">Afficher le fantôme</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</section>
|
</section>
|
||||||
<section id="leaderboardLinkSection">
|
<section id="gameSection" style="display: none">
|
||||||
|
<div>
|
||||||
|
<?php
|
||||||
|
echoTable("holdTable", 6, 0, 6);
|
||||||
|
echoTable("matrixTable", 4, 20, 10);
|
||||||
|
echoTable("nextTable", 24, 0, 6);
|
||||||
|
?>
|
||||||
|
<table id="statsTable">
|
||||||
|
<tr><th colspan=2>SCORE</th></tr>
|
||||||
|
<tr><td id="score" colspan=2>0</td></tr>
|
||||||
|
<tr><th colspan=2>RECORD</th></tr>
|
||||||
|
<tr><td id="highScore" colspan=2>0</td></tr>
|
||||||
|
<tr><th colspan=2>TEMPS</th></tr>
|
||||||
|
<tr><td id="time" colspan=2>00:00</td></tr>
|
||||||
|
<tr><td colspan=2><br/></td></tr>
|
||||||
|
<tr><th>NIVEAU</th><td id="level">0</td></tr>
|
||||||
|
<tr><th>OBJECTIF</th><td id="goal">0</td></tr>
|
||||||
|
<tr><th>LIGNES</th><td id="clearedLines">0</td></tr>
|
||||||
|
</table>
|
||||||
|
<span id="messageSpan"></span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section id="startSection">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Nouvelle partie</legend>
|
||||||
|
<div>
|
||||||
|
<label for="startLevel">Niveau</label>
|
||||||
|
<input type="number" id="startLevelInput" min="1" max="15" step="1" value="1">
|
||||||
|
<div></div>
|
||||||
|
<button id="startButton" type="button" onclick="newGame(Number(startLevelInput.value))" disabled>JOUER</button>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</section>
|
||||||
|
<footer id="footer">
|
||||||
<div>
|
<div>
|
||||||
<a href="leaderboard.php" target="_blank">TABLEAU DE SCORE</a>
|
<a href="leaderboard.php" target="_blank">TABLEAU DE SCORE</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="credits">
|
||||||
|
Sources d'inspiration des thèmes :
|
||||||
|
<a href="https://github.com/kubowania/Tetris">Ania Kubow</a>
|
||||||
|
<a href="https://manjaro.org/">Manjaro</a>
|
||||||
|
<a href="https://www.tetriseffect.game/">Tetris Effect</a>
|
||||||
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user