From bfe422bbdd7df14786638b63c37c8e142102f448 Mon Sep 17 00:00:00 2001 From: Adrien MALINGREY <adrien@malingrey.fr> Date: Thu, 31 Oct 2019 08:24:02 +0100 Subject: [PATCH] php --- css/style.css | 8 ++++++-- index.php | 4 ++-- js/webtris.js | 22 ++++++++-------------- webtris.html => webtris.php | 21 ++++++++++++++++++--- 4 files changed, 34 insertions(+), 21 deletions(-) rename webtris.html => webtris.php (68%) diff --git a/css/style.css b/css/style.css index b298f40..bcc8b64 100644 --- a/css/style.css +++ b/css/style.css @@ -81,10 +81,14 @@ table { table-layout: fixed; border-spacing: 0; width: 0; + height: 0; } td { border: 1px solid transparent; + padding: 0; + width: 20px; + height: 20px; } #hold { @@ -171,8 +175,8 @@ td { .ghost { background-color: rgba(255, 255, 255, 0.4); - border-color: rgba(255, 255, 255, 0.3); - border-style: inset; + border-color: rgba(255, 255, 255, 0.2); + border-style: solid; } #stats { diff --git a/index.php b/index.php index 6c4a57a..ad566a8 100644 --- a/index.php +++ b/index.php @@ -14,7 +14,7 @@ function addButton($action, $label) { ?> <div><?=$label?></div> - <button type='button' onclick='changeKey(this, "<?=$action?>")'> + <button type="button" onclick="changeKey(this, '<?=$action?>')"> <script>getKey("<?=$action?>")</script> </button> <?php } @@ -29,7 +29,7 @@ ?> </div> <div id="play"> - <a href="webtris.html">JOUER</a> + <a href="webtris.php">JOUER</a> </div> </body> </html> \ No newline at end of file diff --git a/js/webtris.js b/js/webtris.js index 9858e4a..238d74f 100644 --- a/js/webtris.js +++ b/js/webtris.js @@ -206,12 +206,6 @@ class MinoesTable { this.columns = columns this.piece = null this.table = document.getElementById(id) - for (var y=0; y < rows; y++) { - var row = this.table.insertRow() - for (var x=0; x < columns; x++) { - row.insertCell() - } - } } drawMino(x, y, className) { @@ -224,8 +218,8 @@ class MinoesTable { } clearTable() { - for(var y=0; y < this.rows; y++) { - for (var x=0; x < this.columns; x++) { + for(var y = 0; y < this.rows; y++) { + for (var x = 0; x < this.columns; x++) { this.drawMino(x, y, INVISIBLE_ROW_CLASS) } } @@ -268,8 +262,8 @@ class Matrix extends MinoesTable { draw() { // grid if (state == STATE.PAUSED) { - for (var y=0; y < this.rows; y++) { - for (var x=0; x < this.columns; x++) { + for (var y = 0; y < this.rows; y++) { + for (var x = 0; x < this.columns; x++) { if (this.clearedLines.includes(y)) var className = CLEARED_LINE_CLASS else { if (y < MATRIX_INVISIBLE_ROWS) var className = INVISIBLE_ROW_CLASS @@ -279,8 +273,8 @@ class Matrix extends MinoesTable { } } } else { - for (var y=0; y < this.rows; y++) { - for (var x=0; x < this.columns; x++) { + for (var y = 0; y < this.rows; y++) { + for (var x = 0; x < this.columns; x++) { var className = this.lockedMinoes[y][x] if (!className) { if (this.clearedLines.includes(y)) className = CLEARED_LINE_CLASS @@ -296,7 +290,7 @@ class Matrix extends MinoesTable { // trail if (this.trail.height) { this.trail.minoesPos.forEach(pos => { - for (var dy=0; dy < this.trail.height; dy++) this.drawMino(pos[0], pos[1]+dy, TRAIL_CLASS) + for (var dy = 0; dy < this.trail.height; dy++) this.drawMino(pos[0], pos[1]+dy, TRAIL_CLASS) }) } @@ -618,7 +612,7 @@ function hardDrop() { scheduler.clearInterval(lockPhase) scheduler.clearTimeout(lockDown) matrix.trail.minoesPos = Array.from(matrix.piece.minoesAbsPos) - for (matrix.trail.height=0; move(MOVEMENT.DOWN); matrix.trail.height++) { + for (matrix.trail.height = 0; move(MOVEMENT.DOWN); matrix.trail.height++) { stats.score += 2 } while (move(MOVEMENT.DOWN)) {} diff --git a/webtris.html b/webtris.php similarity index 68% rename from webtris.html rename to webtris.php index 74ee857..67b6c5f 100644 --- a/webtris.html +++ b/webtris.php @@ -10,9 +10,24 @@ <body> <h1>WEBTRIS</h1> <div id="grid"> - <table id="hold"><table> - <table id="matrix"><table> - <table id="next"><table> +<?php + function echoTable($id, $rows, $columns) { + echo " <table id='$id'>\n"; + echo " <tbody>\n"; + for ($y = 0; $y < $rows; $y++) { + echo " <tr>"; + for ($x = 0; $x < $columns; $x++) { + echo "<td></td>"; + } + echo "</tr>\n"; + } + echo " </tbody>\n"; + echo " </table>\n"; + } + echoTable("hold", 6, 6); + echoTable("matrix", 24, 10); + echoTable("next", 24, 6); +?> <table id="stats"> <tbody> <tr><td class="stat-label">SCORE</td><td class="stat-value" id="score">0</td></tr>