travail sur les croisements des fils

master
pisouvigne 5 years ago
parent bc950714fb
commit e9af81317f

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

@ -5,7 +5,7 @@ var imageRotation = 0;
//Image //Image
const pathImg = "../img/"; const pathImg = "../img/";
const imageLogiqueEt = "eee.png"; const imageLogiqueEt = "eeee.png";
const imageLogiqueOu = "logiqueou.png"; const imageLogiqueOu = "logiqueou.png";
const imageLogiqueEtNon = "logiqueetnon.png"; const imageLogiqueEtNon = "logiqueetnon.png";
const imageLogiqueInv = "non.png"; const imageLogiqueInv = "non.png";

@ -225,18 +225,40 @@ function createLinkSwitch(){
}); });
var distanceSwitch = stage.height(); var distanceSwitch = stage.height();
var switchs = null; var switchs = null;
if(switchsInfo.length > 0){
switchsInfo.forEach(function(element){ switchsInfo.forEach(function(element){
if(Math.abs(logique.y - element.y) < distanceSwitch){ if(Math.abs(logique.y - element.y) < distanceSwitch){
distanceSwitch = Math.abs(logique.y - element.y); distanceSwitch = Math.abs(logique.y - element.y);
switchs = element; 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 ); switchsInfo.splice( switchsInfo.indexOf(switchs), 1 );
createLink(stage.findOne("#"+switchs.id), findLogique(logique.name)); 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(){ function createAllLinkSwitch(){
for(let i = 0;i < numberOfSwitch; i++){ while(getNumberOfSwitchEmpty() > 0){
createLinkSwitch(); createLinkSwitch();
} }
} }

@ -35,6 +35,9 @@ function createGame2() {
timeEnd = 40; timeEnd = 40;
colonneTot = 3;
numberPerColonne = [1,1,3];
initTimer(); initTimer();
switchCreator(7); switchCreator(7);

@ -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() { function initEnd() {
var listeLogique = [];
let countLogique = 0; let countLogique = 0;
logiques.forEach(function (element) { logiques.forEach(function (element) {
if(element.id3 == null){ if(element.id3 == null){
countLogique++; countLogique++;
listeLogique.push(element);
} }
}); });
listeLogique.sort(compareLogiqueForEnd);
end.position = countLogique; end.position = countLogique;
end.let = countLogique; end.let = countLogique;
logiques.forEach(function (element) { listeLogique.forEach(function (element) {
if(element.id3 == null){ if(element.id3 == null){
createLink(element,end); createLink(element,end);
} }

@ -8,12 +8,40 @@ function findLogique(logiqueId) {
return elem; 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) { function giveLineId(logiqueId,entre) {
var newEntre = entre; var newEntre = entre;
isSwitch = false;
if(entre.id !== undefined){ if(entre.id !== undefined){
switchsInfoCopy.forEach(function(element){ switchsInfoCopy.forEach(function(element){
if(entre.id() == element.id){ if(entre.id() == element.id){
isSwitch = true;
newEntre = element; newEntre = element;
} }
}); });
@ -30,10 +58,14 @@ function giveLineId(logiqueId,entre) {
if (logique.id1 == null) { if (logique.id1 == null) {
lineId = "id1"; lineId = "id1";
} else if (logique.id2 == null) { } else if (logique.id2 == null) {
if(isSwitch){
if(giveSwitchYWithLineId(logique.id1) > entre.getY()){
lineRemove.push([entre, "switch"]);
}else{
lineId = "id2"; lineId = "id2";
} }
}
}
} }
}else{ }else{
if (logique.type === "inv") { if (logique.type === "inv") {

@ -63,7 +63,7 @@
</div> </div>
<div id="play-container"></div> <div id="play-container"></div>
<script> <script>
var switchs = [], lineCount = [], logiques = [],lines = [], endLines = [],end, switchsInfo= [], switchsInfoCopy = []; var switchs = [], lineCount = [], logiques = [],lines = [], endLines = [],end, switchsInfo= [], switchsInfoCopy = [],lineRemove = [];
var niveauActuel = localStorage.getItem("niveau"); var niveauActuel = localStorage.getItem("niveau");
if(niveauActuel == null){ if(niveauActuel == null){

Loading…
Cancel
Save