parcour pour changer les fils de couleurs

master
pisouvigne 5 years ago
parent 02914539ed
commit 6b61d8ef1b

Binary file not shown.

@ -67,6 +67,11 @@ function createLine(points, id) {
id: id, id: id,
tension: tension, tension: tension,
}); });
var lineObj = {
id: id,
state: false,
};
lines.push(lineObj);
layer.add(line); layer.add(line);
} }

@ -190,17 +190,48 @@ function changeLineColor(idLine) {
line.stroke(colorline); 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) { function changeLineColorInput(idLine, color) {
let line = stage.findOne("#" + idLine); let line = stage.findOne("#" + idLine);
line.stroke(color); line.stroke(color);
} }
function changeLineColorBlack(idLine) { function changeLineColorBlack(idLine) {
setLineStateFalse(idLine);
let line = stage.findOne("#" + idLine); let line = stage.findOne("#" + idLine);
line.stroke(colorLineInnactive); line.stroke(colorLineInnactive);
} }
function changeLineColorYellow(idLine) { function changeLineColorYellow(idLine) {
setLineStateTrue(idLine);
let line = stage.findOne("#" + idLine); let line = stage.findOne("#" + idLine);
line.stroke(colorLineActive); line.stroke(colorLineActive);
} }
@ -314,24 +345,26 @@ function checkSortieLogique(logiqueId) {
let line1State, line2State; let line1State, line2State;
let id1Color = stage.findOne("#" + element.id1).stroke(); let id1Color = stage.findOne("#" + element.id1).stroke();
if (element.type !== "inv") { 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) { if (id2Color == colorLineInnactive) {
line2State = false; line2State = false;
} else { } else {
line2State = true; line2State = true;
} }*/
} }
line1State = getLineState(element.id1);
if (id1Color == colorLineInnactive) { /*if (id1Color == colorLineInnactive) {
line1State = false; line1State = false;
} else { } else {
line1State = true; line1State = true;
} }*/
switch (logique.type) { switch (logique.type) {
case "et": case "et":
if (line1State == true && line2State == true) { if (line1State == true && line2State == true) {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
console.log("oui");
changeLineColorYellow(line); changeLineColorYellow(line);
}); });
} else { } else {
@ -412,6 +445,29 @@ function isLineCollapsing() {
return isCollapsing; 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) { function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min); return Math.floor(Math.random() * (max - min) + min);
} }
@ -431,11 +487,11 @@ function checkLineSwitch(switchId) {
} }
function activeSwitch(idSwitch) { function activeSwitch(idSwitch) {
getSwitchById(idSwitch);
var switche = getSwitchById(idSwitch); var switche = getSwitchById(idSwitch);
changeSwitchColor(switche.id); changeSwitchColor(switche.id);
switche.id3.forEach(function (element) { switche.id3.forEach(function (element) {
changeLineColor(element); changeLineColor(element);
changeLineState(element);
}); });
} }

@ -5,8 +5,8 @@ function initAllSwitch(mode) {
switche.on('click touchstart', function () { switche.on('click touchstart', function () {
click++; click++;
activeSwitch(switche.id()); activeSwitch(switche.id());
checkAllSortieLogique();
layer.draw(); layer.draw();
lineUpdate(element);
checkEnd(mode); checkEnd(mode);
}); });
switche.on('mouseover', function () { switche.on('mouseover', function () {

@ -31,6 +31,9 @@ var timer = new easytimer.Timer();
timer.start(); timer.start();
timer.addEventListener('secondsUpdated', function (e) { timer.addEventListener('secondsUpdated', function (e) {
if (timer.getTimeValues().seconds <= timeEnd) { if (timer.getTimeValues().seconds <= timeEnd) {
switchs.forEach(function (element) {
lineUpdate(element);
});
move(); move();
} else { } else {
@ -39,6 +42,7 @@ timer.addEventListener('secondsUpdated', function (e) {
timer.stop(); timer.stop();
} }
}); });
function endTime() { function endTime() {
if (!isTuto) { if (!isTuto) {
closeGame(); closeGame();
@ -57,8 +61,7 @@ function endTime() {
document.querySelector("#star1").style.color = "#fe8a71"; document.querySelector("#star1").style.color = "#fe8a71";
document.querySelector("#star2").style.color = "#fe8a71"; document.querySelector("#star2").style.color = "#fe8a71";
document.querySelector("#star3").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("#star1").style.color = "#fe8a71";
document.querySelector("#star2").style.color = "#fe8a71"; document.querySelector("#star2").style.color = "#fe8a71";
document.querySelector("#star3").style.color = "#fe8a71"; document.querySelector("#star3").style.color = "#fe8a71";

Loading…
Cancel
Save