reset fonctionnel
This commit is contained in:
parent
775462025f
commit
db33d3337b
2 changed files with 14 additions and 8 deletions
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- <button id="debut_game" class="game_button" onclick="chrono()">GO!</button>-->
|
<!-- <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="popup" class="popup">
|
<div id="popup" class="popup">
|
||||||
<div class="popup-content">
|
<div class="popup-content">
|
||||||
|
|
18
demineur.js
18
demineur.js
|
@ -18,6 +18,10 @@ let number_mines = 10 ;
|
||||||
let first_click = true ;
|
let first_click = true ;
|
||||||
|
|
||||||
|
|
||||||
|
function getRandomInt(maxi) {
|
||||||
|
return Math.floor(Math.random() * maxi);
|
||||||
|
}
|
||||||
|
|
||||||
function jeuFini() {
|
function jeuFini() {
|
||||||
for (let i = 0; i < hauteur; i++) {
|
for (let i = 0; i < hauteur; i++) {
|
||||||
for (let j = 0; j < largeur; j++) {
|
for (let j = 0; j < largeur; j++) {
|
||||||
|
@ -60,12 +64,12 @@ function creerGrille(haut, larg, mine_nb, x_first, y_first) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var k = 0; k < mine_nb; k++) {
|
for (var k = 0; k < mine_nb; k++) {
|
||||||
let new_x = Math.floor(Math.random() * larg);
|
let new_x = getRandomInt(larg);
|
||||||
let new_y = Math.floor(Math.random() * haut);
|
let new_y = getRandomInt(haut);
|
||||||
|
|
||||||
while (grille[new_y][new_x] == 9 || (new_y == y_first && new_x == x_first)) {
|
while (grille[new_y][new_x] == 9 || (new_y == y_first && new_x == x_first)) {
|
||||||
new_x = Math.floor(Math.random() * larg);
|
new_x = getRandomInt(larg);
|
||||||
new_y = Math.floor(Math.random() * haut);
|
new_y = getRandomInt(haut);
|
||||||
}
|
}
|
||||||
|
|
||||||
grille[new_y][new_x] = 9;
|
grille[new_y][new_x] = 9;
|
||||||
|
@ -206,11 +210,14 @@ function resetJeu(mouseEvent) {
|
||||||
divJeu.removeChild(divJeu.children[0]) ;
|
divJeu.removeChild(divJeu.children[0]) ;
|
||||||
mouseEvent.target.removeEventListener("click",resetJeu) ;
|
mouseEvent.target.removeEventListener("click",resetJeu) ;
|
||||||
grilleButtons(hauteur, largeur) ;
|
grilleButtons(hauteur, largeur) ;
|
||||||
|
first_click = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function changeImageClick(mouseEvent) {
|
function changeImageClick(mouseEvent) {
|
||||||
changeImage(mouseEvent.target) ;
|
if (!(mouseEvent.target.classList.contains("buttonRevealed"))) {
|
||||||
|
changeImage(mouseEvent.target) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,7 +265,6 @@ function grilleButtons(haut, larg) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
grilleButtons(hauteur,largeur) ;
|
grilleButtons(hauteur,largeur) ;
|
||||||
|
|
Loading…
Reference in a new issue