Quellcode
<SCRIPT type="text/javascript">
var variable = window.name;
if (variable=='')
{
var num_rows = 4;
var num_columns = 4;
}
else
{ var temp1=variable.lastIndexOf("c");
var num_rows=variable.slice(1,temp1);
var num_columns=variable.slice(temp1+1,variable.length);
} var num_fields=num_rows * num_columns; var num_pics=num_rows * num_columns/2; var opened_pics=0; var firstclick=0; var pic1; var pic2; var start_time; var end_time; var firstimage=0; var image_number; var first_clicked_image=0; var attempts=0; var allow_click=1; var covered=new Image;
covered.src="covered.gif"; var bild=new Array();
bild[0]=new Array(2);
bild[0]["nick"]=new Image;
bild[0]["nick"].src="00.gif";
bild[0]["avatar"]=new Image;
bild[0]["avatar"].src="00.gif";
.
.
.
bild[17]=new Array(2);
bild[17]["nick"]=new Image;
bild[17]["nick"].src="17.gif";
bild[17]["avatar"]=new Image;
bild[17]["avatar"].src="17.gif"; var image_numbers = new Array();
for (var t=0; t < num_fields; t++)
{
image_numbers[('M'+t)]=new Array();
image_numbers[('M'+t)]["zahl"]=t;
image_numbers[('M'+t)]["status"]=0;
} var temp_numbers= new Array();
function init()
{ for (var t=0; t < num_fields; t++)
{
temp_numbers[('M'+t)]=t;
} for (var t=0; t < num_fields; t++)
{
do
{
random_number = Math.round(Math.random() * (num_fields));
}
while (random_number > (num_fields-1)); var temp=temp_numbers[('M'+t)];
temp_numbers[('M'+t)]=temp_numbers[('M'+random_number)];
temp_numbers[('M'+random_number)]=temp;
}
for (t=0; t < num_fields; t++)
{
image_numbers[('M'+t)]["zahl"]=temp_numbers[('M'+t)];
}
} function close(pic1,pic2)
{
window.document.images[pic1].src=covered.src;
image_numbers[pic1]["status"]=0;
window.document.images[pic2].src=covered.src;
image_numbers[pic2]["status"]=0;
allow_click=1;
} function look(x,y)
{ if (firstclick==0)
{
start_time=new Date();
firstclick=1;
} image_number='M'+(x*num_columns+y); if ((firstimage==0) && (image_numbers[image_number]["status"]<10))
{ allow_click=0;
firstimage=1;
pic1=Math.floor(image_numbers[image_number]["zahl"]/2);
if ((image_numbers[image_number]["zahl"] % 2)==0)
window.document.images[image_number].src=bild[pic1]["avatar"].src;
else window.document.images[image_number].src=bild[pic1]["nick"].src;
image_numbers[image_number]["status"]=10;
first_clicked_image=image_number;
allow_click=1;
} else if ((firstimage==1) && (image_numbers[image_number]["status"]<3))
{ allow_click=0;
firstimage=0;
attempts++;
pic2=Math.floor(image_numbers[image_number]["zahl"]/2);
if ((image_numbers[image_number]["zahl"] % 2)==0)
window.document.images[image_number].src=bild[pic2]["avatar"].src;
else window.document.images[image_number].src=bild[pic2]["nick"].src;
image_numbers[image_number]["status"]=10;
if (pic1!=pic2) window.setTimeout("close(first_clicked_image,image_number)",500);
else
{
opened_pics++;
allow_click=1;
} if (opened_pics==num_pics) end_time=new Date();
} if (opened_pics==num_pics)
{
var seconds=Math.floor(eval( ( (end_time.getTime() - start_time.getTime()) ) / 1000));
alert("Congratulations, you won the game in "+attempts+" turns and "+seconds+" seconds!");
}
} var game; function loadmemory()
{
var start=0;
if (document.spiel.settings[0].checked == true)
{
game="r4c4";
start=1;
}
if (document.spiel.settings[1].checked == true)
{
game="r4c6";
start=1;
}
if (document.spiel.settings[2].checked == true)
{
game="r6c6";
start=1;
}
window.name=game;
location.reload();
}
</SCRIPT> <SCRIPT type="text/javascript"> init(); for (var i=0; i < num_rows; i++)
{
for (var j=0; j < num_columns; j++)
{
document.write('<IMG src="'+covered.src+'" onClick="if (allow_click==1) look('+i+','+j+')" name="M'+(i*num_columns+j)+'">');
}
document.write('<BR>');
}
</SCRIPT> <FORM name="spiel" action="">
<INPUT type="radio" name="settings" id="s1" value="rookie"> <LABEL for="s1">Rookie</LABEL>
<BR>
<INPUT type="radio" name="settings" id="s2" value="advanced"> <LABEL for="s2">Advanced</LABEL>
<BR>
<INPUT type="radio" name="settings" id="s3" value="professional"> <LABEL for="s3">Professional</LABEL>
<BR>
<BR>
<BR>
<INPUT type="button" value="New Game" onClick="loadmemory()">
</FORM> |
Das Programm erhält seine Einstellungen via window.name. Änderungen daran werden im Formular am Ende getätigt.