show ghost setting
This commit is contained in:
parent
ae39fda660
commit
a9c364be55
@ -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 {
|
||||||
|
10
index.php
10
index.php
@ -8,7 +8,9 @@
|
|||||||
<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) {
|
||||||
@ -68,14 +70,18 @@
|
|||||||
<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">
|
||||||
|
@ -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,6 +862,11 @@ function autorepeatPeriodChanged() {
|
|||||||
document.getElementById("autorepeatPeriodRangeLabel").innerText = `Période : ${autorepeatPeriod}ms`
|
document.getElementById("autorepeatPeriodRangeLabel").innerText = `Période : ${autorepeatPeriod}ms`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showGhostChanged() {
|
||||||
|
showGhost = (document.getElementById("showGhostCheckbox").checked == true)
|
||||||
|
localStorage.setItem("showGhost", showGhost)
|
||||||
|
}
|
||||||
|
|
||||||
// global variables
|
// global variables
|
||||||
timeFormat = new Intl.DateTimeFormat("fr-FR", {
|
timeFormat = new Intl.DateTimeFormat("fr-FR", {
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
|
Reference in New Issue
Block a user