diff --git a/site/img/eeee.png b/site/img/eeee.png new file mode 100644 index 0000000..f8477b5 Binary files /dev/null and b/site/img/eeee.png differ diff --git a/site/js/const.js b/site/js/const.js index 3c0435d..28a9633 100644 --- a/site/js/const.js +++ b/site/js/const.js @@ -5,7 +5,7 @@ var imageRotation = 0; //Image const pathImg = "../img/"; -const imageLogiqueEt = "eee.png"; +const imageLogiqueEt = "eeee.png"; const imageLogiqueOu = "logiqueou.png"; const imageLogiqueEtNon = "logiqueetnon.png"; const imageLogiqueInv = "non.png"; diff --git a/site/js/createElement.js b/site/js/createElement.js index a6d7e6c..a0d6892 100644 --- a/site/js/createElement.js +++ b/site/js/createElement.js @@ -225,18 +225,40 @@ function createLinkSwitch(){ }); var distanceSwitch = stage.height(); var switchs = null; - switchsInfo.forEach(function(element){ - if(Math.abs(logique.y - element.y) < distanceSwitch){ - distanceSwitch = Math.abs(logique.y - element.y); - switchs = element; - } - }); + if(switchsInfo.length > 0){ + switchsInfo.forEach(function(element){ + if(Math.abs(logique.y - element.y) < distanceSwitch){ + distanceSwitch = Math.abs(logique.y - element.y); + switchs = element; + } + }); + } + else { + switchsInfoCopy.forEach(function(element){ + if(stage.findOne("#"+element.id).id3 == null){ + if(Math.abs(logique.y - element.y) < distanceSwitch){ + distanceSwitch = Math.abs(logique.y - element.y); + switchs = element; + } + } + }); + } + switchsInfo.splice( switchsInfo.indexOf(switchs), 1 ); createLink(stage.findOne("#"+switchs.id), findLogique(logique.name)); } +function getNumberOfSwitchEmpty(){ + let number = 0; + switchsInfoCopy.forEach(function(element){ + if(stage.findOne("#"+element.id).id3 == null) + number++; + }); + return number; +} + function createAllLinkSwitch(){ - for(let i = 0;i < numberOfSwitch; i++){ + while(getNumberOfSwitchEmpty() > 0){ createLinkSwitch(); } } diff --git a/site/js/creator.js b/site/js/creator.js index 0719c16..a5645ec 100644 --- a/site/js/creator.js +++ b/site/js/creator.js @@ -35,6 +35,9 @@ function createGame2() { timeEnd = 40; + colonneTot = 3; + numberPerColonne = [1,1,3]; + initTimer(); switchCreator(7); diff --git a/site/js/init.js b/site/js/init.js index 0e63d02..47e74e8 100644 --- a/site/js/init.js +++ b/site/js/init.js @@ -24,16 +24,27 @@ function initLayer() { } +function compareLogiqueForEnd(a,b){ + if(a.y > b.y) + return -1; + if(a.y < b.y) + return 1; + return 0; +} + function initEnd() { + var listeLogique = []; let countLogique = 0; logiques.forEach(function (element) { if(element.id3 == null){ countLogique++; + listeLogique.push(element); } }); + listeLogique.sort(compareLogiqueForEnd); end.position = countLogique; end.let = countLogique; - logiques.forEach(function (element) { + listeLogique.forEach(function (element) { if(element.id3 == null){ createLink(element,end); } diff --git a/site/js/logique.js b/site/js/logique.js index 2c62d5b..231aea9 100644 --- a/site/js/logique.js +++ b/site/js/logique.js @@ -8,12 +8,40 @@ function findLogique(logiqueId) { return elem; } +function giveSwitchYWithLineId(lineId){ + var elementY = null; + switchsInfoCopy.forEach(function(element){ + if(stage.findOne("#"+element.id).id3 == lineId){ + elementY = (element.y); + } + }); + return elementY; +} + +function removeLineFromSwitch(lineId){ + switchsInfoCopy.forEach(function(element){ + if(stage.findOne("#"+element.id).id3 == lineId){ + stage.findOne("#"+element.id).id3 = null; + } + }); +} + +function removeLine(lineId){ + //remove from switch + removeLineFromSwitch(lineId); + let line = stage.findOne("#" + lineId); + line.destroy(); + line = stage.findOne("#" + lineId); + +} + function giveLineId(logiqueId,entre) { var newEntre = entre; + isSwitch = false; if(entre.id !== undefined){ switchsInfoCopy.forEach(function(element){ if(entre.id() == element.id){ - + isSwitch = true; newEntre = element; } }); @@ -30,10 +58,14 @@ function giveLineId(logiqueId,entre) { if (logique.id1 == null) { lineId = "id1"; } else if (logique.id2 == null) { - lineId = "id2"; - } - - + if(isSwitch){ + if(giveSwitchYWithLineId(logique.id1) > entre.getY()){ + lineRemove.push([entre, "switch"]); + }else{ + lineId = "id2"; + } + } + } } }else{ if (logique.type === "inv") { diff --git a/site/vues/jeu.html b/site/vues/jeu.html index 29fef4b..6ccc1fb 100644 --- a/site/vues/jeu.html +++ b/site/vues/jeu.html @@ -63,7 +63,7 @@