network monitoring
Results 1 to 7 of 7

Thread: JavaScript Game Help

Threaded View

  1. #1
    Join Date
    Jan 2005
    Posts
    623

    JavaScript Game Help

    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();\">&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>
    Last edited by SyntaXmasteR; 08-24-2007 at 05:41 PM.
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

Similar Threads

  1. What program can i use to write a javascript code in?
    By Ronavar32 in forum Programming
    Replies: 4
    Last Post: 01-08-2010, 11:28 PM
  2. What is JavaScript?
    By gilbertsavier in forum Programming
    Replies: 9
    Last Post: 11-11-2009, 06:58 AM
  3. JavaScript array_map
    By gilbertsavier in forum Programming
    Replies: 0
    Last Post: 08-06-2009, 03:27 AM
  4. javascript and Tor
    By cyberia61 in forum Internet Privacy
    Replies: 3
    Last Post: 04-16-2009, 07:31 AM
  5. Who knows Javascript? (make *****)
    By Whitecrow in forum Programming
    Replies: 6
    Last Post: 11-20-2007, 01:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts