master
pisouvigne 5 years ago
parent 856a27dc46
commit a7503bbdb3

@ -35,6 +35,10 @@
<a>Personnalisé</a> <a>Personnalisé</a>
<i class="fa fa-arrow-right" id="right_select" aria-hidden="true"></i> <i class="fa fa-arrow-right" id="right_select" aria-hidden="true"></i>
</div> </div>
<div class="border background dys listenerHover" onclick="wait('test', this)">
<a>Test Nouveau Générateur</a>
<i class="fa fa-arrow-right" id="right_select" aria-hidden="true"></i>
</div>
<div class="border background dys listenerHover"> <div class="border background dys listenerHover">
<a>Caméléon</a> <a>Caméléon</a>
<i class="fa fa-arrow-right" id="right_select" aria-hidden="true"></i> <i class="fa fa-arrow-right" id="right_select" aria-hidden="true"></i>
@ -508,10 +512,7 @@
<script src="js/db.js"></script> <script src="js/db.js"></script>
<script src="js/generateGame.js"></script> <script src="js/generateGame.js"></script>
<script> <script>
generate2();
initAll(); initAll();
</script> </script>

@ -1,10 +1,10 @@
function openModal(modalId) { function openModal(modalId) {
var modal = document.getElementById(modalId); var modal = document.getElementById(modalId);
modal.style.display = "block"; modal.style.display = "block";
} }
function closeModal(modal) { function closeModal(modal) {
var modal = document.getElementById(modal); var modal = document.getElementById(modal);
modal.style.display = "none"; modal.style.display = "none";
@ -13,8 +13,7 @@ function closeModal(modal) {
function showBarTimer(checkbox) { function showBarTimer(checkbox) {
if (checkbox.checked == true) { if (checkbox.checked == true) {
document.getElementById("progress_bar").style.display = 'block'; document.getElementById("progress_bar").style.display = 'block';
} } else {
else {
document.getElementById("progress_bar").style.display = 'none'; document.getElementById("progress_bar").style.display = 'none';
} }
} }
@ -23,8 +22,7 @@ function darkMode() {
var checkbox = document.getElementById("darkcheck"); var checkbox = document.getElementById("darkcheck");
if (checkbox.checked == true) { if (checkbox.checked == true) {
setColor("black"); setColor("black");
} } else {
else {
setColor("white"); setColor("white");
} }
} }
@ -32,8 +30,7 @@ function darkMode() {
function symbole(checkbox) { function symbole(checkbox) {
if (checkbox.checked == true) { if (checkbox.checked == true) {
pathImg = "img/sym/"; pathImg = "img/sym/";
} } else {
else {
pathImg = "img/txt_en/"; pathImg = "img/txt_en/";
} }
saveStage(); saveStage();
@ -45,8 +42,7 @@ function dysFont() {
var font; var font;
if (checkbox.checked == true) { if (checkbox.checked == true) {
font = "dys"; font = "dys";
} } else {
else {
font = "main"; font = "main";
} }
textToChange.forEach(function (item) { textToChange.forEach(function (item) {
@ -135,8 +131,7 @@ function setLang(newLang) {
}); });
document.querySelector(".img_france").style.opacity = 1; document.querySelector(".img_france").style.opacity = 1;
document.querySelector(".img_usa").style.opacity = 0.2; document.querySelector(".img_usa").style.opacity = 0.2;
} } else {
else {
textToChange.forEach(function (item) { textToChange.forEach(function (item) {
let currText = item.id; let currText = item.id;
document.getElementById(currText).innerHTML = lang.en[currText]; document.getElementById(currText).innerHTML = lang.en[currText];
@ -145,6 +140,7 @@ function setLang(newLang) {
document.querySelector(".img_usa").style.opacity = 1; document.querySelector(".img_usa").style.opacity = 1;
} }
} }
function calculNombreSwitch() { function calculNombreSwitch() {
var entrelibre = 0; var entrelibre = 0;
logiques.forEach(function (element) { logiques.forEach(function (element) {
@ -158,6 +154,7 @@ function calculNombreSwitch() {
}); });
numberOfSwitch = entrelibre; numberOfSwitch = entrelibre;
} }
function whatIsElement(element) { function whatIsElement(element) {
if (findLogique(element.name) == null || findLogique(element.name) == undefined) { if (findLogique(element.name) == null || findLogique(element.name) == undefined) {
return "switch"; return "switch";
@ -192,14 +189,17 @@ function changeLineColor(idLine) {
var colorline = line.stroke() == colorLineActive ? colorLineInnactive : colorLineActive; var colorline = line.stroke() == colorLineActive ? colorLineInnactive : colorLineActive;
line.stroke(colorline); line.stroke(colorline);
} }
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) {
let line = stage.findOne("#" + idLine); let line = stage.findOne("#" + idLine);
line.stroke(colorLineInnactive); line.stroke(colorLineInnactive);
} }
function changeLineColorYellow(idLine) { function changeLineColorYellow(idLine) {
let line = stage.findOne("#" + idLine); let line = stage.findOne("#" + idLine);
line.stroke(colorLineActive); line.stroke(colorLineActive);
@ -260,8 +260,7 @@ function checkEntreCroisement(logiqueId) {
createLink(logique1, logique); createLink(logique1, logique);
createLink(logique2, logique); createLink(logique2, logique);
} } else if (getSwitchFromLine(logique.id1) != null && getLogiqueFromLine(logique.id2) != null) {
else if (getSwitchFromLine(logique.id1) != null && getLogiqueFromLine(logique.id2) != null) {
let logique1 = getLogiqueFromLine(logique.id2); let logique1 = getLogiqueFromLine(logique.id2);
let switch1 = getSwitchFromLine(logique.id1).id; let switch1 = getSwitchFromLine(logique.id1).id;
removeLine(logique.id1); removeLine(logique.id1);
@ -270,8 +269,7 @@ function checkEntreCroisement(logiqueId) {
logique.id2 = null; logique.id2 = null;
createLink(logique1, logique); createLink(logique1, logique);
createLink(stage.findOne("#" + switch1), logique); createLink(stage.findOne("#" + switch1), logique);
} } else if (getLogiqueFromLine(logique.id1) != null && getSwitchFromLine(logique.id2) != null) {
else if (getLogiqueFromLine(logique.id1) != null && getSwitchFromLine(logique.id2) != null) {
let logique1 = getLogiqueFromLine(logique.id1); let logique1 = getLogiqueFromLine(logique.id1);
let switch1 = getSwitchFromLine(logique.id2).id; let switch1 = getSwitchFromLine(logique.id2).id;
removeLine(logique.id1); removeLine(logique.id1);
@ -280,8 +278,7 @@ function checkEntreCroisement(logiqueId) {
logique.id2 = null; logique.id2 = null;
createLink(stage.findOne("#" + switch1), logique); createLink(stage.findOne("#" + switch1), logique);
createLink(logique1, logique); createLink(logique1, logique);
} } else {
else {
croisement = true; croisement = true;
} }
@ -337,8 +334,7 @@ function checkSortieLogique(logiqueId) {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorYellow(line); changeLineColorYellow(line);
}); });
} } else {
else {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorBlack(line); changeLineColorBlack(line);
}); });
@ -349,8 +345,7 @@ function checkSortieLogique(logiqueId) {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorYellow(line); changeLineColorYellow(line);
}); });
} } else {
else {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorBlack(line); changeLineColorBlack(line);
}); });
@ -361,8 +356,7 @@ function checkSortieLogique(logiqueId) {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorYellow(line); changeLineColorYellow(line);
}); });
} } else {
else {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorBlack(line); changeLineColorBlack(line);
}); });
@ -373,8 +367,7 @@ function checkSortieLogique(logiqueId) {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorBlack(line); changeLineColorBlack(line);
}); });
} } else {
else {
element.id3.forEach(function (line) { element.id3.forEach(function (line) {
changeLineColorYellow(line); changeLineColorYellow(line);
}); });
@ -467,7 +460,9 @@ function checkEnd(mode) {
} }
}); });
if (ter && !isTuto) { if (ter && !isTuto) {
setTimeout(() => { success(mode); }, 100); setTimeout(() => {
success(mode);
}, 100);
} }
} }
@ -479,7 +474,10 @@ function success(mode) {
if (successPanel) { if (successPanel) {
openModal("success"); openModal("success");
document.querySelector("#click_number").innerHTML = click; document.querySelector("#click_number").innerHTML = click;
document.querySelector("#next_level_button").onclick = function () { closeModal('success'); nextLevel(mode); } document.querySelector("#next_level_button").onclick = function () {
closeModal('success');
nextLevel(mode);
}
var previewStage = new Konva.Stage({ var previewStage = new Konva.Stage({
container: 'show_stage', container: 'show_stage',
width: window.innerWidth / 1.5, width: window.innerWidth / 1.5,
@ -487,11 +485,15 @@ function success(mode) {
scaleX: 1 / 1.5, scaleX: 1 / 1.5,
scaleY: 1 / 1.5 scaleY: 1 / 1.5
}); });
let previewLayer = layer.clone({ hitGraphEnabled: false }); let previewLayer = layer.clone({
hitGraphEnabled: false
});
previewStage.add(previewLayer); previewStage.add(previewLayer);
previewLayer.batchDraw(); previewLayer.batchDraw();
} else { } else {
setTimeout(() => { nextLevel(mode); }, 1000); setTimeout(() => {
nextLevel(mode);
}, 1000);
} }
} }
@ -526,22 +528,29 @@ function calculNombreSwitch() {
function resize() { function resize() {
stage.scale({ x: 1, y: 1 }); stage.scale({
x: 1,
y: 1
});
stage.draw(); stage.draw();
} }
function activeSwitchInput(event) { function activeSwitchInput(event) {
changeAllSwitchColorActive(event.target.value); changeAllSwitchColorActive(event.target.value);
} }
function inactiveSwitchInput(event) { function inactiveSwitchInput(event) {
changeAllSwitchColorInActive(event.target.value); changeAllSwitchColorInActive(event.target.value);
} }
function activeLineInput(event) { function activeLineInput(event) {
changeAllLineColorActive(event.target.value); changeAllLineColorActive(event.target.value);
} }
function inactiveLineInput(event) { function inactiveLineInput(event) {
changeAllLineColorInActive(event.target.value); changeAllLineColorInActive(event.target.value);
} }
function inactiveEndInput(event) { function inactiveEndInput(event) {
changeEndColorInActive(event.target.value); changeEndColorInActive(event.target.value);
} }
@ -562,11 +571,13 @@ function changeAllSwitchColorActive(color) {
colorSwitchActiveBackground = color; colorSwitchActiveBackground = color;
layer.draw(); layer.draw();
} }
function changeEndColorInActive(color) { function changeEndColorInActive(color) {
colorEnd = color; colorEnd = color;
stage.findOne("#end").fill(color); stage.findOne("#end").fill(color);
layer.draw(); layer.draw();
} }
function changeAllSwitchColorInActive(color) { function changeAllSwitchColorInActive(color) {
switchsInfoCopy.forEach(function (element) { switchsInfoCopy.forEach(function (element) {
var switche = stage.findOne("#" + element.id); var switche = stage.findOne("#" + element.id);
@ -594,6 +605,7 @@ function changeAllLineColorActive(color) {
colorLineActive = color; colorLineActive = color;
layer.draw(); layer.draw();
} }
function changeAllLineColorInActive(color) { function changeAllLineColorInActive(color) {
var line1 = stage.findOne("#line2"); var line1 = stage.findOne("#line2");
var line2 = stage.findOne("#line3"); var line2 = stage.findOne("#line3");
@ -610,9 +622,11 @@ function changeAllLineColorInActive(color) {
colorLineInnactive = color; colorLineInnactive = color;
layer.draw(); layer.draw();
} }
function hideDiv(div) { function hideDiv(div) {
div.style.display = 'none'; div.style.display = 'none';
} }
function showDiv(div) { function showDiv(div) {
if (div.id == "levelSelectionPage") { if (div.id == "levelSelectionPage") {
document.querySelectorAll("#right_select").forEach(function (element) { document.querySelectorAll("#right_select").forEach(function (element) {
@ -626,11 +640,13 @@ function play() {
hideDiv(document.querySelector("#mainPage")); hideDiv(document.querySelector("#mainPage"));
showDiv(document.querySelector("#levelSelectionPage")); showDiv(document.querySelector("#levelSelectionPage"));
} }
function modePerso() { function modePerso() {
document.querySelector("#generate_button_perso").childNodes[3].classList = "fa fa-arrow-right"; document.querySelector("#generate_button_perso").childNodes[3].classList = "fa fa-arrow-right";
hideDiv(document.querySelector("#levelSelectionPage")); hideDiv(document.querySelector("#levelSelectionPage"));
showDiv(document.querySelector("#PersoSetupPage")); showDiv(document.querySelector("#PersoSetupPage"));
} }
function playNormal() { function playNormal() {
hideDiv(document.querySelector("#levelSelectionPage")); hideDiv(document.querySelector("#levelSelectionPage"));
showDiv(document.querySelector("#playPage")); showDiv(document.querySelector("#playPage"));
@ -638,6 +654,7 @@ function playNormal() {
timeTot = 0; timeTot = 0;
launchGameOne(); launchGameOne();
} }
function modeTuto() { function modeTuto() {
hideDiv(document.querySelector("#levelSelectionPage")); hideDiv(document.querySelector("#levelSelectionPage"));
showDiv(document.querySelector("#playPage")); showDiv(document.querySelector("#playPage"));
@ -645,6 +662,15 @@ function modeTuto() {
timeTot = 0; timeTot = 0;
launchTuto(); launchTuto();
} }
function modeTest() {
hideDiv(document.querySelector("#levelSelectionPage"));
showDiv(document.querySelector("#playPage"));
niveauActuel = 1;
timeTot = 0;
launchTest();
}
function wait(mode, btn) { function wait(mode, btn) {
var time = 300; var time = 300;
spin(btn); spin(btn);
@ -658,6 +684,9 @@ function wait(mode, btn) {
case "tuto": case "tuto":
setTimeout(modeTuto, time); setTimeout(modeTuto, time);
break; break;
case "test":
setTimeout(modeTest, time);
break;
} }
} }
@ -685,6 +714,7 @@ function colonne_check_setup(value) {
} }
refresh_input(); refresh_input();
} }
function refresh_input() { function refresh_input() {
document.querySelector("#colonne_number_setup_global").value = "0"; document.querySelector("#colonne_number_setup_global").value = "0";
document.querySelectorAll(".input_refresh").forEach(function (element) { document.querySelectorAll(".input_refresh").forEach(function (element) {
@ -718,6 +748,7 @@ function launchGameOne() {
resetAllTabs(false); resetAllTabs(false);
gameOne(); gameOne();
} }
function launchTuto() { function launchTuto() {
document.querySelector(".niveau").innerHTML = niveauActuel; document.querySelector(".niveau").innerHTML = niveauActuel;
timer.stop(); timer.stop();
@ -726,6 +757,14 @@ function launchTuto() {
tuto(); tuto();
} }
function launchTest() {
document.querySelector(".niveau").innerHTML = niveauActuel;
timer.stop();
timer.reset();
resetAllTabs(false);
generate2();
}
function clearArray(arr) { function clearArray(arr) {
while (arr.length > 0) { while (arr.length > 0) {
arr.pop(); arr.pop();
@ -745,11 +784,13 @@ function closeSelection() {
showDiv(document.querySelector("#mainPage")); showDiv(document.querySelector("#mainPage"));
hideDiv(document.querySelector("#levelSelectionPage")); hideDiv(document.querySelector("#levelSelectionPage"));
} }
function closePerso() { function closePerso() {
showDiv(document.querySelector("#levelSelectionPage")); showDiv(document.querySelector("#levelSelectionPage"));
hideDiv(document.querySelector("#PersoSetupPage")); hideDiv(document.querySelector("#PersoSetupPage"));
} }
var rotated = false; var rotated = false;
function flip() { function flip() {
document.querySelectorAll(".fa").forEach(function (element) { document.querySelectorAll(".fa").forEach(function (element) {
deg = rotated ? 0 : 360; deg = rotated ? 0 : 360;

@ -31,6 +31,7 @@ function generate_perso_level() {
createLinkAuto(element.name); createLinkAuto(element.name);
}); });
initEndGame(); initEndGame();
timer.stop(); timer.stop();
} }
@ -38,7 +39,13 @@ function generate_perso_level() {
function loadPerso() { function loadPerso() {
arrayPorte = [[document.querySelector("#logique1").checked, "et"], [document.querySelector("#logique2").checked, "ou"], [document.querySelector("#logique3").checked, "inv"], [document.querySelector("#logique4").checked, "etnon"], [document.querySelector("#logique5").checked, "nonou"]]; arrayPorte = [
[document.querySelector("#logique1").checked, "et"],
[document.querySelector("#logique2").checked, "ou"],
[document.querySelector("#logique3").checked, "inv"],
[document.querySelector("#logique4").checked, "etnon"],
[document.querySelector("#logique5").checked, "nonou"]
];
document.querySelector("#PersoSetupPage").style.display = 'none'; document.querySelector("#PersoSetupPage").style.display = 'none';
document.querySelector("#playPage").style.display = 'block'; document.querySelector("#playPage").style.display = 'block';
resetAllTabs(false); resetAllTabs(false);
@ -63,7 +70,9 @@ function loadPerso() {
numberPerColonne.push(parseInt(element.value)); numberPerColonne.push(parseInt(element.value));
}); });
} }
arrayPorte = arrayPorte.filter(function (e) { if (e[0] === true) return e; }) arrayPorte = arrayPorte.filter(function (e) {
if (e[0] === true) return e;
})
generate_perso_level(); generate_perso_level();
isLineCollapsing() isLineCollapsing()
click = 0; click = 0;
@ -82,13 +91,17 @@ function loadPerso() {
if (error) { if (error) {
document.location.reload(true); document.location.reload(true);
} }
} }
function spin(button) { function spin(button) {
button.childNodes[3].classList = "fa fa-spinner"; button.childNodes[3].classList = "fa fa-spinner";
} }
function stopspin(button) { function stopspin(button) {
button.childNodes[3].classList = "fa fa-arrow-right"; button.childNodes[3].classList = "fa fa-arrow-right";
} }
function buttonSpin(button) { function buttonSpin(button) {
spin(document.querySelector("#generate_button_perso")); spin(document.querySelector("#generate_button_perso"));
setTimeout(loadPerso, 1000); setTimeout(loadPerso, 1000);
@ -181,7 +194,7 @@ function createGameOne(niveau) {
numberColonne2 = 1; numberColonne2 = 1;
timeEnd = 20; timeEnd = 20;
break; break;
//Fin premiere serie //Fin premiere serie
case 5: case 5:
firstTime.push("inv"); firstTime.push("inv");
isNotAllowed = true; isNotAllowed = true;
@ -301,19 +314,33 @@ function createGameOne(niveau) {
function generate2() { function generate2() {
var matchs = [[3, 2], [2, 2]]; var matchs = [
var fork = [[2, 1], [1, 1]]; [3, 2],
[2, 2]
];
var fork = [
[2, 1],
[1, 1]
];
var numberCol = 3; var numberCol = 3;
var numberPerCol = [5, 3, 2]; var numberPerCol = [5, 3, 2];
colonneTot = 3;
numberPerColonne = [5, 3, 2];
var compt = new Array(); var compt = new Array();
var listeSame = [];
let num = 1;
//attribution //attribution
for (let i = numberCol; i > 0; i--) { for (let i = numberCol; i > 0; i--) {
let num = 1;
matchs.forEach(function (element) { matchs.forEach(function (element) {
if (element[0] == i) { if (element[0] == i) {
for (let j = 0; j < element[1]; j++) { for (let j = 0; j < element[1]; j++) {
compt.push([i, "same" + num]); compt.push([i, "same" + num]);
numberPerCol[i - 1]--; numberPerCol[i - 1]--;
listeSame.push(["same" + num, null]);
} }
num++; num++;
} }
@ -334,7 +361,6 @@ function generate2() {
id2: null, id2: null,
id3: null, id3: null,
matchId1: null, matchId1: null,
matchId2: null,
type: null, type: null,
}); });
} else { } else {
@ -345,13 +371,71 @@ function generate2() {
id2: null, id2: null,
id3: null, id3: null,
matchId1: element[1], matchId1: element[1],
matchId2: null,
type: null, type: null,
}); });
} }
i++; i++;
}); });
console.log(listeLogiqueObj); //Attribution des types
//num = liste de comptatibilité
let num2 = getRandomArbitrary(0, 3);
for (x in compt) {
if (listeLogiqueObj[x].matchId1 !== null) {
if (getElementArray(listeLogiqueObj[x].matchId1, listeSame)[1] === null) {
getElementArray(listeLogiqueObj[x].matchId1, listeSame)[1] = num2;
num2 = getRandomArbitrary(0, 3);
} else {
listeSame[x] = getElementArray(listeLogiqueObj[x].matchId1, listeSame);
}
}
}
createStage("play_container");
stage.add(layer);
timeEnd = 1000;
for (let i = 0; i < colonneTot; i++) {
liveColonneNumber.push([]);
}
initTimer();
//creation logique
listeLogiqueObj.forEach(function (logique) {
if (getTypeFromSameMatch(listeSame, logique.matchId1) === null) logique.type = getRandomArbitrary(0, 3);
else logique.type = getTypeFromSameMatch(listeSame, logique.matchId1);
switch (logique.type) {
case 0:
console.log(logique.id + " type : " + logique.type + " col : " + logique.col);
insertLogiqueColonne(logique.id, "et", logique.col - 1);
break;
case 1:
console.log(logique.id + " type : " + logique.type + " col : " + logique.col);
insertLogiqueColonne(logique.id, "ou", logique.col - 1);
break;
case 2:
console.log(logique.id + " type : " + logique.type + " col : " + logique.col);
insertLogiqueColonne(logique.id, "inv", logique.col - 1);
break;
}
});
}
function getElementArray(one, array) {
retour = null;
array.forEach(function (element) {
if (element[0] === one && retour === null) {
retour = element;
}
});
return retour;
}
function getTypeFromSameMatch(listeMatch, sameId) {
retour = null;
listeMatch.forEach(function (element) {
if (element[0] === sameId)
retour = element[1];
});
return retour;
} }
@ -359,7 +443,11 @@ function generate2() {
function generateFromBottom() { function generateFromBottom() {
var NombrecolonneTest = 2; var NombrecolonneTest = 2;
var numberPerColonneTest = [3, 2]; var numberPerColonneTest = [3, 2];
var porteBool = [[true, "et"], [true, "ou"], [true, "inv"]]; var porteBool = [
[true, "et"],
[true, "ou"],
[true, "inv"]
];
var logiquesTest = []; var logiquesTest = [];
for (let i = NombrecolonneTest; i > 0; i--) { for (let i = NombrecolonneTest; i > 0; i--) {

@ -6,7 +6,14 @@ function initAll() {
} }
var mobile = false; var mobile = false;
var switchs = [], lineCount = [], logiques = [], lines = [], endLines = [], end, switchsInfo = [], switchsInfoCopy = [], lineRemove = []; var switchs = [],
lineCount = [],
logiques = [],
lines = [],
endLines = [],
end, switchsInfo = [],
switchsInfoCopy = [],
lineRemove = [];
var width = window.innerWidth - window.innerWidth / 100 * 30; var width = window.innerWidth - window.innerWidth / 100 * 30;
var height = window.innerHeight / 2.5; var height = window.innerHeight / 2.5;
var stage = new Konva.Stage({ var stage = new Konva.Stage({
@ -114,7 +121,9 @@ function initEndGame(mode) {
function resetCache() { function resetCache() {
openModal("reset_cache"); openModal("reset_cache");
setTimeout(() => { location.reload(); }, 3000); setTimeout(() => {
location.reload();
}, 3000);
} }
window.addEventListener('resize', saveStage); window.addEventListener('resize', saveStage);

Loading…
Cancel
Save