diff --git a/code/button_displayer.js b/code/button_displayer.js index add0dd5..436b1ad 100644 --- a/code/button_displayer.js +++ b/code/button_displayer.js @@ -6,6 +6,9 @@ hideAll(); var modeSelected=null; var diffSelected=null; +var btn_options=document.getElementById("btn_options"); +btn_options.width=size; + modes.forEach(element => { eval("var btn"+element+"= document.getElementById('btn_"+element+"')"); eval("btn_"+element+".width=size"); @@ -71,5 +74,5 @@ function hideAll() function play() { - //window.location.replace("./game.html?mode="+modeSelected+"&diff="+diffSelected+"&pseudo="+document.getElementById("field_pseudo")); + window.location.replace("./game.html?mode="+modeSelected+"&diff="+diffSelected+"&pseudo="+document.getElementById("field_pseudo")); } \ No newline at end of file diff --git a/code/game.css b/code/game.css index 054f824..9667294 100644 --- a/code/game.css +++ b/code/game.css @@ -92,6 +92,7 @@ -webkit-box-shadow:inset 0px 0px 0px 5px blue; -moz-box-shadow:inset 0px 0px 0px 5px blue; box-shadow:inset 0px 0px 0px 5px blue; + } .stats { diff --git a/code/index.css b/code/index.css index 84235b1..bdcea52 100644 --- a/code/index.css +++ b/code/index.css @@ -17,4 +17,74 @@ -webkit-box-shadow:inset 0px 0px 0px 5px black; -moz-box-shadow:inset 0px 0px 0px 5px black; box-shadow:inset 0px 0px 0px 5px black; -} \ No newline at end of file +} + +.slider { + -webkit-appearance: none; + width: 100%; + height: 15px; + border-radius: 5px; + background: #d3d3d3; + outline: none; + opacity: 0.7; + -webkit-transition: .2s; + transition: opacity .2s; + } + + .slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 25px; + height: 25px; + border-radius: 50%; + background: #4CAF50; + cursor: pointer; + } + + .slider::-moz-range-thumb { + width: 25px; + height: 25px; + border-radius: 50%; + background: #4CAF50; + cursor: pointer; + } + + + /* The Modal (background) */ +.modal { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 1; /* Sit on top */ + padding-top: 100px; /* Location of the box */ + left: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: rgb(0,0,0); /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ + } + + /* Modal Content */ + .modal-content { + background-color: #fefefe; + margin: auto; + padding: 20px; + border: 1px solid #888; + width: 80%; + } + + /* The Close Button */ + .close { + color: #aaaaaa; + float: right; + font-size: 28px; + font-weight: bold; + } + + .close:hover, + .close:focus { + color: #000; + text-decoration: none; + cursor: pointer; + } \ No newline at end of file diff --git a/code/index.html b/code/index.html deleted file mode 100644 index 2a8ee48..0000000 --- a/code/index.html +++ /dev/null @@ -1,49 +0,0 @@ - - - On The Dot - - - - - Jouer la partie en :
-
- - - - -
- - - Entrez votre pseudo (optionnel, mais nécessaire si vous voulez sauvegarder votre score): - - - - - - -
- Partie en points : la partie finit quand vous obtenez le nombre de points choisi. Mettez le moins de temps possible !
- Partie en temps : la partie finit quand le temps imparti est écoulé. Obtenez le plus de points possible !
- Partie en survie : la partie finit quand le temps atteint 0. Gagner un point vous rajoute 30s, obtenez le plus de points possible !
-
- - - diff --git a/code/index.php b/code/index.php new file mode 100644 index 0000000..de461b5 --- /dev/null +++ b/code/index.php @@ -0,0 +1,75 @@ + + +On The Dot + + + + + +Jouer la partie en :
+
+ + + + +
+ + +Entrez votre pseudo (optionnel, mais nécessaire si vous voulez sauvegarder votre score): + + + + + +
+Partie en points : la partie finit quand vous obtenez le nombre de points choisi. Mettez le moins de temps possible !
+Partie en temps : la partie finit quand le temps imparti est écoulé. Obtenez le plus de points possible !
+Partie en survie : la partie finit quand le temps atteint 0. Gagner un point vous rajoute 30s, obtenez le plus de points possible !
+
+ + + + + + + + + + diff --git a/code/options.js b/code/options.js new file mode 100644 index 0000000..8762144 --- /dev/null +++ b/code/options.js @@ -0,0 +1,33 @@ +// Get the modal +var modal = document.getElementById("optionsModal"); + +// Get the button that opens the modal +var btn = document.getElementById("btn_options"); + +// Get the element that closes the modal +var span = document.getElementsByClassName("close")[0]; + +// When the user clicks the button, open the modal +btn.onclick = function() { + modal.style.display = "block"; +} + +// When the user clicks on (x), close the modal +span.onclick = function() { + modal.style.display = "none"; +} + +// When the user clicks anywhere outside of the modal, close it +window.onclick = function(event) { + if (event.target == modal) { + modal.style.display = "none"; + } +} + +var slider = document.getElementById("range_dots"); +var output = document.getElementById("dotsNumber"); +output.innerHTML = slider.value; + +slider.oninput = function() { + output.innerHTML = this.value; +} \ No newline at end of file diff --git a/code/ress/material_10.png b/code/ress/black.png similarity index 64% rename from code/ress/material_10.png rename to code/ress/black.png index 338c677..b587860 100644 Binary files a/code/ress/material_10.png and b/code/ress/black.png differ diff --git a/code/ress/brown.png b/code/ress/brown.png new file mode 100644 index 0000000..4b16c03 Binary files /dev/null and b/code/ress/brown.png differ diff --git a/code/ress/cyan.png b/code/ress/cyan.png new file mode 100644 index 0000000..9f9e92e Binary files /dev/null and b/code/ress/cyan.png differ diff --git a/code/ress/gear.png b/code/ress/gear.png new file mode 100644 index 0000000..b46ad6b Binary files /dev/null and b/code/ress/gear.png differ diff --git a/code/ress/lightblue.png b/code/ress/lightblue.png new file mode 100644 index 0000000..e421f8a Binary files /dev/null and b/code/ress/lightblue.png differ diff --git a/code/ress/material_11.png b/code/ress/material_11.png new file mode 100644 index 0000000..7ef0f0c Binary files /dev/null and b/code/ress/material_11.png differ diff --git a/code/ress/orange.png b/code/ress/orange.png new file mode 100644 index 0000000..77e5d32 Binary files /dev/null and b/code/ress/orange.png differ diff --git a/code/vitraux.js b/code/vitraux.js index af5dcac..3da02f3 100644 --- a/code/vitraux.js +++ b/code/vitraux.js @@ -1,576 +1,589 @@ var canvasT = document.getElementById('canvasTotal'); - var ctxT = canvasT.getContext('2d'); - - var canvasO = document.getElementById('canvasObj'); - var ctxO = canvasO.getContext('2d'); - - var canvasR = document.getElementById('canvasR'); - //var ctxR = canvasR.getContext('2d'); - - tab1=[]; - tab2=[]; - tab3=[]; - tab4=[]; +var ctxT = canvasT.getContext('2d'); - tabR=[[],[],[],[],[]]; +var canvasO = document.getElementById('canvasObj'); +var ctxO = canvasO.getContext('2d'); - tabR1=[]; - tabR2=[]; - tabR3=[]; - tabR4=[]; +var canvasR = document.getElementById('canvasR'); +//var ctxR = canvasR.getContext('2d'); - points=0; - tabTotal=[]; - tabObjCmp=[]; - mousePos=[]; - colorsAvailable=["red","yellow","green","purple"]; - colors=["red","yellow","green","purple"]; - - size=screen.height/6; // 6 lignes de 50px // 6 colonnes de 50px - canvasT.width=size; - canvasO.width=size; - - canvasT.height=size; - canvasO.height=size; - - for(var a=1;a<5;a++) - { - eval("var canvas"+ a +"= document.getElementById('canvas"+a+"')"); - eval("var ctx"+a+" = canvas"+a+".getContext('2d')"); - eval("canvas"+a+".width=size"); - eval("canvas"+a+".height=size"); - - eval("var canvasR"+ a +"= document.getElementById('canvasR"+a+"')"); - eval("var ctxR"+a+" = canvasR"+a+".getContext('2d')"); - eval("canvasR"+a+".width=size"); - eval("canvasR"+a+".height=size"); - } - - function faireCercle(x,y,color,lectx){ - var cercle = new Path2D(); - - nx=(size/6)*(x>0 ? x+2 : x+3); - ny=(size/6)*(y>0 ? y+2 : y+3); - - cercle.moveTo(nx, ny); - cercle.arc(nx+(size/12), ny+(size/12), (size/12), 0, 2 * Math.PI); - - lectx.fillStyle = color; - lectx.fill(cercle); - } - - function drawImg(x,y,color,lectx) +tab1=[]; +tab2=[]; +tab3=[]; +tab4=[]; + +tabR=[[],[],[],[],[]]; + +tabR1=[]; +tabR2=[]; +tabR3=[]; +tabR4=[]; + +points=0; +tabTotal=[]; +tabObjCmp=[]; +mousePos=[]; + +var dotsAmount=4; +var colors=[]; +colorsAvailable=["red","yellow","green","purple","lightblue","brown","cyan","orange"]; + +for(var cpt=0;cpt-1) + { + colors.push(colorsAvailable[pos]); + colorsAvailable.splice(index,1); + } +} + +size=screen.height/6; // 6 lignes de 50px // 6 colonnes de 50px +canvasT.width=size; +canvasO.width=size; + +canvasT.height=size; +canvasO.height=size; + +for(var a=1;a<5;a++) +{ + eval("var canvas"+ a +"= document.getElementById('canvas"+a+"')"); + eval("var ctx"+a+" = canvas"+a+".getContext('2d')"); + eval("canvas"+a+".width=size"); + eval("canvas"+a+".height=size"); + + eval("var canvasR"+ a +"= document.getElementById('canvasR"+a+"')"); + eval("var ctxR"+a+" = canvasR"+a+".getContext('2d')"); + eval("canvasR"+a+".width=size"); + eval("canvasR"+a+".height=size"); +} + +function faireCercle(x,y,color,lectx){ + var cercle = new Path2D(); + + nx=(size/6)*(x>0 ? x+2 : x+3); + ny=(size/6)*(y>0 ? y+2 : y+3); + + cercle.moveTo(nx, ny); + cercle.arc(nx+(size/12), ny+(size/12), (size/12), 0, 2 * Math.PI); + + lectx.fillStyle = color; + lectx.fill(cercle); +} + +function drawImg(x,y,color,lectx) +{ + var img= new Image(); + + + var nx=(size/6)*(x>0 ? x+2 : x+3); + var ny=(size/6)*(y>0 ? y+2 : y+3); + + img.src="ress/"+color+".png"; + + img.onload = function(){ + lectx.drawImage(img,nx,ny,size/6,size/6); + } + +} + +function tourneG(letab,lecanvas,lectx) +{ + letab.forEach(element => { + tmp=element[0]; + element[0]=element[1]; + element[1]=-tmp; + }); + toutDessiner(letab,lecanvas,lectx); + empiler(); +} + +function tourneD(letab,lecanvas,lectx,sselem=null) +{ + if(sselem==null){ + letab.forEach(element => { + tmp=element[1]; + element[1]=element[0]; + element[0]=-tmp; + }); + } + + else { + letab[sselem].forEach(element => { + tmp=element[1]; + element[1]=element[0]; + element[0]=-tmp; + }); + } + //console.log("pre-empiler :"+tabTotal); + empiler(sselem!=null); + //console.log("post-empiler :"+tabTotal); + if(sselem==null) + toutDessiner(letab,lecanvas,lectx); +} + +function toutDessiner(pts,lecanvas,lectx) +{ + lectx.clearRect(0, 0, lecanvas.width, lecanvas.height); + if(pts[0]) + { + var i=1*(typeof pts[0]==="boolean"); + for(i;i0 ? x+2 : x+3); - var ny=(size/6)*(y>0 ? y+2 : y+3); - - img.src="ress/"+color+".png"; - - img.onload = function(){ - lectx.drawImage(img,nx,ny,size/6,size/6); + if(Array.isArray(pts[i])) + { + faireCercle(pts[i][0],pts[i][1],pts[i][2],lectx); + drawImg(pts[i][0],pts[i][1],pts[i][2],lectx); } - - } - - function tourneG(letab,lecanvas,lectx) - { - letab.forEach(element => { - tmp=element[0]; - element[0]=element[1]; - element[1]=-tmp; - }); - toutDessiner(letab,lecanvas,lectx); - empiler(); } - - function tourneD(letab,lecanvas,lectx,sselem=null) + } +} + +function empiler(obj=false) +{ + const unique = (val) => val.toString() != test.toString(); + var exists=false; + + if(!obj) + { + tabTotal=[]; + if(tab1[0]) { - if(sselem==null){ - letab.forEach(element => { - tmp=element[1]; - element[1]=element[0]; - element[0]=-tmp; - }); - } - else { - letab[sselem].forEach(element => { - tmp=element[1]; - element[1]=element[0]; - element[0]=-tmp; - }); - } - //console.log("pre-empiler :"+tabTotal); - empiler(sselem!=null); - //console.log("post-empiler :"+tabTotal); - if(sselem==null) - toutDessiner(letab,lecanvas,lectx); - } - - function toutDessiner(pts,lecanvas,lectx) - { - lectx.clearRect(0, 0, lecanvas.width, lecanvas.height); - if(pts[0]) - { - var i=1*(typeof pts[0]==="boolean"); - for(i;i { + if(Array.isArray(element)) { - if(Array.isArray(pts[i])) - { - faireCercle(pts[i][0],pts[i][1],pts[i][2],lectx); - drawImg(pts[i][0],pts[i][1],pts[i][2],lectx); - } + tabTotal.push(element); } - } + }) } - - function empiler(obj=false) - { - const unique = (val) => val.toString() != test.toString(); - var exists=false; + if(tab2[0]){ - if(!obj) - { - tabTotal=[]; - if(tab1[0]) - { - - tab1.forEach(element => { - if(Array.isArray(element)) - { - tabTotal.push(element); - } - }) - } - if(tab2[0]){ - - tab2.forEach(element => { - if(Array.isArray(element)) - { - colors.forEach(col => { - test=[element[0],element[1],col]; - if(!exists) - exists=!tabTotal.every(unique); - }) - if(!exists) - tabTotal.push(element); - exists=false; - } - }) - } - if(tab3[0]) + tab2.forEach(element => { + if(Array.isArray(element)) { - - tab3.forEach(element => { - if(Array.isArray(element)){ - colors.forEach(col => { - test=[element[0],element[1],col]; - if(!exists) - exists=!tabTotal.every(unique); - }) - if(!exists) - tabTotal.push(element); - exists=false; - } + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); }) + if(!exists) + tabTotal.push(element); + exists=false; } - if(tab4[0]){ - - tab4.forEach(element => { - if(Array.isArray(element)) - { - colors.forEach(col => { - test=[element[0],element[1],col]; - if(!exists) - exists=!tabTotal.every(unique); - }) - if(!exists) - tabTotal.push(element); - exists=false; - } + }) + } + if(tab3[0]) + { + + tab3.forEach(element => { + if(Array.isArray(element)){ + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); }) + if(!exists) + tabTotal.push(element); + exists=false; } - checkAllOK(); - toutDessiner(tabTotal,canvasT,ctxT); - } - else{ - tabObjCmp=[]; - for(count=1;count { + if(Array.isArray(element)) { - for(elmCount=1;elmCount { - test=[element[0],element[1],col]; - if(!exists) - exists=!tabObjCmp.every(unique); - }) + colors.forEach(col => { + test=[element[0],element[1],col]; if(!exists) - tabObjCmp.push(element); - exists=false; - } + exists=!tabTotal.every(unique); + }) + if(!exists) + tabTotal.push(element); + exists=false; } - } + }) } - - function swap(letab, lecanvas, lectx,ladir){ - if(ladir=="H"){ - letab.forEach(element=> { - element[1]=-element[1]; - }) - } - else { - letab.forEach(element=> { - element[0]=-element[0]; + checkAllOK(); + toutDessiner(tabTotal,canvasT,ctxT); + } + else{ + tabObjCmp=[]; + for(count=1;count { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabObjCmp.every(unique); }) + if(!exists) + tabObjCmp.push(element); + exists=false; } - if(lecanvas!=null) - { + } + } +} - toutDessiner(letab,lecanvas,lectx); - empiler(); - } +function swap(letab, lecanvas, lectx,ladir){ + if(ladir=="H"){ + letab.forEach(element=> { + element[1]=-element[1]; + }) + } + else { + letab.forEach(element=> { + element[0]=-element[0]; + }) + } + if(lecanvas!=null) + { + + toutDessiner(letab,lecanvas,lectx); + empiler(); + } +} + +function getRandomInt(max) { //rng entier [1;max] + return Math.floor(Math.random() * Math.floor(max))+1; +} + +function copyMDArray(array) //permet la copie d'arrays sans copier les références +{ + var newArray = []; + array.forEach(element => { + newArray.push(Array.from(element)) + }); + return newArray +} + +function generate(){ + tabObj=[copyMDArray(tab1),copyMDArray(tab2),copyMDArray(tab3),copyMDArray(tab4)]; + tabObjCmp=[]; + var actions=getRandomInt(4)+1; + var swapTreshold=11; + var switchTreshold=11; + if(difficulty=="med") //70% tournerD, 30% swap + { + actions+=getRandomInt(3)+3; + swapTreshold=8; + } + if(difficulty=="hard") //50% tournerD, 30% swap, 20% switch + { + actions+=getRandomInt(5)+5; + swapTreshold=6; + switchTreshold=9; + } + + console.log("actions : "+actions+" difficulty="+difficulty); + + while(actions>0){ + if(difficulty!="easy") + act=getRandomInt(10); + else + act=1; + console.log("act="+act+" left:"+actions); + if(switchTreshold<=act && actions>3) // faire un switch + { + var from=getRandomInt(4)-1; + var to=getRandomInt(4)-1; + while(from==to) + to=getRandomInt(4)-1; + + [tabObj[from],tabObj[to]]=[tabObj[to],tabObj[from]]; + console.log("switch "+from+"->"+to); + actions-=3; } - - function getRandomInt(max) { //rng entier [1;max] - return Math.floor(Math.random() * Math.floor(max))+1; + else if(swapTreshold<=act && actions>2) + { + var from=getRandomInt(4)-1; + var dir=getRandomInt(2)==1 ? "H":"V"; + swap(tabObj[from],null,ctxO,dir); + console.log("swap"+dir+" de "+from); + actions-=2; } - - function copyMDArray(array) //permet la copie d'arrays sans copier les références + else { - var newArray = []; - array.forEach(element => { - newArray.push(Array.from(element)) - }); - return newArray + tourneD(tabObj,canvasO,ctxO,getRandomInt(4)-1); + actions-=1; } - - function generate(){ - tabObj=[copyMDArray(tab1),copyMDArray(tab2),copyMDArray(tab3),copyMDArray(tab4)]; - tabObjCmp=[]; - var actions=getRandomInt(4)+1; - var swapTreshold=11; - var switchTreshold=11; - if(difficulty=="med") //70% tournerD, 30% swap - { - actions+=getRandomInt(3)+3; - swapTreshold=8; - } - if(difficulty=="hard") //50% tournerD, 30% swap, 20% switch - { - actions+=getRandomInt(5)+5; - swapTreshold=6; - switchTreshold=9; - } + } + empiler(true); + toutDessiner(tabObjCmp,canvasO,ctxO); + +} - console.log("actions : "+actions+" difficulty="+difficulty); - - while(actions>0){ - if(difficulty!="easy") - act=getRandomInt(10); - else - act=1; - console.log("act="+act+" left:"+actions); - if(switchTreshold<=act && actions>3) // faire un switch - { - var from=getRandomInt(4)-1; - var to=getRandomInt(4)-1; - while(from==to) - to=getRandomInt(4)-1; - - [tabObj[from],tabObj[to]]=[tabObj[to],tabObj[from]]; - console.log("switch "+from+"->"+to); - actions-=3; - } - else if(swapTreshold<=act && actions>2) - { - var from=getRandomInt(4)-1; - var dir=getRandomInt(2)==1 ? "H":"V"; - swap(tabObj[from],null,ctxO,dir); - console.log("swap"+dir+" de "+from); - actions-=2; - } - else - { - tourneD(tabObj,canvasO,ctxO,getRandomInt(4)-1); - actions-=1; - } - } - empiler(true); - toutDessiner(tabObjCmp,canvasO,ctxO); - - } - - function getMousePosition(lecanvas, event, lectx, letab) { - let rect = lecanvas.getBoundingClientRect(); - let x = event.clientX - rect.left; - let y = event.clientY - rect.top; - let dir = compas(x,y,lecanvas); - - if(xy; + se = x>lecanvas.height-y; + + if(ne && se ) return "E"; + if(ne && !se ) return "N"; + if(!ne && se ) return "S"; + if(!ne && !se ) return "O"; +} + + +function rotationManager(e) +{ + var mouseOnRes = mousePos[0].match(/[R]/g)!=null; + canvasNumber=e.currentTarget.id.substring(6); + document.getElementById("canvas"+mousePos[0]).classList.remove('vitrail-select'); + + console.log(mousePos[0]+" vers "+canvasNumber+", mouseOnRes?"+mouseOnRes); + + var firstAv=1; + for(i=1;i<4;i++) //détermine la 1° place libre dans la réserve + { + if(typeof tabR[i][0]=="boolean") + firstAv++; + else + break; + } + + if(mouseOnRes && !canvasNumber.includes("R")) //clic dans la réserve, relâche sur la pile en jeu + { + if(!isVisible(canvasNumber)) //relâche sur emplacement vide au centre { - rect = lecanvas.getBoundingClientRect(); - x = event.clientX - rect.left; - y = event.clientY - rect.top; - ne = x>y; - se = x>lecanvas.height-y; - - if(ne && se ) return "E"; - if(ne && !se ) return "N"; - if(!ne && se ) return "S"; - if(!ne && !se ) return "O"; + toggleVisible(canvasNumber); + tabR[canvasNumber]=[]; + console.log("contenu du tabR[cn] : "+tabR[canvasNumber]); + toggleVisible(mousePos[0].substring(1),true); } - - - function rotationManager(e) + } + else + { + if(isVisible(mousePos[0])) //clic sur un vitrail présent { - var mouseOnRes = mousePos[0].match(/[R]/g)!=null; - canvasNumber=e.currentTarget.id.substring(6); - document.getElementById("canvas"+mousePos[0]).classList.remove('vitrail-select'); - - console.log(mousePos[0]+" vers "+canvasNumber+", mouseOnRes?"+mouseOnRes); - - var firstAv=1; - for(i=1;i<4;i++) //détermine la 1° place libre dans la réserve - { - if(typeof tabR[i][0]=="boolean") - firstAv++; - else - break; - } - - if(mouseOnRes && !canvasNumber.includes("R")) //clic dans la réserve, relâche sur la pile en jeu + if(canvasNumber.includes("R")) //relâche dans réserve { - if(!isVisible(canvasNumber)) //relâche sur emplacement vide au centre + if(tabR[canvasNumber]==null) //emplacement de réserve vide + { + toggleVisible(mousePos[0]); //inverser tag du canvas du centre + tabR[firstAv]=copyMDArray(eval("tab"+mousePos[0])); //mettre le canvas dans la réserve + tabR[firstAv][0]=eval("tab"+mousePos[0]+"[0]"); //transférer le tag du canvas dans la réserve + toggleVisible(firstAv,true); //inverser tag du canvas de réesrve + toutDessiner(tabR[firstAv],eval("canvasR"+firstAv),eval("ctxR"+firstAv)); //afficher canvas dans réserve + //console.log(eval("tabR["+(mousePos[0]-1)+"]")); + } + else //emplacement de réserve occupé { - toggleVisible(canvasNumber); - tabR[canvasNumber]=[]; - console.log("contenu du tabR[cn] : "+tabR[canvasNumber]); - toggleVisible(mousePos[0].substring(1),true); + changeOrder(mousePos[0],canvasNumber); } } else { - if(isVisible(mousePos[0])) //clic sur un vitrail présent + lecanvas=eval("canvas"+canvasNumber); + letab=eval("tab"+canvasNumber); + lectx=lecanvas.getContext('2d'); + dir = compas(e.clientX,e.clientY,e.currentTarget); + if(mousePos[0]==canvasNumber) { - if(canvasNumber.includes("R")) //relâche dans réserve + if((mousePos[1]=="N" && dir == "O") || (mousePos[1]=="S" && dir == "E") || (mousePos[1]=="O" && dir == "S") || (mousePos[1]=="E" && dir == "N")) + { + tourneG(letab,lecanvas,lectx); + } + else if((mousePos[1] == "N" && dir == "E") || (mousePos[1] == "S" && dir == "O") || (mousePos[1] == "E" && dir == "S") || (mousePos[1] == "O" && dir == "N")) { - if(tabR[canvasNumber]==null) //emplacement de réserve vide - { - toggleVisible(mousePos[0]); //inverser tag du canvas du centre - tabR[firstAv]=copyMDArray(eval("tab"+mousePos[0])); //mettre le canvas dans la réserve - tabR[firstAv][0]=eval("tab"+mousePos[0]+"[0]"); //transférer le tag du canvas dans la réserve - toggleVisible(firstAv,true); //inverser tag du canvas de réesrve - toutDessiner(tabR[firstAv],eval("canvasR"+firstAv),eval("ctxR"+firstAv)); //afficher canvas dans réserve - //console.log(eval("tabR["+(mousePos[0]-1)+"]")); - } - else //emplacement de réserve occupé - { - changeOrder(mousePos[0],canvasNumber); - } + tourneD(letab,lecanvas,lectx); } - else + else if ((mousePos[1] == "E" && dir == "O") || (mousePos[1] == "O" && dir == "E")) { - lecanvas=eval("canvas"+canvasNumber); - letab=eval("tab"+canvasNumber); - lectx=lecanvas.getContext('2d'); - dir = compas(e.clientX,e.clientY,e.currentTarget); - if(mousePos[0]==canvasNumber) - { - if((mousePos[1]=="N" && dir == "O") || (mousePos[1]=="S" && dir == "E") || (mousePos[1]=="O" && dir == "S") || (mousePos[1]=="E" && dir == "N")) - { - tourneG(letab,lecanvas,lectx); - } - else if((mousePos[1] == "N" && dir == "E") || (mousePos[1] == "S" && dir == "O") || (mousePos[1] == "E" && dir == "S") || (mousePos[1] == "O" && dir == "N")) - { - tourneD(letab,lecanvas,lectx); - } - else if ((mousePos[1] == "E" && dir == "O") || (mousePos[1] == "O" && dir == "E")) - { - swap(letab,lecanvas,lectx,"V"); - } - else if ((mousePos[1] == "N" && dir == "S") || (mousePos[1] == "S" && dir == "N")) - { - swap(letab,lecanvas,lectx,"H"); - } - } - else - { - changeOrder(mousePos[0],canvasNumber); - } + swap(letab,lecanvas,lectx,"V"); + } + else if ((mousePos[1] == "N" && dir == "S") || (mousePos[1] == "S" && dir == "N")) + { + swap(letab,lecanvas,lectx,"H"); } } - } - } - - - function checkAllOK(){ - //const condition = (val) => val.toString() == element.toString(); - var exists=true; - //exists=!tabObjCmp.every(unique); - if(tabTotal.length==tabObjCmp.length) - { - var verifTab=[]; - verifTab=copyMDArray(tabTotal); - - - for(i=0;i point.toString()==tabObjCmp[i].toString()); - exists*=result.length; + changeOrder(mousePos[0],canvasNumber); } } - else - { - exists=false; - } - - if(exists) - { - var audio = new Audio('ress/Jewel4.mp3'); - audio.play(); - handleScore(1); - generate(); - } } + } +} - function handleScore(modif) - { - points+=modif; - document.getElementById("stats").innerHTML = points+" points"; - - if(objPts!=null && points==objPts) - { - chronoStop(); - var pts = diff.getSeconds()+ (diff.getMinutes()*60) + ((diff.getHours()-1)*3600); - //console.log("./score.php?pts="+pts+"&mode="+get['mode']+"&diff="+get['diff']+"&pseudo="+get['pseudo']); - window.location.replace("./score.php?pts="+pts+"&mode="+get['mode']+"&diff="+get['diff']+"&pseudo="+get['pseudo']); - } - else if(get['mode']=="surv") - { - addTime(30); - } - } - - function changeOrder(from, to) - { - if(from.includes("R")) - fromTab=tabR[from]; - else - fromTab=eval("tab"+from); - - if(to.includes("R")) - toTab=tabR[to]; - else - toTab=eval("tab"+to); - for(i=0;i val.toString() == element.toString(); + var exists=true; + //exists=!tabObjCmp.every(unique); + if(tabTotal.length==tabObjCmp.length) + { + var verifTab=[]; + verifTab=copyMDArray(tabTotal); - function isVisible(what) - { - if(what.includes("R")) - { - if(tabR[what.substring(1)]==null) - return null; - return tabR[what.substring(1)][0]; - } - - return eval("tab"+what+"[0]"); - } - function toggleVisible(where,reserve=false) + for(i=0;i point.toString()==tabObjCmp[i].toString()); + exists*=result.length; } - - function meManager(e) { - document.getElementById(e.currentTarget.id).classList.add('vitrail-hover'); - } - - function mlManager(e) { - document.getElementById(e.currentTarget.id).classList.remove('vitrail-hover'); - } - - - tab1.push(true,[-3,-3,"green"],[-3,2,"red"],[1,2,"yellow"],[3,-3,"purple"]); - tab2.push(true,[-3,-3,"green"],[-3,2,"red"],[1,2,"yellow"],[3,-3,"purple"]); - tab3.push(true,[-3,-3,"green"],[-3,2,"red"],[1,2,"yellow"],[3,-3,"purple"]); - tab4.push(true,[-3,-3,"green"],[-3,2,"red"],[1,2,"yellow"],[3,-3,"purple"]); - - toutDessiner(tab1,canvas1,ctx1); - toutDessiner(tab2,canvas2,ctx2); - toutDessiner(tab3,canvas3,ctx3); - toutDessiner(tab4,canvas4,ctx4); - + } + else + { + exists=false; + } + + if(exists) + { + var audio = new Audio('ress/Jewel4.mp3'); + audio.play(); + handleScore(1); + generate(); + } +} + +function handleScore(modif) +{ + points+=modif; + document.getElementById("stats").innerHTML = points+" points"; + + if(objPts!=null && points==objPts) + { + chronoStop(); + var pts = diff.getSeconds()+ (diff.getMinutes()*60) + ((diff.getHours()-1)*3600); + //console.log("./score.php?pts="+pts+"&mode="+get['mode']+"&diff="+get['diff']+"&pseudo="+get['pseudo']); + window.location.replace("./score.php?pts="+pts+"&mode="+get['mode']+"&diff="+get['diff']+"&pseudo="+get['pseudo']); + } + else if(get['mode']=="surv") + { + addTime(30); + } +} + +function changeOrder(from, to) +{ + if(from.includes("R")) + fromTab=tabR[from]; + else + fromTab=eval("tab"+from); + + if(to.includes("R")) + toTab=tabR[to]; + else + toTab=eval("tab"+to); + + for(i=0;i