From f0715190b90e1d12b9bd9a8bbcc310981ee44c6d Mon Sep 17 00:00:00 2001 From: adplantade Date: Tue, 9 Jun 2020 18:53:28 +0200 Subject: [PATCH] =?UTF-8?q?v=C3=A9rificatoin=20fonctionnelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/index.html | 129 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 43 deletions(-) diff --git a/code/index.html b/code/index.html index 338c457..6a1654e 100644 --- a/code/index.html +++ b/code/index.html @@ -18,7 +18,7 @@ var canvas2 = document.getElementById('canvas2'); var ctx2 = canvas2.getContext('2d'); - + var canvas3 = document.getElementById('canvas3'); var ctx3 = canvas3.getContext('2d'); @@ -36,6 +36,7 @@ tab3=[]; tab4=[]; tabTotal=[]; + tabObjCmp=[]; mousePos=[]; colors=["red","blue","green","brown"]; @@ -114,47 +115,66 @@ }) } - function empiler() + function empiler(obj=false) { - tabTotal=[]; const unique = (val) => val.toString() != test.toString(); exists=false; - - tab1.forEach(element => { - tabTotal.push(element); - }) - tab2.forEach(element => { - colors.forEach(col => { - test=[element[0],element[1],col]; - if(!exists) - exists=!tabTotal.every(unique); - }) - if(!exists) + + if(!obj) + { + tabTotal=[]; + tab1.forEach(element => { tabTotal.push(element); - exists=false; - }) - tab3.forEach(element => { - colors.forEach(col => { - test=[element[0],element[1],col]; + }) + tab2.forEach(element => { + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); + }) if(!exists) + tabTotal.push(element); + exists=false; + }) + tab3.forEach(element => { + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) exists=!tabTotal.every(unique); + }) + if(!exists) + tabTotal.push(element); + exists=false; }) - if(!exists) + tab4.forEach(element => { + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabTotal.every(unique); + }) + if(!exists) tabTotal.push(element); - exists=false; - }) - tab4.forEach(element => { - colors.forEach(col => { - test=[element[0],element[1],col]; + exists=false; + }) + checkAllOK(); + toutDessiner(tabTotal,canvasT,ctxT); + } + else{ + tabObj[0].forEach(element => { + tabObjCmp.push(element); + }) + + tabObj[1].forEach(element => { + colors.forEach(col => { + test=[element[0],element[1],col]; + if(!exists) + exists=!tabObjCmp.every(unique); + }) if(!exists) - exists=!tabTotal.every(unique); + tabObjCmp.push(element); + exists=false; }) - if(!exists) - tabTotal.push(element); - exists=false; - }) - - toutDessiner(tabTotal,canvasT,ctxT); + } } function swap(letab, lecanvas, lectx,ladir){ @@ -181,15 +201,14 @@ tabObj=[[],[]]; tabObj[0]=Array.from(tab1); tabObj[1]=Array.from(tab2); - console.log(tabObj); + tabObjCmp=[]; actions=getRandomInt(5); while(actions>0){ tourneD(tabObj,canvasO,ctxO,getRandomInt(2)-1); - console.log(tabObj); actions--; } - console.log("sec",tabObj); + empiler(true); toutDessiner(tabObj,canvasO,ctxO); } @@ -247,34 +266,58 @@ } } + + function checkAllOK(){ + //const condition = (val) => val.toString() == element.toString(); + exists=true; + //exists=!tabObjCmp.every(unique); + + if(tabTotal.length==tabObjCmp.length) + { + for(i=0;i>tabTotal.length;i++) + { + exists*tabTotal[i].toString()==tabObjCmp[i].toString(); + } + } + else + exists=false; + + if(exists) + { + console.log("OK"); + generateEasy(); + } + } + + canvas1.addEventListener("mousedown",function(e){ mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; }) - + canvas1.addEventListener("mouseup",function(e){ rotationManager(e); }) - + canvas2.addEventListener("mousedown",function(e){ mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; }) - + canvas2.addEventListener("mouseup",function(e){ rotationManager(e); }) - + canvas3.addEventListener("mousedown",function(e){ mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; }) - + canvas3.addEventListener("mouseup",function(e){ rotationManager(e); }) - + canvas4.addEventListener("mousedown",function(e){ mousePos = [e.currentTarget.id.substring(6),compas(e.clientX,e.clientY,e.currentTarget)]; }) - + canvas4.addEventListener("mouseup",function(e){ rotationManager(e); }) @@ -283,7 +326,7 @@ tab2.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]); tab3.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]); tab4.push([-3,-3,"green"],[-3,2,"red"],[1,2,"blue"],[3,-3,"brown"]); - + toutDessiner(tab1,canvas1,ctx); toutDessiner(tab2,canvas2,ctx2); toutDessiner(tab3,canvas3,ctx3);