ne charger que les mots de la bonne longueur
This commit is contained in:
+3
-3
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<dialog id="optionsDialog" open>
|
<dialog id="optionsDialog">
|
||||||
<article>
|
<article>
|
||||||
<header>
|
<header>
|
||||||
<h2>L<img src="icones/lotus.svg" alt="🪷">TUS</h2>
|
<h2>L<img src="icones/lotus.svg" alt="🪷">TUS</h2>
|
||||||
@@ -42,11 +42,11 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<label class="option">
|
<label class="option">
|
||||||
<input class="lettre mal-placee" disabled>
|
<input class="lettre mal-placee" disabled>
|
||||||
indique une lettre se trouvant ailleurs dans le mot et
|
indique une lettre se trouvant ailleurs dans le mot.
|
||||||
</label>
|
</label>
|
||||||
<label class="option">
|
<label class="option">
|
||||||
<input class="lettre bien-placee" disabled>
|
<input class="lettre bien-placee" disabled>
|
||||||
une lettre bien placée.
|
indique une lettre bien placée.
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|||||||
+6093
File diff suppressed because it is too large
Load Diff
+2387
File diff suppressed because it is too large
Load Diff
+4482
File diff suppressed because it is too large
Load Diff
+6393
File diff suppressed because it is too large
Load Diff
+7396
File diff suppressed because it is too large
Load Diff
+70065
File diff suppressed because it is too large
Load Diff
+20288
File diff suppressed because it is too large
Load Diff
+35348
File diff suppressed because it is too large
Load Diff
+52397
File diff suppressed because it is too large
Load Diff
+65493
File diff suppressed because it is too large
Load Diff
@@ -1,58 +1,82 @@
|
|||||||
const NB_ESSAIS_MAX = 6
|
const NB_ESSAIS_MAX = 6
|
||||||
const periode = 400 //ms
|
const periode = 400 //ms
|
||||||
|
|
||||||
var motsAutorises
|
|
||||||
var motsATrouver
|
|
||||||
|
|
||||||
window.onload = function(event) {
|
window.onload = function(event) {
|
||||||
fetch("motsAutorises.txt")
|
confirmOptionsButton.ariaBusy = false
|
||||||
.then(response => response.text())
|
afficheOptions()
|
||||||
.then(data => motsAutorises = data.split("\n"))
|
|
||||||
.then(jouer)
|
|
||||||
|
|
||||||
fetch("motsATrouver.txt")
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(data => {
|
|
||||||
motsATrouver = []
|
|
||||||
data.split("\n").forEach(mot => {
|
|
||||||
var longeur = mot.length
|
|
||||||
if (!motsATrouver[longeur]) motsATrouver[longeur] = []
|
|
||||||
motsATrouver[longeur].push(mot)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.then(jouer)
|
|
||||||
}
|
|
||||||
|
|
||||||
function jouer() {
|
|
||||||
if (motsAutorises && motsATrouver) {
|
|
||||||
confirmOptionsButton.innerHTML = "Jouer"
|
|
||||||
confirmOptionsButton.disabled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
optionsButton.onclick = function(event) {
|
|
||||||
optionsDialog.showModal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var volumeOn = true
|
var volumeOn = true
|
||||||
|
var nbEssais = 0
|
||||||
|
function afficheOptions() {
|
||||||
|
if (nbEssais) {
|
||||||
|
nbLettresInput.disabled = true
|
||||||
|
confirmOptionsButton.innerHTML = "Continuer"
|
||||||
|
} else {
|
||||||
|
nbLettresInput.disabled = false
|
||||||
|
confirmOptionsButton.innerHTML = "Jouer"
|
||||||
|
}
|
||||||
|
confirmOptionsButton.disabled = false
|
||||||
|
confirmOptionsButton.innerHTML = nbEssais? "Continuer" : "Jouer"
|
||||||
|
optionsDialog.showModal()
|
||||||
|
}
|
||||||
|
|
||||||
|
optionsButton.onclick = afficheOptions
|
||||||
|
|
||||||
var nbLettres = 8
|
var nbLettres = 8
|
||||||
|
var motsAutorises = []
|
||||||
|
var motsATrouver = []
|
||||||
optionsForm.onsubmit = function(event) {
|
optionsForm.onsubmit = function(event) {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
if (optionsForm.checkValidity()) {
|
if (optionsForm.checkValidity()) {
|
||||||
volumeOn = volumeCheckbox.checked
|
volumeOn = volumeCheckbox.checked
|
||||||
nbLettres = nbLettresInput.valueAsNumber
|
nbLettres = nbLettresInput.valueAsNumber
|
||||||
optionsDialog.close()
|
|
||||||
if (!nbEssais) nouvellePartie()
|
if (!chargementTermine()) {
|
||||||
|
confirmOptionsButton.innerHTML = "Chargement..."
|
||||||
|
confirmOptionsButton.disabled = true
|
||||||
|
confirmOptionsButton.ariaBusy = true
|
||||||
|
|
||||||
|
if (!motsATrouver[nbLettres]) {
|
||||||
|
fetch(`motsATrouver${nbLettres}.txt`)
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(data => motsATrouver[nbLettres] = data.split("\n"))
|
||||||
|
.then(chargementTermine)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!motsAutorises[nbLettres]) {
|
||||||
|
fetch(`motsAutorises${nbLettres}.txt`)
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(data => motsAutorises[nbLettres] = data.split("\n"))
|
||||||
|
.then(chargementTermine)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
optionsForm.reportValidity()
|
optionsForm.reportValidity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function chargementTermine() {
|
||||||
|
if (motsAutorises[nbLettres] && motsATrouver[nbLettres]) {
|
||||||
|
optionsDialog.close()
|
||||||
|
confirmOptionsButton.innerHTML = "Continuer"
|
||||||
|
confirmOptionsButton.disabled = false
|
||||||
|
confirmOptionsButton.ariaBusy = false
|
||||||
|
|
||||||
|
if (!nbEssais) nouvellePartie()
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var nbLettres
|
||||||
var motATrouver
|
var motATrouver
|
||||||
var listeATrouver
|
var listeATrouver
|
||||||
var lettresTrouvees
|
var lettresTrouvees
|
||||||
var nbEssais = 0
|
var nbEssais = 0
|
||||||
function nouvellePartie() {
|
function nouvellePartie() {
|
||||||
nbEssais = 0
|
|
||||||
motATrouver = motsATrouver[nbLettres][Math.floor(motsATrouver[nbLettres].length * Math.random())]
|
motATrouver = motsATrouver[nbLettres][Math.floor(motsATrouver[nbLettres].length * Math.random())]
|
||||||
motATrouver = motATrouver.normalize("NFD").replace(/\p{Diacritic}/gu, "")
|
motATrouver = motATrouver.normalize("NFD").replace(/\p{Diacritic}/gu, "")
|
||||||
listeATrouver = Array.from(motATrouver)
|
listeATrouver = Array.from(motATrouver)
|
||||||
@@ -65,7 +89,7 @@ function nouvellePartie() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function perdu() {
|
function perdu() {
|
||||||
if (confirm(`Perdu ! Le mot à trouver était : ${motATrouver.toUpperCase()}.\nRéessayer ?`)) nouvellePartie()
|
if (confirm(`Perdu ! Le mot à trouver était : ${motATrouver.toUpperCase()}.\nRéessayer ?`)) afficheOptions()
|
||||||
else nbEssais = 0
|
else nbEssais = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +140,7 @@ function nouvelEssai() {
|
|||||||
})
|
})
|
||||||
if (volumeOn) play(sonPerdu)
|
if (volumeOn) play(sonPerdu)
|
||||||
else perdu()
|
else perdu()
|
||||||
|
nbEssais = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,14 +181,14 @@ function play(son) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function gagne() {
|
function gagne() {
|
||||||
if (confirm("Bien joué !\nUne nouvelle partie ?")) nouvellePartie()
|
if (confirm("Bien joué !\nUne nouvelle partie ?")) afficheOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
sonMotTrouve.onended = gagne
|
sonMotTrouve.onended = gagne
|
||||||
|
|
||||||
function onsubmit(event) {
|
function onsubmit(event) {
|
||||||
if (this.checkValidity()) {
|
if (this.checkValidity()) {
|
||||||
if (motsAutorises.includes(Array.from(form.children).map((input) => input.value).join(""))) {
|
if (motsAutorises[nbLettres].includes(Array.from(form.children).map((input) => input.value).join(""))) {
|
||||||
var inputsNonValides = Array.from(form.children)
|
var inputsNonValides = Array.from(form.children)
|
||||||
listeATrouver.forEach((lettre, indice) => {
|
listeATrouver.forEach((lettre, indice) => {
|
||||||
var input = this.children[indice]
|
var input = this.children[indice]
|
||||||
@@ -195,6 +220,7 @@ function onsubmit(event) {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (nbLettresBienPlacees == nbLettres) {
|
if (nbLettresBienPlacees == nbLettres) {
|
||||||
|
nbEssais = 0
|
||||||
if (volumeOn) play(sonMotTrouve)
|
if (volumeOn) play(sonMotTrouve)
|
||||||
else gagne()
|
else gagne()
|
||||||
} else nouvelEssai()
|
} else nouvelEssai()
|
||||||
|
|||||||
Reference in New Issue
Block a user