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
const pathImg = "../img/";
const imageLogiqueEt = "eee.png";
const imageLogiqueEt = "eeee.png";
const imageLogiqueOu = "logiqueou.png";
const imageLogiqueEtNon = "logiqueetnon.png";
const imageLogiqueInv = "non.png";

@ -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();
}
}

@ -35,6 +35,9 @@ function createGame2() {
timeEnd = 40;
colonneTot = 3;
numberPerColonne = [1,1,3];
initTimer();
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() {
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);
}

@ -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") {

@ -63,7 +63,7 @@
</div>
<div id="play-container"></div>
<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");
if(niveauActuel == null){

Loading…
Cancel
Save