The MONSTER! Game
Ok, this is my first script I write after reading about JavaScript. Its cheesy as hell, but whatever. The object of the game is to find the finish.
Once you find the finish it should reload the game so you can start over with new monster positions and a new finish position. This is where the problem occurs. After the new game is re-loaded upon finding the finish the OnMouseOver functions stop working and I get errors!
I'm sure someone with a little more javascript experience can spot the error I am making.
Thanks for any help. Here is [url=http://www.syntax******.info/test/monster_game.php][game][/url] and here is the code:
Code:
<script>
function create_monsters(count){
var monsters=new Array(); // ARRAY STORING MONSTER LOCATIONS
var new_monster; // NEW MONSTER WILL BE TESTED TO SEE IF EXIST ALREADY
var j; // COUNTING VARIABLE - PARSE THROUGH MONSTERS
var k; // COUNTING VARIABLE - PARSE THROUGH MONSTERS
var create; // FLAG - IF 0 MONSTER EXIST, IF * MONSTER DOES NOT EXIST
j=0;
while(j<count){
new_monster=(Math.round((Math.random()***)));
k=0;
create=*;
while(monsters[k] && create==*){
if(new_monster==monsters[k]){
create=0;
}
k++;
}
if(create!=0){
monsters[j]=new_monster;
j++;
}
}
return monsters;
}
function create_finish(monsters){
var k;
var create;
var new_finish;
create=0;
while(create==0){
new_finish= (Math.round((Math.random()***)));
k=0;
create=*;
while(monsters[k] && create==*){
if(new_finish==monsters[k]){
create=0;
}
k++;
}
}
return new_finish;
}
function action_monster(){
alert("A Monster Has Grabbed You!");
return 0;
}
function action_finish(){
alert("You have found the Finish!");
document.clear();
game();
return 0;
}
function game(){
document.write("<html><head><style type=\"text/css\">a:link{font-family:Arial, Helvetica, sans-serif; font-size:*5px; color:#000000; text-decoration:none; cursor:cross****}a:visited{font-family:Arial, Helvetica, sans-serif; font-size:*5px; color:#000000; text-decoration:none; cursor:cross****}a:hover{font-family:Arial, Helvetica, sans-serif; font-size:*5px; color:#ffe825; text-decoration:none; cursor:cross****}--></style><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-885*-*\" /><title>Untitled Document</title></head><body style=\"cursor:cross****; margin:0; padding:0; border:none; background-color:#000000;\"><center><table><tr><td>");
// BEGINNING OF ACTUAL DISPLAY SECTION
document.write("<div style=\"width:500px; float:left; background-color:#000000; border: 5px #****** solid;\">");
var monsters=create_monsters(5);
var finish=create_finish(monsters);
var i;
var j;
var flag=0;
i=0;
while(i<**){
flag=0; // FLAG FOR SEARCH - IF FLAG=* ITEM EXIST IN BLOCK, GO TO NEXT BLOCK (i)
j=0; // COUNTING VARIABLE - PARSE THROUGH MONSTERS
while(monsters[j] && flag==0){
if(i==monsters[j]){
flag=*;
document.write("<div style=\"width:*4px; height:*4px; float:left; margin:0; padding:0; margin-right:*px;\"><a href='#' onmouseover=\"action_monster();\">Ø</a></div>");
}
j++;
}
if(flag==0 && finish==i){
flag=*;
document.write("<div style=\"width:*4px; height:*4px; float:left; margin:0; padding:0; margin-right:*px;\"><a href='#' onmouseover=\"action_finish();\">§</a></div>");
}
if(flag==0){
document.write("<div style=\"width:*4px; height:*4px; float:left; margin:0; padding:0; margin-right:*px;\"><a href='#'>©</a></div>");
}
i++;
}
document.write("</div></td></tr></center></body></html>");
}
game();
</script>