start game leval at location hash

This commit is contained in:
Adrien MALINGREY 2020-10-14 20:24:01 +02:00
parent 3fccefc57c
commit 1d1b2b24d2
2 changed files with 11 additions and 13 deletions

View File

@ -106,9 +106,9 @@
<legend>Nouvelle partie</legend>
<div>
<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>
<button id="startButton" type="button" onclick="newGame()" disabled>JOUER</button>
<button id="startButton" type="button" onclick="newGame(startLevelInput.value)" disabled>JOUER</button>
</div>
</fieldset>
</section>

View File

@ -377,10 +377,8 @@ class Stats {
}
newLevel(level=null) {
if (level)
this.level = level
else
this.level++
this.level = level || this.level + 1
location.hash = "#" + this.level
this.levelCell.innerText = this.level
printTempTexts(`NIVEAU<br/>${this.level}`)
this.goal += 5 * this.level
@ -429,7 +427,7 @@ class Stats {
// Functions
function newGame() {
function newGame(startLevel=startLevelInput) {
document.getElementById("startButton").blur()
holdQueue.newGame()
@ -437,7 +435,6 @@ function newGame() {
nextQueue.newGame()
stats.newGame()
var startLevel = document.getElementById("startLevel").value
localStorage.setItem("startLevel", startLevel)
document.getElementById("game").style.display = "grid"
@ -455,8 +452,8 @@ function newGame() {
newLevel(startLevel)
}
function newLevel(startLevel) {
stats.newLevel(startLevel)
function newLevel(level) {
stats.newLevel(level)
generationPhase()
}
@ -967,7 +964,7 @@ selectedAction = ""
window.onload = function() {
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").focus()
@ -980,6 +977,7 @@ window.onload = function() {
matrix = new Matrix()
nextQueue = new NextQueue()
themePreview = new ThemePreview()
showSettings()
if (location.hash) newGame(Math.min(location.hash.slice(1), 15))
else showSettings()
}