PDA

View Full Version : JavaScript Game Help



SyntaXmasteR
08-24-2007, 12:56 PM
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 [game] (http://www.syntax******.info/test/monster_game.php) and here is the 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();\">&Oslash;</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();\">&sect;</a></div>");
}

if(flag==0){
document.write("<div style=\"width:*4px; height:*4px; float:left; margin:0; padding:0; margin-right:*px;\"><a href='#'>&copy;</a></div>");
}

i++;
}
document.write("</div></td></tr></center></body></html>");

}

game();

</script>

Moonbat
08-24-2007, 03:07 PM
Why don't you just make it so that when the person finishes the game (wins it), the page just reloads? It's a simple lazy way of getting around this.

SyntaXmasteR
08-24-2007, 03:20 PM
Because they do not WIN! Muhahaha!

Actually I will make different levels. When one level is finished it will load the next level, more monsters, more possibilities. I will add a timer and score each person on each level, but first I need to figure out a way to load the next level. I learn nothing taking the easy way out.

Ezekiel
08-24-2007, 04:39 PM
For hax, drag your cursor over the whole block to highlight it. Monsters will reveal themselves.

SyntaXmasteR
08-24-2007, 04:44 PM
Stop Haxing my MONSTER! game!

I actually changed the symbols to make it easier for me to debug :D

Ezekiel
08-24-2007, 05:33 PM
Sorry to bring more hax, but ctrl+a is cheat #2.

It looks like you've improved it since I last checked, since now the icon moves with the cursor. This is like Minesweeper! I'm getting better at it.

SyntaXmasteR
08-24-2007, 06:00 PM
LoL

Ok thats it! No more hax for you! All are &copy;