volumeOn event
This commit is contained in:
parent
9b41ad99d2
commit
1963277e23
14
script.js
14
script.js
@ -1,10 +1,13 @@
|
|||||||
|
const NB_ESSAIS_MAX = 6
|
||||||
const periode = 500 //ms
|
const periode = 500 //ms
|
||||||
|
|
||||||
var motATrouver
|
var motATrouver
|
||||||
var listeATrouver
|
var listeATrouver
|
||||||
var lettresTrouvees
|
var lettresTrouvees
|
||||||
var nbLettres
|
var nbLettres
|
||||||
|
var nbEssais
|
||||||
function nouvellePartie() {
|
function nouvellePartie() {
|
||||||
|
nbEssais = 0
|
||||||
motATrouver = motsATrouver[Math.floor(motsATrouver.length * Math.pow(Math.random(), 1.5))]
|
motATrouver = motsATrouver[Math.floor(motsATrouver.length * Math.pow(Math.random(), 1.5))]
|
||||||
motATrouver = motATrouver.normalize("NFD").replace(/\p{Diacritic}/gu, "")
|
motATrouver = motATrouver.normalize("NFD").replace(/\p{Diacritic}/gu, "")
|
||||||
listeATrouver = Array.from(motATrouver)
|
listeATrouver = Array.from(motATrouver)
|
||||||
@ -20,7 +23,6 @@ function nouvellePartie() {
|
|||||||
var form
|
var form
|
||||||
var lettresATrouver
|
var lettresATrouver
|
||||||
var nbLettresBienPlacees
|
var nbLettresBienPlacees
|
||||||
var nbEssais = 0
|
|
||||||
function nouvelEssai() {
|
function nouvelEssai() {
|
||||||
nbEssais++
|
nbEssais++
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ function nouvelEssai() {
|
|||||||
|
|
||||||
grille.appendChild(form)
|
grille.appendChild(form)
|
||||||
|
|
||||||
if (nbEssais <= 6) {
|
if (nbEssais <= NB_ESSAIS_MAX) {
|
||||||
form.onsubmit = onsubmit
|
form.onsubmit = onsubmit
|
||||||
form.children[0].focus()
|
form.children[0].focus()
|
||||||
} else {
|
} else {
|
||||||
@ -93,7 +95,6 @@ function onkeyup(event) {
|
|||||||
|
|
||||||
function onsubmit(event) {
|
function onsubmit(event) {
|
||||||
if (this.checkValidity()) {
|
if (this.checkValidity()) {
|
||||||
volumeOn = volumeCheckbox.checked
|
|
||||||
if (motsAutorises.includes(Array.from(form.children).map((input) => input.value).join(""))) {
|
if (motsAutorises.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) => {
|
||||||
@ -126,7 +127,7 @@ function onsubmit(event) {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (nbLettresBienPlacees == nbLettres) {
|
if (nbLettresBienPlacees == nbLettres) {
|
||||||
if (confirm("Bien joué gros !\nUne nouvelle partie ?")) nouvellePartie()
|
if (confirm("Bien joué !\nUne nouvelle partie ?")) nouvellePartie()
|
||||||
} else nouvelEssai()
|
} else nouvelEssai()
|
||||||
}, listeATrouver.length * periode)
|
}, listeATrouver.length * periode)
|
||||||
|
|
||||||
@ -141,4 +142,9 @@ function onsubmit(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var volumeOn
|
||||||
|
volumeCheckbox.oninput = function(event) {
|
||||||
|
volumeOn = this.checked
|
||||||
|
}
|
||||||
|
|
||||||
nouvellePartie()
|
nouvellePartie()
|
Loading…
x
Reference in New Issue
Block a user