// Tous les javascripts droits d'auteurs 2003 Serge Lamarche à sergewebservice@yahoo.ca
// All javascripts copyrights 2003 Serge Lamarche at sergewebservice@yahoo.ca

function labyrinth() {  //a4;
if (!document.layers) {
nx =document.forms["jeu"].elements["x"].value; //maxx=window.innerWidth
ny =document.forms["jeu"].elements["y"].value; //maxy=window.innerHeight
 }
else {
nx =document.un.document.forms["jeu"].elements["x"].value;
ny =document.un.document.forms["jeu"].elements["y"].value;  } ;
if((isNaN(nx+ny)==isNaN("hgtrkt"))||(nx<5)||(ny<5)||(200<nx*ny)) {
alert("Please, enter numbers\n greater than four\n but not too big !\n") ;return;};
if ((-1 != navigator.userAgent.search(/Opera/))&&((ny>35)||(175<nx*ny))) {
alert("Maximum depth 35 tiles \n and max surface 175 on Opera.");return;};
if (!document.layers) {
net="" ; table(ny,nx);            // exécute
document.open("text/html") ;
if (document.all) {document.write(codeHTML)} else {document.write(codeHTMLmisc)};
document.close() ;  }
else {net="net" ;
table(ny,nx); window.document.un.visibility="hide" ; // exécute
with(document.lab) { document.open();
document.write(codeHTMLnet); 
document.close(); } ; } ;

function dir1() { return((2*Math.round(Math.random()))-1) } ;

function table(nbligne,nbcol) { 
codeHTML='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 ' 
+ 'Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' +
'<html>\n' +
'<head>\n' +
'<title>Machine-generated game</title>\n' +
'<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">\n' +
'<meta http-equiv="Content-Language" content="en">\n' +
'<meta http-equiv="Content-Language" content="fr">\n' +
'<meta name="code-generator" content="Serge Lamarche">\n' +
'<meta name="html-script-formatting" content="sergewebservice@yahoo.ca">\n' ;
codeHTMLmisc='<script language="javascript1.2" type="text/javascript" src="JS-jeu1-2b.js" charset="iso-8859-1">\n' +
'<\!-- Javascript created by sergewebservice@yahoo.ca --\> \n<\/script>\n' +
'<link rel="Stylesheet" href="CSS-a-partager.css" type="text/css">\n</head>\n\n' +
'<body class="jeu" bgcolor="#FFFFFF" text="#000000" link="#006600" alink="#66CC33" vlink="#008000" background="" onLoad="">\n\n' ;
codeHTMLnet='<h1 class="jeu">Labyrinth-type game generated by javascript</h1>\n<p class="jeu"><a class="jeu" href="javascript:souris'+net+'('+ nbligne+','+nbcol+
')">Click here to start !</a></p>\n<p class="jeu"><a class="jeu"  href="javascript:reinit'+net+'('+ nbligne+','+nbcol+
')">Reinitialize.</a></p>\n<p class="jeu"><form class="jeu" method="get" name="result" action="">Score: <input class="jeu" name="score" type="text" size="4" align="middle" value=""></form></p>\n' +
'<table bgcolor="lightblue" align="center" width="10%" border="0" cellspacing="2" cellpadding="0" >\n';

var diry1=0 ; var diry2=0 ; var dirx1=0 ; var dirx2=0 ;
// début de boucle sur les lignes
 for(ligne=1;ligne<=nbligne;ligne++) {
   codeHTMLnet+='<tr align="center">';          // début de ligne
// boucle sur les colonnes
   for(col=1;col<=nbcol;col++) {
      codeHTMLnet+='<td>' ;

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 ; } ;

      codeHTMLnet+='<a href="javascript:chgimg'+net+'(\'a' +dirx1+'b'+diry1+ '\'); chgimg'+net+'(\'a'+ dirx2+'b'+diry2+'\');compte'+net+'()" ondblClick="javascript:casse' +net+'(\'a' +col+'b'+ligne
+'\')"><img name="a' +col+'b'+ligne+ '" width="25" height="25" src="images-jeu/jeu.gif" alt="">' ; //changer images

      codeHTMLnet+='</a></td>' ;
   }

 codeHTMLnet+='</tr>\n'    ;                      // fin de ligne
 }

codeHTMLnet+='</table>\n\n<p class="jeu">Game explanations: \n <p class="jeu">When clicking on a tile you make two neighbouring go up (or down). Because of defective connections, the tiles who lift (or descend) while clicking, respond according to a random pattern. Note that this pattern remain unchanged even after a reinitialization. You must go back one page and recreate the labyrinth to change the pattern.</p> \n <p class="jeu">The mice do not jump over lifted tiles and do not go in diagonal. (They are also slower in corners and tight places.) You can, like this, direct it (or them) to the cage for a safe recuperation. The mice are precious and must stay alive for further tests and results. They are not mean but better avoid this disease. <br>You have about half an hour. Small scores are better.</p>\n<p class="jeu">Comments? Write to sergewebservice@yahoo.ca</p><br><br>\n' ;
codeHTMLmisc+=codeHTMLnet ; codeHTML+=codeHTMLmisc+'</body>\n</html>\n'    ;
} }

