v2
This commit is contained in:
		| @ -29,12 +29,12 @@ const THEME = { | ||||
|     PIECE_POSITION: [1, 1] | ||||
| } | ||||
| const CLASSNAME = { | ||||
|     EMPTY_CELL: "empty-cell", | ||||
|     EMPTY_CELL: "", | ||||
|     MINO: "mino", | ||||
|     LOCKED: "locked-mino", | ||||
|     TRAIL: "trail", | ||||
|     LOCKED: "locked", | ||||
|     TRAIL: "mino trail", | ||||
|     GHOST: "ghost", | ||||
|     CLEARED_LINE: "mino cleared-line" | ||||
|     CLEARED_LINE: "cleared-line" | ||||
| } | ||||
| const DELAY = { | ||||
|     LOCK: 500, | ||||
| @ -97,6 +97,8 @@ const actionsDefaultKeys = { | ||||
| const RETRIES = 3 | ||||
| const DEFAULT_THEME = "light-relief" | ||||
| 
 | ||||
| var theme = null | ||||
| 
 | ||||
| 
 | ||||
| // Classes
 | ||||
| class Scheduler { | ||||
| @ -246,7 +248,7 @@ class HoldQueue extends MinoesTable { | ||||
| 
 | ||||
|     draw() { | ||||
|         this.clearTable() | ||||
|         if (this.piece && state != STATE.PAUSED) | ||||
|         if (this.piece) | ||||
|             this.drawPiece(this.piece) | ||||
|     } | ||||
| } | ||||
| @ -277,9 +279,6 @@ class Matrix extends MinoesTable { | ||||
|      | ||||
|     draw() { | ||||
|         // grid
 | ||||
|         if (state == STATE.PAUSED) { | ||||
|             this.clearTable() | ||||
|         } else { | ||||
|         for (var y = 0; y < this.rows; y++) { | ||||
|             for (var x = 0; x < this.columns; x++) { | ||||
|                 if (this.clearedLines.includes(y)) | ||||
| @ -291,7 +290,7 @@ class Matrix extends MinoesTable { | ||||
|         } | ||||
|          | ||||
|         // ghost
 | ||||
|             if (showGhost && !this.piece.locked && state != STATE.GAME_OVER) { | ||||
|         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) | ||||
| @ -303,12 +302,10 @@ class Matrix extends MinoesTable { | ||||
|         if (this.trail.height) { | ||||
|             this.trail.minoesPos.forEach(pos => { | ||||
|                 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) | ||||
|             }) | ||||
|         } | ||||
|     } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -323,18 +320,8 @@ class NextQueue extends MinoesTable { | ||||
| 
 | ||||
|     draw() { | ||||
|         this.clearTable() | ||||
|         if (state != STATE.PAUSED) { | ||||
|         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" | ||||
|     gameSection.style.display = "block" | ||||
|     settingsSection.style.display = "none" | ||||
|     leaderboardLinkSection.style.display = "none" | ||||
| 
 | ||||
|     state = STATE.PLAYING | ||||
|     pressedKeys = new Set() | ||||
| @ -611,8 +597,7 @@ function gameOver() { | ||||
|                 } | ||||
|                 request.open('POST', 'publish.php') | ||||
|                 request.send(fd) | ||||
|             } | ||||
|         } else { | ||||
|             } else | ||||
|             alert(info) | ||||
|         } | ||||
|     } | ||||
| @ -632,7 +617,6 @@ function gameOver() { | ||||
|     startSection.style.display = "block" | ||||
|     gameSection.style.display = "block" | ||||
|     settingsSection.style.display = "none" | ||||
|     leaderboardLinkSection.style.display = "block" | ||||
| } | ||||
| 
 | ||||
| function autorepeat() { | ||||
| @ -848,29 +832,8 @@ function loadSettings() { | ||||
|     autorepeatPeriodRangeLabel.innerText = `Période : ${autorepeatPeriod}ms` | ||||
| 
 | ||||
|     themeSelect.value=themeName; | ||||
|     themePreview.drawPiece(themePreview.piece) | ||||
| 
 | ||||
|     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) { | ||||
| @ -907,14 +870,13 @@ function themeChanged() { | ||||
| } | ||||
| 
 | ||||
| function loadTheme() { | ||||
|     theme = document.getElementById("theme") | ||||
|     if (theme) document.head.removeChild(theme) | ||||
|     var link  = document.createElement('link') | ||||
|     link.id   = "theme"; | ||||
|     link.rel  = 'stylesheet' | ||||
|     link.type = 'text/css' | ||||
|     link.href = 'themes/' + themeName+ '/style.css' | ||||
|     link.media = 'all' | ||||
|     if (theme) document.head.removeChild(theme) | ||||
|     document.head.appendChild(link); | ||||
| } | ||||
| 
 | ||||
| @ -945,7 +907,6 @@ window.onload = function() { | ||||
|     stats = new Stats() | ||||
|     matrix = new Matrix() | ||||
|     nextQueue = new NextQueue() | ||||
|     themePreview = new ThemePreview() | ||||
|      | ||||
|     applySettings() | ||||
|     loadSettings() | ||||
							
								
								
									
										127
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										127
									
								
								index.php
									
									
									
									
									
								
							| @ -15,7 +15,7 @@ | ||||
|         for ($y = 0; $y < $invisibleRows; $y++) { | ||||
|             echo "                    <tr>"; | ||||
|             for ($x = 0; $x < $columns; $x++) { | ||||
|                 echo "<th class=empty-cell></td>"; | ||||
|                 echo "<th></td>"; | ||||
|             } | ||||
|             echo "</tr>\n"; | ||||
|         } | ||||
| @ -35,44 +35,11 @@ | ||||
|         <meta charset="utf-8" /> | ||||
|         <title>Webtris</title> | ||||
|         <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="webtris.js"></script> | ||||
|         <script type="text/javascript" src="app.js"></script> | ||||
|     </head> | ||||
|     <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"> | ||||
|             <h1>WEBTRIS</h1> | ||||
|             <fieldset> | ||||
|                 <legend>Clavier</legend> | ||||
|                 <div> | ||||
| @ -107,20 +74,98 @@ | ||||
|     } | ||||
| ?> | ||||
|                     </select> | ||||
| <?php | ||||
|     echoTable("themePreviewTable",   2,  0,  3); | ||||
| ?> | ||||
|                     <div> | ||||
|                     <table id="themePreviewTable" class=minoes-table> | ||||
|                         <tr> | ||||
|                             <th class="mino I"></th> | ||||
|                             <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()"/> | ||||
|                         <label for="showGhostCheckbox">Afficher le fantôme</label> | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </fieldset> | ||||
|         </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> | ||||
|                 <a href="leaderboard.php" target="_blank">TABLEAU DE SCORE</a> | ||||
|             </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> | ||||
|     </body> | ||||
| </html> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user