ajout de options et resolution conflit

This commit is contained in:
Younes Bezza 2025-01-01 16:29:22 +01:00
commit 5870054bd9
2 changed files with 25 additions and 8 deletions

View file

@ -39,7 +39,7 @@
</div>
<!-- <button id="debut_game" class="game_button" onclick="chrono()">GO!</button>-->
<button id="fin_game" class="game_button" onclick="reset()">CIAO</button>
<button id="fin_game" class="game_button" onclick="reset()">RESET</button>
<div id="cookies-popup" class="popup">
<div class="popup-content">

View file

@ -39,6 +39,10 @@ function resetGame() {
creerGrille(hauteur, largeur, number_mines);
grilleButtons(hauteur, largeur);
}
function getRandomInt(maxi) {
return Math.floor(Math.random() * maxi);
}
function jeuFini() {
for (let i = 0; i < hauteur; i++) {
for (let j = 0; j < largeur; j++) {
@ -81,12 +85,12 @@ function creerGrille(haut, larg, mine_nb, x_first, y_first) {
}
for (var k = 0; k < mine_nb; k++) {
let new_x = Math.floor(Math.random() * larg);
let new_y = Math.floor(Math.random() * haut);
let new_x = getRandomInt(larg);
let new_y = getRandomInt(haut);
while (grille[new_y][new_x] == 9 || (new_y == y_first && new_x == x_first)) {
new_x = Math.floor(Math.random() * larg);
new_y = Math.floor(Math.random() * haut);
new_x = getRandomInt(larg);
new_y = getRandomInt(haut);
}
grille[new_y][new_x] = 9;
@ -222,8 +226,19 @@ function changeImage(targetCase) {
}
function resetJeu(mouseEvent) {
const divJeu = document.getElementById("jeu") ;
divJeu.removeChild(divJeu.children[0]) ;
mouseEvent.target.removeEventListener("click",resetJeu) ;
grilleButtons(hauteur, largeur) ;
first_click = true ;
}
function changeImageClick(mouseEvent) {
if (!(mouseEvent.target.classList.contains("buttonRevealed"))) {
changeImage(mouseEvent.target) ;
}
}
@ -254,6 +269,9 @@ function grilleButtons(haut, larg) {
divGrille.style.gridTemplateRows = taille_rows ;
divJeu.appendChild(divGrille) ;
const myButton = document.getElementById("fin_game");
myButton.addEventListener("click", resetJeu) ;
for (var i=0;i<haut;i++) {
for (var j=0;j<larg;j++){
var newCase = document.createElement("BUTTON") ;
@ -268,7 +286,6 @@ function grilleButtons(haut, larg) {
}
}
}
grilleButtons(hauteur,largeur) ;