start game leval at location hash
This commit is contained in:
parent
3fccefc57c
commit
1d1b2b24d2
@ -106,9 +106,9 @@
|
|||||||
<legend>Nouvelle partie</legend>
|
<legend>Nouvelle partie</legend>
|
||||||
<div>
|
<div>
|
||||||
<label for="startLevel">Niveau</label>
|
<label for="startLevel">Niveau</label>
|
||||||
<input type="number" id="startLevel" min="1" max="15" step="1">
|
<input type="number" id="startLevelInput" min="1" max="15" step="1">
|
||||||
<div></div>
|
<div></div>
|
||||||
<button id="startButton" type="button" onclick="newGame()" disabled>JOUER</button>
|
<button id="startButton" type="button" onclick="newGame(startLevelInput.value)" disabled>JOUER</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</section>
|
</section>
|
||||||
|
20
webtris.js
20
webtris.js
@ -377,10 +377,8 @@ class Stats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newLevel(level=null) {
|
newLevel(level=null) {
|
||||||
if (level)
|
this.level = level || this.level + 1
|
||||||
this.level = level
|
location.hash = "#" + this.level
|
||||||
else
|
|
||||||
this.level++
|
|
||||||
this.levelCell.innerText = this.level
|
this.levelCell.innerText = this.level
|
||||||
printTempTexts(`NIVEAU<br/>${this.level}`)
|
printTempTexts(`NIVEAU<br/>${this.level}`)
|
||||||
this.goal += 5 * this.level
|
this.goal += 5 * this.level
|
||||||
@ -429,7 +427,7 @@ class Stats {
|
|||||||
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
function newGame() {
|
function newGame(startLevel=startLevelInput) {
|
||||||
document.getElementById("startButton").blur()
|
document.getElementById("startButton").blur()
|
||||||
|
|
||||||
holdQueue.newGame()
|
holdQueue.newGame()
|
||||||
@ -437,7 +435,6 @@ function newGame() {
|
|||||||
nextQueue.newGame()
|
nextQueue.newGame()
|
||||||
stats.newGame()
|
stats.newGame()
|
||||||
|
|
||||||
var startLevel = document.getElementById("startLevel").value
|
|
||||||
localStorage.setItem("startLevel", startLevel)
|
localStorage.setItem("startLevel", startLevel)
|
||||||
|
|
||||||
document.getElementById("game").style.display = "grid"
|
document.getElementById("game").style.display = "grid"
|
||||||
@ -455,8 +452,8 @@ function newGame() {
|
|||||||
newLevel(startLevel)
|
newLevel(startLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
function newLevel(startLevel) {
|
function newLevel(level) {
|
||||||
stats.newLevel(startLevel)
|
stats.newLevel(level)
|
||||||
generationPhase()
|
generationPhase()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -967,7 +964,7 @@ selectedAction = ""
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
applySettings()
|
applySettings()
|
||||||
|
|
||||||
document.getElementById("startLevel").value = localStorage.getItem("startLevel") || 1
|
document.getElementById("startLevelInput").value = localStorage.getItem("startLevel") || 1
|
||||||
|
|
||||||
document.getElementById("startButton").disabled = false
|
document.getElementById("startButton").disabled = false
|
||||||
document.getElementById("startButton").focus()
|
document.getElementById("startButton").focus()
|
||||||
@ -980,6 +977,7 @@ window.onload = function() {
|
|||||||
matrix = new Matrix()
|
matrix = new Matrix()
|
||||||
nextQueue = new NextQueue()
|
nextQueue = new NextQueue()
|
||||||
themePreview = new ThemePreview()
|
themePreview = new ThemePreview()
|
||||||
|
|
||||||
showSettings()
|
if (location.hash) newGame(Math.min(location.hash.slice(1), 15))
|
||||||
|
else showSettings()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user