Compare commits

..

2 commits

Author SHA1 Message Date
Bocquel Raphael
091919c612 Merge branch 'main' of https://git.etud.insa-toulouse.fr/bocquel/Projet_JS 2024-12-23 15:50:03 +01:00
Bocquel Raphael
d06610ca58 grille marche mieux 2024-12-23 15:47:19 +01:00
5 changed files with 37 additions and 9 deletions

BIN
case_flag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
case_zero.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

View file

@ -33,8 +33,10 @@
<div id="jeu">
<button id="debut_game" onclick="chrono()">GO!</button>
<button id="fin_game" onclick="reset()">CIAO</button>
<div id="grille">
<script type="text/javascript">grilleButtons(7,7);</script>
</div>
</div>

View file

@ -7,8 +7,9 @@ class Case {
this.hidden = true;
}
}
<<<<<<< HEAD
=======
//Fonction pour créer un cookie.
function setCookie(name, value, days) {
const expires = new Date(Date.now() + days * 864e5).toUTCString();
@ -18,6 +19,7 @@ function setCookie(name, value, days) {
function getCookie(name) {
return document.cookie.split('; ').find(row => row.startsWith(name + '='))?.split('=')[1];
}
>>>>>>> d322df708ea3bd0301a054980adc49db1c96d181
function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms));
@ -69,6 +71,8 @@ function creerGrille(haut, larg) {
}
function cookie(){
const popup = document.getElementById('popup');
const closePopupButton = document.getElementById('accept-button');
@ -91,28 +95,50 @@ const cookieAccepted = getCookie('cookiesAccepted');
if (!cookieAccepted){
cookie();
}
function changeImage(mouseEvent) {
mouseEvent.target.style.background="url('case_mine.png')" ;
function selectImage(idCase) {
const coords = idCase.split("_") ;
const x = parseInt(coords[0]) ;
const y = parseInt(coords[0]) ;
}
function changeImage(mouseEvent) {
if (!(mouseEvent.target.classList.contains("buttonFlagged"))) {
mouseEvent.target.style.background="url('case_mine.png')" ;
mouseEvent.target.classList.add("buttonRevealed") ;
}
}
function changeImageFlag(rightClick) {
rightClick.preventDefault() ;
if (rightClick.target.classList.contains("buttonRevealed")) {
return 0 ;
} else if (rightClick.target.classList.contains("buttonFlagged")) {
rightClick.target.style.background="url('case_vide.png')" ;
rightClick.target.classList.remove("buttonFlagged") ;
} else {
rightClick.target.style.background="url('case_flag.png')" ;
rightClick.target.classList.add("buttonFlagged") ;
}
}
function grilleButtons(haut, larg) {
const divGrille = document.getElementById("grille") ;
for (var i=0;i<haut;i++) {
for (var j=0;j<larg;j++){
var newCase = document.createElement("BUTTON") ;
newCase.style.gridrow=i.toString() ;
newCase.classList.add("button_case") ;
newCase.id = i.toString() + "_" + j.toString() ;
newCase.style.background="url('case_vide.png')" ;
newCase.addEventListener("click", changeImage);
newCase.addEventListener("contextmenu", changeImageFlag);
divGrille.appendChild(newCase) ;
}
}
}