// Tous les javascripts droits d'auteurs Serge Lamarche à sergewebservice@yahoo.ca
// All javascripts copyrights Serge Lamarche at sergewebservice@yahoo.ca
// a5 

var textfr1 = new Array(); var textfr2 = new Array(); 
var texten1 = new Array(); var texten2 = new Array(); 

textfr1=["SVP, il faut entrer des nombres\n plus grands que quatre\n mais pas trop grands !\n\n ","Profondeur maximum de 35 carreaux \n et surface max de 168 sur Opera."];
textfr2=["Jeu de type labyrinthe généré par javascript"];
textfr2.push('"Sauver les écureuils"',"Appuyer ici pour le départ!","Réinitialiser.","Pointage: ","Explications du jeu: ","Un ou deux écureuils (tamias rayés en fait) sont pris sur le lac. Par déclic, vous lancez un grosse roche à l'eau pour aider le ou les écureuils à rejoindre la berge. Le fond du lac est inégal et les roches ne vont pas exactement où vous les lancez. Les roches peuvent aussi couler sous le choc. Remarquez que le fond du lac reste le même à moins de recharger la page et de regénérer le jeu. Et il peut arriver que ce ne soit pas possible de trouver un trajet vers la berge.","Les écureuils évitent l'eau et ne vont pas en diagonale. Vous pouvez donc le (ou les) diriger vers la berge pour leur sauver la vie.","Vous avez environ une demi-heure. Plus bas votre pointage, meilleur vous êtes.","Commentaires?","feedback.html?labyrinthe-ec","Organigramme","organigramme.html") 

texten1=["Please, enter numbers\n greater than four\n but not too big !\n","Maximum depth 35 tiles \n and max surface 168 on Opera."];
texten2=["Labyrinth-type game generated by javascript"];
texten2.push('"Save the squirrels"',"Click here to start !","Reinitialize.","Score: ","Game explanations: ","One or two squirrels (chipmunks in fact) are stuck on the lake. With a click, you can throw a rock in the water to help the squirrel(s) get to the bank. The lake bottom is uneven and the rocks do not land exactly where you throw them. The rocks may also sink with the shock. Remark that the lake bottom does not change unless you reload the page and regenerate the game. And it can happen that it is not possible to find a path to the bank.","The squirrels avoid the water and do not jump in diagonal. You may therefore direct the squirrel(s) to the bank to save them.","You have about half an hour. Small scores are better.","Comments?","feedback.html?labyrinth-ec","Site Map","organigramme.html") 


function labyrinthe2(langue) {  //a5;
if (langue=="en") {inserer=texten1}; if (langue=="fr") {inserer=textfr1};
nx =document.forms["jeu"].elements["x"].value;
ny =document.forms["jeu"].elements["y"].value;
if((isNaN(nx+ny)==isNaN("hgtrkt"))||(nx<5)||(ny<5)||(200<nx*ny)) {
alert(inserer[0]); return;};
if ((-1 != navigator.userAgent.search(/Opera/))&&((ny>35)||(168<nx*ny))) {
alert(inserer[1]); return;};
if (document.createTextNode) { table2(ny,nx,langue); } else return; }

function dir1() { return((2*Math.round(Math.random()))-1) } ;

function chgimGecko(e) { if (!e) e = window.event; 
if (e.srcElement) chgimg(e.srcElement.coorda); 
else if (this.coorda) chgimg(this.coorda); //chgimg(this.coordb); 
else if (e.target) chgimg(e.target.coorda); compte(); }
function casseGecko(e) { if (!e) e = window.event; 
if (e.srcElement) casse(e.srcElement.id); 
else if (this.id) casse(this.id); 
else if (e.target) casse(e.target.id); compte(); }
function sourisGecko() { souris(ny,nx); }
function reinitGecko() { reinit(ny,nx); }

function table2(nbligne,nbcol,language) { 
if (language=="en") {inserer=texten2}; if (language=="fr") {inserer=textfr2};
labo=document.getElementById("lab2"); 

titre = document.createElement("h1");  titre.setAttribute("class","jeu"); 
texte = document.createTextNode(inserer[0]); 
titre.appendChild(texte); labo.appendChild(titre); 

divbravo = document.createElement("div"); divbravo.setAttribute("id","bravo"); 
divbravo.setAttribute("class","bravo"); labo.appendChild(divbravo); 

soustitre = document.createElement("h2");  soustitre.setAttribute("class","jeu"); 
texte = document.createTextNode(inserer[1]); 
soustitre.appendChild(texte); labo.appendChild(soustitre); 

paragraphe = document.createElement("p"); paragraphe.setAttribute("class","jeu"); 
lien = document.createElement("a"); //-----
texte = document.createTextNode(inserer[2]); 
//======paragraphe.appendChild(texte); 
lien.appendChild(texte); //-----
texte = "javascript:sourisGecko()"; lien.setAttribute("href",texte); //----
lien.setAttribute("class","jeu"); paragraphe.appendChild(lien); //----
//=========paragraphe.addEventListener("click",sourisGecko,true); 
labo.appendChild(paragraphe); 

paragraphe = document.createElement("p");  paragraphe.setAttribute("class","jeu"); 
lien = document.createElement("a"); //-----
texte = document.createTextNode(inserer[3]); 
//======paragraphe.appendChild(texte); 
lien.appendChild(texte); //-----
texte = "javascript:reinitGecko()"; lien.setAttribute("href",texte); //----
lien.setAttribute("class","jeu"); paragraphe.appendChild(lien); //----
//=========paragraphe.addEventListener("click",sourisGecko,true); 
labo.appendChild(paragraphe); 

paragraphe = document.createElement("p");  paragraphe.setAttribute("class","jeu"); 
formulaire = document.createElement("form"); 
formulaire.setAttribute("method","post"); formulaire.setAttribute("id","result"); 
formulaire.setAttribute("action",""); texte = document.createTextNode(inserer[4]); 
entree = document.createElement("input"); entree.setAttribute("id","score"); entree.setAttribute("type","text"); entree.setAttribute("size","4"); 
entree.style.padding="0px 10px"; entree.setAttribute("value","0"); 
formulaire.appendChild(texte); formulaire.appendChild(entree); paragraphe.appendChild(formulaire); 
labo.appendChild(paragraphe); 


plancher = document.createElement("table");
tplancher = document.createElement("tbody");
var diry1=0 ; var diry2=0 ; var dirx1=0 ; var dirx2=0 ;
for(ligne=1;ligne<=nbligne;ligne++) {
ligneplancher=document.createElement("tr"); ligneplancher.setAttribute("align","center");
for(col=1;col<=nbcol;col++) {
carreau=document.createElement("td");
lecarreau=document.createElement("img"); lecarreau.setAttribute("id","a"+col+"b"+ligne); 

diry1=diry2=ligne ; dirx1=dirx2=col ;
if (dir1()<0) { diry1+= ((ligne==1) ? 1 : ((ligne==nbligne) ? -1 : dir1())) } 
else { dirx1+= ((col==1) ? 1 : ((col==nbcol) ? -1 : dir1())) } ;
if (dir1()<0) { diry2+= ((ligne==1) ? 1 : ((ligne==nbligne) ? -1 : dir1())) } 
else { dirx2+= ((col==1) ? 1 : ((col==nbcol) ? -1 : dir1())) } ;
//if ((dirx1==dirx2)&&(diry1==diry2)) { diry2=ligne ; dirx2=col ; } ;


lecarreau.coorda='a'+dirx1+'b'+diry1; //lecarreau.coordb='a'+dirx2+'b'+diry2 ; 
lecarreau.setAttribute("width","25px"); lecarreau.setAttribute("height","25px"); 
lecarreau.src="images-jeu/jeu-eau.gif"; 
if (lecarreau.addEventListener) { lecarreau.addEventListener("click",chgimGecko,true); lecarreau.addEventListener("dblclick",casseGecko,true); }
else if (lecarreau.attachEvent) { lecarreau.attachEvent("onclick",chgimGecko); 
lecarreau.attachEvent("ondblclick",casseGecko); }
carreau.appendChild(lecarreau);
ligneplancher.appendChild(carreau);
 }
tplancher.appendChild(ligneplancher);
 }
plancher.appendChild(tplancher); //plancher.setAttribute("background","");
plancher.style.background="slateblue url("+jfond.src+")"; 
plancher.setAttribute("align","center"); plancher.setAttribute("cellspacing","0");
plancher.setAttribute("border","0"); plancher.setAttribute("cellpadding","0");
//var ww=(25*nbcol)+"px"; var hh=(25*nbligne)+"px"
//plancher.setAttribute("width",ww); 
//plancher.setAttribute("height",hh);
plancher.setAttribute("class","fond"); 
labo.style.visibility="visible"; labo.appendChild(plancher); document.forms["jeu"].style.visibility="hidden";

paragraphe = document.createElement("p"); sauteli = document.createElement("br"); 
texte = document.createTextNode(inserer[5]);  paragraphe.setAttribute("class","jeu"); 
paragraphe.appendChild(texte); paragraphe.appendChild(sauteli); labo.appendChild(paragraphe); 

paragraphe = document.createElement("p");  paragraphe.setAttribute("class","jeu"); 
texte = document.createTextNode(inserer[6]); 
paragraphe.appendChild(texte); labo.appendChild(paragraphe); 

paragraphe = document.createElement("p");  paragraphe.setAttribute("class","jeu"); 
texte = document.createTextNode(inserer[7]); 
paragraphe.appendChild(texte); 
texte = document.createTextNode(inserer[8]); 
paragraphe.appendChild(sauteli); paragraphe.appendChild(texte); 
labo.appendChild(paragraphe); 

regle = document.createElement("hr"); regle.style.margin="30px 25%"; 
document.getElementsByTagName("body").item(0).style.background="#f5f5f5"; 
regle.setAttribute("width","50%"); labo.appendChild(regle); 
for (var i=0; i<labo.childNodes.length; i++) labo.childNodes.item(i).style.fontFamily="comic sans ms, arial, helvetica"; titre.style.marginLeft="5%"; 
noeud = document.getElementById("infobas").cloneNode(true); labo.appendChild(noeud); 
paragraphe = document.createElement("p");  paragraphe.setAttribute("class","evalpage"); 
texte = document.createTextNode(inserer[9]); 
lien = document.createElement("a"); lien.setAttribute("href",inserer[10]); 
lien.setAttribute("id","rating"); lien.appendChild(texte); 
paragraphe.appendChild(lien); labo.appendChild(paragraphe); 
paragraphe = document.createElement("p");  paragraphe.setAttribute("class","evalpage"); 
texte = document.createTextNode(inserer[11]); 
lien = document.createElement("a"); lien.setAttribute("href",inserer[12]); 
lien.setAttribute("id","rating"); lien.appendChild(texte); 
paragraphe.appendChild(lien); labo.appendChild(paragraphe); 
}

