show ghost setting
This commit is contained in:
		@ -41,18 +41,18 @@ div {
 | 
				
			|||||||
    flex-wrap: wrap;
 | 
					    flex-wrap: wrap;
 | 
				
			||||||
    justify-content: center;
 | 
					    justify-content: center;
 | 
				
			||||||
    align-content: center;
 | 
					    align-content: center;
 | 
				
			||||||
    margin: 2vmin;
 | 
					    margin: 4vmin;
 | 
				
			||||||
    text-align: center;
 | 
					    text-align: center;
 | 
				
			||||||
    column-gap: 1vmin;
 | 
					    column-gap: 1vmin;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
div * {
 | 
					div * {
 | 
				
			||||||
    margin: auto 1vmin;
 | 
					    margin: auto 2vmin;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fieldset {
 | 
					fieldset {
 | 
				
			||||||
    display: grid;
 | 
					    display: grid;
 | 
				
			||||||
    grid-template-columns: 24vmin 18vmin 24vmin 18vmin;
 | 
					    grid-template-columns: 25vmin 17vmin 25vmin 17vmin;
 | 
				
			||||||
    grid-gap: 1vmin;
 | 
					    grid-gap: 1vmin;
 | 
				
			||||||
    margin: 2vmin auto;
 | 
					    margin: 2vmin auto;
 | 
				
			||||||
    width: 85vmin;
 | 
					    width: 85vmin;
 | 
				
			||||||
@ -243,8 +243,17 @@ th, td {
 | 
				
			|||||||
    display: none;
 | 
					    display: none;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#settings > label {
 | 
					#settings > * {
 | 
				
			||||||
    margin: auto auto auto 0;
 | 
					    margin: 2vmin auto;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#settings > div {
 | 
				
			||||||
 | 
					    justify-content: left;
 | 
				
			||||||
 | 
					    width: 85vmin;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#settings > div > * {
 | 
				
			||||||
 | 
					    margin: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#keyboard button {
 | 
					#keyboard button {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								index.php
									
									
									
									
									
								
							@ -1,16 +1,18 @@
 | 
				
			|||||||
<!DOCTYPE html>
 | 
					<!DOCTYPE html>
 | 
				
			||||||
<html>
 | 
					<html>
 | 
				
			||||||
<head>
 | 
					    <head>
 | 
				
			||||||
        <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 rel="stylesheet" type="text/css" href="css/style.css" />
 | 
					        <link rel="stylesheet" type="text/css" href="css/style.css" />
 | 
				
			||||||
        <script type="text/javascript" src="js/webtris.js"></script>
 | 
					        <script type="text/javascript" src="js/webtris.js"></script>
 | 
				
			||||||
</head>
 | 
					    </head>
 | 
				
			||||||
<body>
 | 
					    <body>
 | 
				
			||||||
 | 
					        <header>
 | 
				
			||||||
            <h1>WEBTRIS</h1>
 | 
					            <h1>WEBTRIS</h1>
 | 
				
			||||||
 | 
					        </header>
 | 
				
			||||||
        <div id="game">
 | 
					        <div id="game">
 | 
				
			||||||
<?php
 | 
					    <?php
 | 
				
			||||||
        function echoTable($id, $invisibleRows, $visibleRows, $columns) {
 | 
					        function echoTable($id, $invisibleRows, $visibleRows, $columns) {
 | 
				
			||||||
            echo "            <table id='$id' class=minoes-table>\n";
 | 
					            echo "            <table id='$id' class=minoes-table>\n";
 | 
				
			||||||
            for ($y = 0; $y < $invisibleRows; $y++) {
 | 
					            for ($y = 0; $y < $invisibleRows; $y++) {
 | 
				
			||||||
@ -32,7 +34,7 @@
 | 
				
			|||||||
        echoTable("hold",   6,  0,  6);
 | 
					        echoTable("hold",   6,  0,  6);
 | 
				
			||||||
        echoTable("matrix", 4, 20, 10);
 | 
					        echoTable("matrix", 4, 20, 10);
 | 
				
			||||||
        echoTable("next",  24,  0,  6);
 | 
					        echoTable("next",  24,  0,  6);
 | 
				
			||||||
?>
 | 
					    ?>
 | 
				
			||||||
            <table id="stats">
 | 
					            <table id="stats">
 | 
				
			||||||
                <tr><th class="name" colspan=2>SCORE</th></tr>
 | 
					                <tr><th class="name" colspan=2>SCORE</th></tr>
 | 
				
			||||||
                <tr><td class="value" id="score" colspan=2>0</td></tr>
 | 
					                <tr><td class="value" id="score" colspan=2>0</td></tr>
 | 
				
			||||||
@ -50,7 +52,7 @@
 | 
				
			|||||||
        <div id="settings">
 | 
					        <div id="settings">
 | 
				
			||||||
            <fieldset id="keyboard">
 | 
					            <fieldset id="keyboard">
 | 
				
			||||||
                <legend>Clavier</legend>
 | 
					                <legend>Clavier</legend>
 | 
				
			||||||
<?php
 | 
					    <?php
 | 
				
			||||||
        function addButton($action, $label) {
 | 
					        function addButton($action, $label) {
 | 
				
			||||||
            echo "                <label for='set-$action-key'>$label</label>\n";
 | 
					            echo "                <label for='set-$action-key'>$label</label>\n";
 | 
				
			||||||
            echo "                <button id='set-$action-key' type='button' onclick=\"waitKey(this, '$action')\"></button>";
 | 
					            echo "                <button id='set-$action-key' type='button' onclick=\"waitKey(this, '$action')\"></button>";
 | 
				
			||||||
@ -63,19 +65,23 @@
 | 
				
			|||||||
        addButton("rotateCCW", "Rotation anti-horaire");
 | 
					        addButton("rotateCCW", "Rotation anti-horaire");
 | 
				
			||||||
        addButton("hold", "Garde");
 | 
					        addButton("hold", "Garde");
 | 
				
			||||||
        addButton("pause", "Pause/Reprise");
 | 
					        addButton("pause", "Pause/Reprise");
 | 
				
			||||||
?>
 | 
					    ?>
 | 
				
			||||||
            </fieldset>
 | 
					            </fieldset>
 | 
				
			||||||
            <fieldset>
 | 
					            <fieldset>
 | 
				
			||||||
                <legend>Répétition automatique</legend>
 | 
					                <legend>Répétition automatique</legend>
 | 
				
			||||||
                <label id="autorepeatDelayRangeLabel" for="autorepeatDelayRange"></label>
 | 
					                <label id="autorepeatDelayRangeLabel" for="autorepeatDelayRange"></label>
 | 
				
			||||||
            <input id="autorepeatDelayRange" type="range" oninput="autorepeatDelayChanged()" min="100" max="1000" step="50">
 | 
					                <input id="autorepeatDelayRange" type="range" oninput="autorepeatDelayChanged()" min="100" max="1000" step="50" />
 | 
				
			||||||
                <label id="autorepeatPeriodRangeLabel" for="autorepeatPeriodRange"></label>
 | 
					                <label id="autorepeatPeriodRangeLabel" for="autorepeatPeriodRange"></label>
 | 
				
			||||||
            <input id="autorepeatPeriodRange" type="range" id="autorepeatPeriodRange" oninput="autorepeatPeriodChanged()" min="2" max="50" step="2">
 | 
					                <input id="autorepeatPeriodRange" type="range" id="autorepeatPeriodRange" oninput="autorepeatPeriodChanged()" min="2" max="50" step="2" />
 | 
				
			||||||
            </fieldset>
 | 
					            </fieldset>
 | 
				
			||||||
<!--        <fieldset>
 | 
					    <!--        <fieldset>
 | 
				
			||||||
                <legend>Thème</legend>
 | 
					                <legend>Thème</legend>
 | 
				
			||||||
                <div>À venir</div>
 | 
					                <div>À venir</div>
 | 
				
			||||||
            </fieldset> -->
 | 
					            </fieldset> -->
 | 
				
			||||||
 | 
					            <div>
 | 
				
			||||||
 | 
					                <input id="showGhostCheckbox" type="checkbox" checked onchange="showGhostChanged()"/>
 | 
				
			||||||
 | 
					                <label for="showGhostCheckbox">Afficher le fantôme</label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
            <button type="button" onclick="hideSettings()">RETOUR</button>
 | 
					            <button type="button" onclick="hideSettings()">RETOUR</button>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div id="start">
 | 
					        <div id="start">
 | 
				
			||||||
@ -89,5 +95,5 @@
 | 
				
			|||||||
        <div id="leaderboardLink">
 | 
					        <div id="leaderboardLink">
 | 
				
			||||||
            <a href="leaderboard.php" target="_blank">TABLEAU DE SCORE</a>
 | 
					            <a href="leaderboard.php" target="_blank">TABLEAU DE SCORE</a>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
</body>
 | 
					    </body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
@ -284,7 +284,7 @@ class Matrix extends MinoesTable {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            //ghost
 | 
					            //ghost
 | 
				
			||||||
            if (!this.piece.locked && state != STATE.GAME_OVER) {
 | 
					            if (showGhost && !this.piece.locked && state != STATE.GAME_OVER) {
 | 
				
			||||||
                for (var ghost = this.piece.ghost; this.spaceToMove(ghost.minoesAbsPos); ghost.pos.y++) {}
 | 
					                for (var ghost = this.piece.ghost; this.spaceToMove(ghost.minoesAbsPos); ghost.pos.y++) {}
 | 
				
			||||||
                ghost.pos.y--
 | 
					                ghost.pos.y--
 | 
				
			||||||
                this.drawPiece(ghost)
 | 
					                this.drawPiece(ghost)
 | 
				
			||||||
@ -419,24 +419,6 @@ function start() {
 | 
				
			|||||||
    newLevel(startLevel)
 | 
					    newLevel(startLevel)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function applySettings() {
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING] = {}
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("moveLeft")] = moveLeft
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("moveRight")] = moveRight
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("softDrop")] = softDrop
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("hardDrop")] = hardDrop
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("rotateCW")] = rotateCW
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("rotateCCW")] = rotateCCW
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("hold")] = hold
 | 
					 | 
				
			||||||
    actions[STATE.PLAYING][getKeyName("pause")] = pause
 | 
					 | 
				
			||||||
    actions[STATE.PAUSED] = {}
 | 
					 | 
				
			||||||
    actions[STATE.PAUSED][getKeyName("pause")] = resume
 | 
					 | 
				
			||||||
    actions[STATE.GAME_OVER] = {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    autorepeatDelay = localStorage.getItem("autorepeatDelay") || AUTOREPEAT_DELAY
 | 
					 | 
				
			||||||
    autorepeatPeriod = localStorage.getItem("autorepeatPeriod") || AUTOREPEAT_PERIOD
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function newLevel(startLevel) {
 | 
					function newLevel(startLevel) {
 | 
				
			||||||
    stats.newLevel(startLevel)
 | 
					    stats.newLevel(startLevel)
 | 
				
			||||||
    generationPhase()
 | 
					    generationPhase()
 | 
				
			||||||
@ -773,30 +755,56 @@ function getKeyName(action) {
 | 
				
			|||||||
    return localStorage.getItem(action) || actionsDefaultKeys[action]
 | 
					    return localStorage.getItem(action) || actionsDefaultKeys[action]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getKeyNameOrSpace(action) {
 | 
					// Settings functions
 | 
				
			||||||
    key = getKeyName(action)
 | 
					function applySettings() {
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING] = {}
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("moveLeft")] = moveLeft
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("moveRight")] = moveRight
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("softDrop")] = softDrop
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("hardDrop")] = hardDrop
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("rotateCW")] = rotateCW
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("rotateCCW")] = rotateCCW
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("hold")] = hold
 | 
				
			||||||
 | 
					    actions[STATE.PLAYING][getKeyName("pause")] = pause
 | 
				
			||||||
 | 
					    actions[STATE.PAUSED] = {}
 | 
				
			||||||
 | 
					    actions[STATE.PAUSED][getKeyName("pause")] = resume
 | 
				
			||||||
 | 
					    actions[STATE.GAME_OVER] = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    autorepeatDelay = localStorage.getItem("autorepeatDelay") || AUTOREPEAT_DELAY
 | 
				
			||||||
 | 
					    autorepeatPeriod = localStorage.getItem("autorepeatPeriod") || AUTOREPEAT_PERIOD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    showGhost = localStorage.getItem("showGhost")
 | 
				
			||||||
 | 
					    if (showGhost)
 | 
				
			||||||
 | 
					        showGhost = (showGhost == "true")
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    showGhost = true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function replaceSpace(key) {
 | 
				
			||||||
    return (key == " ") ? "Space" : key
 | 
					    return (key == " ") ? "Space" : key
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Settings functions
 | 
					 | 
				
			||||||
function showSettings() {
 | 
					function showSettings() {
 | 
				
			||||||
    document.getElementById("set-moveLeft-key").innerHTML = getKeyNameOrSpace("moveLeft")
 | 
					 | 
				
			||||||
    document.getElementById("set-moveRight-key").innerHTML = getKeyNameOrSpace("moveRight")
 | 
					 | 
				
			||||||
    document.getElementById("set-softDrop-key").innerHTML = getKeyNameOrSpace("softDrop")
 | 
					 | 
				
			||||||
    document.getElementById("set-hardDrop-key").innerHTML = getKeyNameOrSpace("hardDrop")
 | 
					 | 
				
			||||||
    document.getElementById("set-rotateCW-key").innerHTML = getKeyNameOrSpace("rotateCW")
 | 
					 | 
				
			||||||
    document.getElementById("set-rotateCCW-key").innerHTML = getKeyNameOrSpace("rotateCCW")
 | 
					 | 
				
			||||||
    document.getElementById("set-hold-key").innerHTML = getKeyNameOrSpace("hold")
 | 
					 | 
				
			||||||
    document.getElementById("set-pause-key").innerHTML = getKeyNameOrSpace("pause")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    document.getElementById("autorepeatDelayRange").value = localStorage.getItem("autorepeatDelay") || AUTOREPEAT_DELAY
 | 
					 | 
				
			||||||
    document.getElementById("autorepeatDelayRangeLabel").innerText = `Délai : ${autorepeatDelay}ms`
 | 
					 | 
				
			||||||
    document.getElementById("autorepeatPeriodRange").value = localStorage.getItem("autorepeatPeriod") || AUTOREPEAT_PERIOD
 | 
					 | 
				
			||||||
    document.getElementById("autorepeatPeriodRangeLabel").innerText = `Période : ${autorepeatPeriod}ms`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (state == STATE.PLAYING)
 | 
					    if (state == STATE.PLAYING)
 | 
				
			||||||
        pause()
 | 
					        pause()
 | 
				
			||||||
    document.getElementById("settings").style.display = "flex"
 | 
					
 | 
				
			||||||
 | 
					    document.getElementById("set-moveLeft-key").innerHTML = replaceSpace(getKeyName("moveLeft"))
 | 
				
			||||||
 | 
					    document.getElementById("set-moveRight-key").innerHTML = replaceSpace(getKeyName("moveRight"))
 | 
				
			||||||
 | 
					    document.getElementById("set-softDrop-key").innerHTML = replaceSpace(getKeyName("softDrop"))
 | 
				
			||||||
 | 
					    document.getElementById("set-hardDrop-key").innerHTML = replaceSpace(getKeyName("hardDrop"))
 | 
				
			||||||
 | 
					    document.getElementById("set-rotateCW-key").innerHTML = replaceSpace(getKeyName("rotateCW"))
 | 
				
			||||||
 | 
					    document.getElementById("set-rotateCCW-key").innerHTML = replaceSpace(getKeyName("rotateCCW"))
 | 
				
			||||||
 | 
					    document.getElementById("set-hold-key").innerHTML = replaceSpace(getKeyName("hold"))
 | 
				
			||||||
 | 
					    document.getElementById("set-pause-key").innerHTML = replaceSpace(getKeyName("pause"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    document.getElementById("autorepeatDelayRange").value = autorepeatDelay
 | 
				
			||||||
 | 
					    document.getElementById("autorepeatDelayRangeLabel").innerText = `Délai : ${autorepeatDelay}ms`
 | 
				
			||||||
 | 
					    document.getElementById("autorepeatPeriodRange").value = autorepeatPeriod
 | 
				
			||||||
 | 
					    document.getElementById("autorepeatPeriodRangeLabel").innerText = `Période : ${autorepeatPeriod}ms`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    document.getElementById("showGhostCheckbox").checked = showGhost
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    document.getElementById("settings").style.display = "block"
 | 
				
			||||||
    document.getElementById("game").style.display = "none"
 | 
					    document.getElementById("game").style.display = "none"
 | 
				
			||||||
    document.getElementById("start").style.display = "none"
 | 
					    document.getElementById("start").style.display = "none"
 | 
				
			||||||
    document.getElementById("leaderboardLink").style.display = "none"
 | 
					    document.getElementById("leaderboardLink").style.display = "none"
 | 
				
			||||||
@ -854,7 +862,12 @@ function autorepeatPeriodChanged() {
 | 
				
			|||||||
    document.getElementById("autorepeatPeriodRangeLabel").innerText = `Période : ${autorepeatPeriod}ms`
 | 
					    document.getElementById("autorepeatPeriodRangeLabel").innerText = `Période : ${autorepeatPeriod}ms`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//global variables
 | 
					function showGhostChanged() {
 | 
				
			||||||
 | 
					    showGhost = (document.getElementById("showGhostCheckbox").checked == true)
 | 
				
			||||||
 | 
					    localStorage.setItem("showGhost", showGhost)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// global variables
 | 
				
			||||||
timeFormat = new Intl.DateTimeFormat("fr-FR", {
 | 
					timeFormat = new Intl.DateTimeFormat("fr-FR", {
 | 
				
			||||||
    minute: "2-digit",
 | 
					    minute: "2-digit",
 | 
				
			||||||
    second: "2-digit",
 | 
					    second: "2-digit",
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user