diff --git a/Doc/algo gen.pages b/Doc/algo gen.pages new file mode 100755 index 0000000..97707e8 Binary files /dev/null and b/Doc/algo gen.pages differ diff --git a/site/vue/js/createElement.js b/site/vue/js/createElement.js index 5d9453b..a18b2f5 100644 --- a/site/vue/js/createElement.js +++ b/site/vue/js/createElement.js @@ -67,6 +67,11 @@ function createLine(points, id) { id: id, tension: tension, }); + var lineObj = { + id: id, + state: false, + }; + lines.push(lineObj); layer.add(line); } diff --git a/site/vue/js/func.js b/site/vue/js/func.js index a5518c6..365c908 100644 --- a/site/vue/js/func.js +++ b/site/vue/js/func.js @@ -190,17 +190,48 @@ function changeLineColor(idLine) { line.stroke(colorline); } +function changeLineState(idLine) { + let line = null; + lines.forEach(function (element) { + if (element.id === idLine) line = element; + }); + var stateLine = line.state == true ? false : true; + line.state = stateLine; +} + +function setLineStateTrue(lineId) { + lines.forEach(function (line) { + if (line.id == lineId) line.state = true; + }); +} + +function setLineStateFalse(lineId) { + lines.forEach(function (line) { + if (line.id == lineId) line.state = false; + }); +} + +function getLineState(lineId) { + var state = null; + lines.forEach(function (line) { + if (line.id == lineId) state = line.state; + }); + return state; +} + function changeLineColorInput(idLine, color) { let line = stage.findOne("#" + idLine); line.stroke(color); } function changeLineColorBlack(idLine) { + setLineStateFalse(idLine); let line = stage.findOne("#" + idLine); line.stroke(colorLineInnactive); } function changeLineColorYellow(idLine) { + setLineStateTrue(idLine); let line = stage.findOne("#" + idLine); line.stroke(colorLineActive); } @@ -314,24 +345,26 @@ function checkSortieLogique(logiqueId) { let line1State, line2State; let id1Color = stage.findOne("#" + element.id1).stroke(); if (element.type !== "inv") { - let id2Color = stage.findOne("#" + element.id2).stroke(); + line2State = getLineState(element.id2); + /*let id2Color = stage.findOne("#" + element.id2).stroke(); if (id2Color == colorLineInnactive) { line2State = false; } else { line2State = true; - } + }*/ } - - if (id1Color == colorLineInnactive) { + line1State = getLineState(element.id1); + /*if (id1Color == colorLineInnactive) { line1State = false; } else { line1State = true; - } + }*/ switch (logique.type) { case "et": if (line1State == true && line2State == true) { element.id3.forEach(function (line) { + console.log("oui"); changeLineColorYellow(line); }); } else { @@ -412,6 +445,29 @@ function isLineCollapsing() { return isCollapsing; } +function getLogiqueByLine(idLine) { + var logique = null; + logiques.forEach(function (element) { + if (element.id1 === idLine || element.id2 === idLine) logique = element; + }); + return logique; +} + +function updateLines(logique) { + if (logique !== null) { + checkSortieLogique(logique.name); + logique.id3.forEach(function (line) { + updateLines(getLogiqueByLine(line)); + }); + } +} + +function lineUpdate(swithId) { + var lineId = getSwitchById(swithId).id3; + var currLogique = getLogiqueByLine(lineId[0]); + updateLines(currLogique); +} + function getRandomArbitrary(min, max) { return Math.floor(Math.random() * (max - min) + min); } @@ -431,11 +487,11 @@ function checkLineSwitch(switchId) { } function activeSwitch(idSwitch) { - getSwitchById(idSwitch); var switche = getSwitchById(idSwitch); changeSwitchColor(switche.id); switche.id3.forEach(function (element) { changeLineColor(element); + changeLineState(element); }); } diff --git a/site/vue/js/init.js b/site/vue/js/init.js index 5966dcc..a6d3584 100644 --- a/site/vue/js/init.js +++ b/site/vue/js/init.js @@ -5,8 +5,8 @@ function initAllSwitch(mode) { switche.on('click touchstart', function () { click++; activeSwitch(switche.id()); - checkAllSortieLogique(); layer.draw(); + lineUpdate(element); checkEnd(mode); }); switche.on('mouseover', function () { diff --git a/site/vue/js/timer.js b/site/vue/js/timer.js index 282d000..3032444 100644 --- a/site/vue/js/timer.js +++ b/site/vue/js/timer.js @@ -31,6 +31,9 @@ var timer = new easytimer.Timer(); timer.start(); timer.addEventListener('secondsUpdated', function (e) { if (timer.getTimeValues().seconds <= timeEnd) { + switchs.forEach(function (element) { + lineUpdate(element); + }); move(); } else { @@ -39,6 +42,7 @@ timer.addEventListener('secondsUpdated', function (e) { timer.stop(); } }); + function endTime() { if (!isTuto) { closeGame(); @@ -57,8 +61,7 @@ function endTime() { document.querySelector("#star1").style.color = "#fe8a71"; document.querySelector("#star2").style.color = "#fe8a71"; document.querySelector("#star3").style.color = "#fe8a71"; - } - else if (score > 200 || score < 400) { + } else if (score > 200 || score < 400) { document.querySelector("#star1").style.color = "#fe8a71"; document.querySelector("#star2").style.color = "#fe8a71"; document.querySelector("#star3").style.color = "#fe8a71"; @@ -80,4 +83,4 @@ function resetStar() { document.querySelector("#star3").style.color = document.body.style.color; document.querySelector("#star4").style.color = document.body.style.color; document.querySelector("#star5").style.color = document.body.style.color; -} +} \ No newline at end of file