<html><head>

<title>Javascript Maze Maker</title>

<script language="javascript">

 

black = new Image(10, 10);

black.src = "black.gif";

white = new Image(10, 10);

white.src = "white.gif";

blue = new Image(10, 10);

blue.src = "blue.gif";

purple = new Image(10, 10);

purple.src = "purple.gif";

red = new Image(10, 10);

red.src = "red.gif";

function number(k) {

if (k == '0'){

return "black.gif";

}

else if (k == '1'){

return "orange.gif";

}

else if (k == '2'){

return "red.gif";

}

else if (k == '3'){

return "green.gif";

}

else if (k == '4'){

return "blue.gif";

}

else if (k == '5'){

return "yellow.gif";

 

}

else if (k == '6'){

return "purple.gif";

}

else if (k == '8'){

return "grey.gif";

}

else if (k == '9'){

return "ltgrey.gif";

}

else if (k == 'a'){

return "peach.gif";

}

else if (k == 'b'){

return "ltblue.gif";

}

else if (k == 'c'){

return "ltpurple.gif";

}

else if (k == 'd'){

return "turquoise.gif";

}

else if (k == 'e'){

return "brown.gif";

}

else if (k == 'f'){

return "ltgreen.gif";

}

else {

return "white.gif";

}

}

function display(name,screen,size,hello,mouseover,mouseout) {

var i =0 ;

var x='';

var y='';

while ( hello.charAt(i)!=",") {

x+=hello.charAt(i);

i++;

}

i++;

while (hello.charAt(i)!=",") {

y+=hello.charAt(i);

i++

}

i++;

j=0;

 

 

num= new Array(eval(x*y));

while (hello.charAt(i)) {

num[j]=hello.charAt(i);

j++; i++;

 

 

}

screen.document.writeln("<center><table border=0 cellspacing=0 cellpadding=0>");

for (i=0;i<(eval(y));i++) {

screen.document.writeln("<tr>");

for (a=0;a<(eval(x));a++) {

screen.document.write("<td><a href=#blah ");

if (mouseover == "yes") {

document.write("onmouseover=action("+eval(i*(eval(x))+a)+",'"+name+"') ");

}

if (mouseout == "yes") {

document.write("onmouseout=action2("+eval(i*(eval(x))+a)+",'"+name+"') ");

}

screen.document.writeln(" ><img src='"+number(num[i*(eval(x))+a])+"' border=0 width="+size+" height="+size+"></a></td>");

}

screen.document.writeln("</tr>");

}

screen.document.writeln("</table>");

}

function action2 (i,name) {

if (document.images[i].src == 'http://www.humboldt1.com/~medusa/guy.gif') {

document.images[eval(i)].src="dot.gif";

}

}

function action (i,name) {

if (document.images[i].src == 'http://www.humboldt1.com/~medusa/white.gif') {

if (i==1){

document.images[eval(i)].src="guy.gif";

}

else if ((document.images[eval(i)-eval(name)].src == 'http://www.humboldt1.com/~medusa/dot.gif') ||(document.images[eval(i)-eval(name)].src == 'http://www.humboldt1.com/~medusa/guy.gif')) {

document.images[eval(i)].src="guy.gif";

}

else if ((document.images[eval(i)+eval(name)].src == 'http://www.humboldt1.com/~medusa/dot.gif') ||(document.images[eval(i)+eval(name)].src == 'http://www.humboldt1.com/~medusa/guy.gif') ) {

document.images[eval(i)].src="guy.gif";

}

else if ((document.images[eval(i)-1].src == 'http://www.humboldt1.com/~medusa/dot.gif') ||(document.images[eval(i)-1].src == 'http://www.humboldt1.com/~medusa/guy.gif') ) {

document.images[eval(i)].src="guy.gif";

}

else if ((document.images[eval(i)+1].src == 'http://www.humboldt1.com/~medusa/dot.gif') ||(document.images[eval(i)+1].src == 'http://www.humboldt1.com/~medusa/guy.gif') ) {

document.images[eval(i)].src="guy.gif";

}

if (((document.images[eval(i)].src == "http://www.humboldt1.com/~medusa/dot.gif") ||(document.images[eval(i)].src == 'http://www.humboldt1.com/~medusa/guy.gif')) && (eval(i)>(eval(name)-1)*eval(name)+1)) {

if (window.confirm("Good Job! You solved a "+name+" by "+name+" maze. Now do you want to try something harder?")) {

bigger=eval(name)+10;

document.location="maze.htm?"+bigger;

}

}

}

}

function random(maxValue) {

return (parseInt(Math.random()*maxValue));

}

 

function drawMaze(initx,inity) {

x = eval(initx);

y = eval(inity);

var data = new Array(x*y);

 

for (i=0;i<x*y;i++) {

if ((i%x)==0 || (i%x)==(x-1) || i<y || i>(x*(y-1))) {

data[i]=4;

}

else {

data[i]= 2;

}

}

enter=1;

data[enter]=7;

drawPath(data,x,y,enter, enter+x);

i=x+2;

while (i<x*(y-1)-2) {

if (data[i]==2) {

if (data[i-x]==0) {

drawPath(data,x,y,i-x,i);

check=i-x;

while (check-x >= 0 && data[check] !=7 && data[check] !=4){

data[check]=7;

check-=x;

}

i++;

}

else if (data[i-1]==0) {

drawPath(data,x,y,i-1,i);

check=i-1;

while (check-1 >= 0 && data[check] !=7 && data[check] !=4){

data[check]=7;

check--;

}

i++;

}

}

i++;

}

choice=(y*x)-(parseInt(x/2));

while (data[choice-x] != 7) {

choice--;

}

if (choice<(y-1)*x-1) {

data[choice+x]=7;

}

data[choice]=7;

data[enter+x]=7;

save=x+","+y+",";

for (i=0;i<x*y;i++) {

save+=data[i];

}

pixels=8;

if (x>=60 && x<80) {

pixels=7;

}

else if (x>=80 && x<100) {

pixels=6;

}

else if (x>=100) {

pixels=5;

}

display(x,self,pixels,save,'yes','yes');

}

function drawPath (data,x,y,previous,current) {

if (data[current] ==2 ) {

data[current]=7;

 

choice=random(56);

if (choice==1) {

total=3;

}

else if (choice >1 && choice<15) {

total=2;

}

else if (choice >50 && choice <57) {

total=0;

}

else {

total=1;

}

tried=0;

 

while ( total>0 && tried <4) {

choice=random(4);

if (choice==1) {

if (current+1 != previous) {

if (drawPath(data,x,y,current,current+1)) {

total--;

}

}

tried++;

}

if (choice==2) {

if (current-1 != previous) {

if (drawPath(data,x,y,current,current-1)) {

total--;

}

}

tried++;

}

if (choice==3) {

if (current+x != previous) {

if (drawPath(data,x,y,current,current+x)) {

total--;

}

}

tried++;

}

if (choice==4) {

if (current-x != previous) {

if (drawPath(data,x,y,current,current-x)) {

total--;

}

}

tried++;

}

if (data[previous]==0 || data[previous]==2) {

data[previous]=7;

}

}

if (data[current+1]==2) {

data[current+1]=0;

}

if (data[current-1]==2) {

data[current-1]=0;

}

if (data[current-x]==2) {

data[current-x]=0;

}

if (data[current+x]==2) {

data[current+x]=0;

return true;

}

}

else {

if (data[previous]==7) {

data[previous]=0;

}

return false;

}

}

</script>

</head><body bgcolor=#ffffff><font size=4><center>Try to get from the opening in the top </center>

<script language='javascript'>

if (eval(navigator.appVersion.substring(0,1))<3 || document.location.search == '') {

maze_size=window.prompt("How large do you want the maze? (10 is small, 80 is huge, and older PCs can't handle anything bigger than 19)",19);

}

else {

maze_size=eval(document.location.search.substring(1,document.location.search.length));

}

if (maze_size>=35) {

window.alert("This may take awhile. You might need to increase your browser's memory allocation, and you should go get a snack.");

}

drawMaze(maze_size,maze_size);

</script>

<center>down to the bottom</font>

<img src=http://humboldt1.com/cgi-bin/Count.cgi?df=medusa1.dat|dd=B|ft=2 height=1 width=1>

<p><a href=http://humboldt.edu/cgi-bin/cgiwrap/jpz2/connect4/connect4.pl><font size=+1>Play connect 4 against a computer oppenent that <i>learns</i></font></a>

</p><p><a href=page target=_top>Check out the rest of my site</a></center>

</body></html>