You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
4.8 KiB

function initAll() {
darkMode();
setLang("fr");
dysFont();
}
var mobile = false;
var switchs = [], lineCount = [], logiques = [], lines = [], endLines = [], end, switchsInfo = [], switchsInfoCopy = [], lineRemove = [];
var width = window.innerWidth - window.innerWidth / 100 * 30;
var height = window.innerHeight /2.5;
var stage = new Konva.Stage({
container: 'setting_container',
width: width,
height: height,
});
var layer = new Konva.Layer();
tutoCreateLayer();
function tutoCreateLayer() {
isTuto = true;
width = window.innerWidth - window.innerWidth / 100 * 30;
height = window.innerHeight /2.5;
stage = new Konva.Stage({
container: 'setting_container',
width: width,
height: height,
});
stage.add(layer);
colonneTot = 1;
numberPerColonne = [1];
var logiqueCount = 0;
for (let i = 0; i < colonneTot; i++) {
liveColonneNumber.push([]);
}
insertLogiqueColonne("logique1", "et", 0);
calculNombreSwitch();
switchCreator(numberOfSwitch);
createAllLinkSwitch();
initAllSwitch();
createEnd();
initEnd();
}
function resetAllTabs() {
switchs = [], lineCount = [], logiques = [], lines = [], endLines = [], end, switchsInfo = [], switchsInfoCopy = [], lineRemove = [];
width = window.innerWidth - window.innerWidth / 100 * 10;
height = window.innerHeight /1.5;
timeEnd = 5;
numberOfSwitch = 0;
colonneTot = 0;
numberPerColonne = [];
liveColonneNumber = [];
layer.destroyChildren();
}
function gameOne() {
createGameOne(niveauActuel);
}
function createGameOne(niveau){
windowWidth = window.innerWidth;
windowHeight = window.innerHeight ;
var numberColonne1 = 2;
var numberColonne2 = 1;
var isEtNonAllowed = false;
var isOuNonAllowed = false;
switch(niveau){
case 1:
case 2:
timeEnd = 5;
break;
case 3:
case 4:
timeEnd = 4;
break;
case 5:
timeEnd = 3;
break;
case 6:
case 7:
case 8:
isEtNonAllowed = true;
timeEnd = 5;
numberColonne1 = 3;
break;
case 9:
case 10:
case 11:
isEtNonAllowed = true;
timeEnd = 4;
numberColonne1 = 3;
break;
case 12:
case 13:
case 14:
isEtNonAllowed = true;
isOuNonAllowed = true;
timeEnd = 4;
numberColonne1 = 3;
break;
default:
isEtNonAllowed = true;
isOuNonAllowed = true;
timeEnd = 3;
numberColonne1 = 4;
break;
}
timeEnd = 500;
isTuto = false;
stage = new Konva.Stage({
container: 'play_container',
/*rotation: -90,
x: 20,
y: 1000,*/
width: width,
height: height,
});
stage.add(layer);
initTimer();
colonneTot = 2;
numberPerColonne = [numberColonne1,numberColonne2];
var logiqueCount = 0;
for (let i = 0; i < colonneTot; i++) {
liveColonneNumber.push([]);
}
for (let i = 0; i < colonneTot; i++) {
for (let j = 0; j < numberPerColonne[i]; j++) {
logiqueCount++;
let type = null;
switch (getRandomArbitrary(0, 4)) {
case 0:
type = "et";
break;
case 1:
type = "ou";
break;
case 2:
if(isEtNonAllowed){
type = "etnon";
}else{
type = "et";
}
break;
case 3:
if(isOuNonAllowed){
type = "nonou";
}else{
type = "et";
}
break;
}
insertLogiqueColonne("logique" + logiqueCount, type, i);
}
}
logiques.forEach(function (element) {
createLinkAuto(element.name);
});
calculNombreSwitch();
switchCreator(numberOfSwitch);
createAllLinkSwitch();
initAllSwitch();
createEnd();
initEnd();
console.log(layer.scaleX());
checkAllSortieLogique();
}
window.addEventListener('resize', changeStage);
function changeStage(){
if(window.innerWidth <= 900){
console.log("mobile");
if(!mobile){
stage.rotate(90);
stage.x(stage.getX() + stage.height());
mobile = true;
}
}else{
stage.scaleX(window.innerWidth / windowWidth);
console.log(document.querySelector("#play_container").offsetHeight);
stage.scaleY(window.innerHeight / windowHeight);
}
stage.draw();
}