@ -50,6 +50,10 @@ function setColor(color) {
document . querySelectorAll ( ".border" ) . forEach ( function ( element ) {
document . querySelectorAll ( ".border" ) . forEach ( function ( element ) {
element . style . border = "5px solid" + whiteColor ;
element . style . border = "5px solid" + whiteColor ;
} ) ;
} ) ;
document . querySelectorAll ( ".color" ) . forEach ( function ( element ) {
element . style . color = whiteColor ;
} ) ;
} else {
} else {
document . body . style . color = blackColor ;
document . body . style . color = blackColor ;
@ -65,11 +69,27 @@ function setColor(color) {
document . querySelectorAll ( ".border" ) . forEach ( function ( element ) {
document . querySelectorAll ( ".border" ) . forEach ( function ( element ) {
element . style . border = "5px solid" + blackColor ;
element . style . border = "5px solid" + blackColor ;
} ) ;
} ) ;
document . querySelectorAll ( ".color" ) . forEach ( function ( element ) {
element . style . color = blackColor ;
} ) ;
}
}
//fun
//fun
document . querySelector ( ".secret" ) . style . color = "#fe8a71" ;
document . querySelector ( ".secret" ) . style . color = "#fe8a71" ;
}
}
document . querySelector ( "#button_next_level" ) . onmouseover = function ( ) { mouseOver ( ) } ;
document . querySelector ( "#button_next_level" ) . onmouseout = function ( ) { mouseOut ( ) } ;
function mouseOver ( ) {
document . querySelector ( "#button_next_level" ) . style . backgroundColor = document . querySelector ( ".modal-body" ) . style . borderColor ;
document . querySelector ( "#button_next_level" ) . style . color = document . querySelector ( ".modal-body" ) . style . backgroundColor ;
}
function mouseOut ( ) {
document . querySelector ( "#button_next_level" ) . style . backgroundColor = document . querySelector ( ".modal-body" ) . style . backgroundColor ;
document . querySelector ( "#button_next_level" ) . style . color = document . querySelector ( ".modal-body" ) . style . borderColor ;
}
function setLang ( newLang ) {
function setLang ( newLang ) {
var textToChange = document . querySelectorAll ( ".txt" ) ;
var textToChange = document . querySelectorAll ( ".txt" ) ;
if ( newLang === "fr" ) {
if ( newLang === "fr" ) {
@ -156,6 +176,71 @@ function checkAllSortieLogique() {
} ) ;
} ) ;
}
}
function getSwitchById ( switchId ) {
let switche ;
switchsInfoCopy . forEach ( function ( element ) {
if ( element . id == switchId )
switche = element ;
} ) ;
return switche ;
}
function checkEntreCroisement ( logiqueId ) {
let croisement = false ;
let logique = findLogique ( logiqueId ) ;
if ( logique . id1 != null && logique . id2 != null ) {
if ( stage . findOne ( "#" + logique . id1 ) . points ( ) [ 1 ] > stage . findOne ( "#" + logique . id2 ) . points ( ) [ 1 ] ) {
if ( getSwitchFromLine ( logique . id1 ) != null && getSwitchFromLine ( logique . id2 ) != null ) {
let switch1 = getSwitchFromLine ( logique . id1 ) . id ;
let switch2 = getSwitchFromLine ( logique . id2 ) . id ;
removeLine ( logique . id1 ) ;
removeLine ( logique . id2 ) ;
logique . id1 = null ;
logique . id2 = null ;
createLink ( stage . findOne ( "#" + switch1 ) , logique ) ;
createLink ( stage . findOne ( "#" + switch2 ) , logique ) ;
} else if ( getLogiqueFromLine ( logique . id1 ) != null && getLogiqueFromLine ( logique . id2 ) != null ) {
console . log ( "blem la " ) ;
let logique1 = getLogiqueFromLine ( logique . id1 ) ;
let logique2 = getLogiqueFromLine ( logique . id2 ) ;
removeLine ( logique . id1 ) ;
removeLine ( logique . id2 ) ;
logique . id1 = null ;
logique . id2 = null ;
createLink ( logique1 , logique ) ;
createLink ( logique2 , logique ) ;
}
else {
console . log ( "wait" ) ;
}
croisement = true ;
}
}
return croisement ;
}
function getLogiqueFromLine ( lineId ) {
var logique = null ;
logiques . forEach ( function ( element ) {
element . id3 . forEach ( function ( line ) {
if ( line == lineId ) logique = element ;
} )
} ) ;
return logique ;
}
function getSwitchFromLine ( lineId ) {
var switche = null ;
switchsInfoCopy . forEach ( function ( element ) {
element . id3 . forEach ( function ( line ) {
if ( line == lineId ) switche = element ;
} ) ;
} ) ;
return switche ;
}
function checkSortieLogique ( logiqueId ) {
function checkSortieLogique ( logiqueId ) {
let logique = findLogique ( logiqueId ) ;
let logique = findLogique ( logiqueId ) ;
logiques . forEach ( function ( element , index ) {
logiques . forEach ( function ( element , index ) {
@ -226,6 +311,21 @@ function checkSortieLogique(logiqueId) {
} ) ;
} ) ;
}
}
function isLineCollapsing ( ) {
var isCollapsing = false ;
if ( stage . findOne ( "#s2" ) != undefined && stage . findOne ( "#s2" ) != null && stage . findOne ( "#s1" ) != undefined && stage . findOne ( "#s1" ) != null ) {
var distance = stage . findOne ( "#s2" ) . getY ( ) - stage . findOne ( "#s1" ) . getY ( ) ;
switchsInfoCopy . forEach ( function ( element ) {
element . id3 . forEach ( function ( line ) {
if ( Math . abs ( element . y - stage . findOne ( "#" + line ) . points ( ) [ 7 ] ) > distance ) {
isCollapsing = true ;
}
} )
} ) ;
}
return isCollapsing ;
}
function getRandomArbitrary ( min , max ) {
function getRandomArbitrary ( min , max ) {
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
}
}
@ -244,22 +344,70 @@ function checkLineSwitch(switchId) {
return false ;
return false ;
}
}
function activeSwitch ( idSwitch ) {
getSwitchById ( idSwitch ) ;
var switche = getSwitchById ( idSwitch ) ;
changeSwitchColor ( switche . id ) ;
switche . id3 . forEach ( function ( element ) {
changeLineColor ( element ) ;
} ) ;
}
function checkIfEnd ( ) {
var ter = true ;
endLines . forEach ( function ( element ) {
if ( stage . findOne ( "#line" + element ) . stroke ( ) == colorLineInnactive ) {
ter = false ;
}
} ) ;
return ter ;
}
function checkEnd ( ) {
function checkEnd ( ) {
let ter = true ;
let ter = true ;
endLines . forEach ( function ( element ) {
endLines . forEach ( function ( element ) {
if ( stage . findOne ( "#line" + element ) . stroke ( ) == "black" ) {
if ( stage . findOne ( "#line" + element ) . stroke ( ) == colorLineInnactive ) {
ter = false ;
ter = false ;
}
}
} ) ;
} ) ;
if ( ter && ! isTuto ) {
if ( ter && ! isTuto ) {
setTimeout ( ( ) => { nextLevel ( ) ; } , 100 ) ;
setTimeout ( ( ) => { success ( ) ; } , 100 ) ;
}
}
function success ( ) {
timeTot = timeTot + timer . getTimeValues ( ) . seconds ;
timer . stop ( ) ;
stage . findOne ( "#end" ) . fill ( "yellow" ) ;
layer . draw ( ) ;
if ( successPanel ) {
openModal ( "success" ) ;
document . querySelector ( "#click_number" ) . innerHTML = click ;
var previewStage = new Konva . Stage ( {
container : 'show_stage' ,
width : window . innerWidth / 1.5 ,
height : window . innerHeight / 2.5 ,
scaleX : 1 / 1.5 ,
scaleY : 1 / 1.5
} ) ;
let previewLayer = layer . clone ( { hitGraphEnabled : false } ) ;
previewStage . add ( previewLayer ) ;
previewLayer . batchDraw ( ) ;
} else {
setTimeout ( ( ) => { nextLevel ( ) ; } , 1000 ) ;
}
}
}
}
function successCheck ( ) {
if ( document . querySelector ( "#success_check_input" ) . checked === true ) successPanel = true ;
else successPanel = false ;
}
function nextLevel ( ) {
function nextLevel ( ) {
niveauActuel ++ ;
niveauActuel ++ ;
timeTot = timeTot + timer . getTimeValues ( ) . seconds ;
launchGameOne ( ) ;
launchGameOne ( ) ;
}
}