Thread: Javascript combat system.

Results 1 to 4 of 4
  1. #1 Javascript combat system. 
    Registered Member
    Logical's Avatar
    Join Date
    Jan 2008
    Posts
    1,284
    Thanks given
    11
    Thanks received
    29
    Rep Power
    328
    This is by no means perfect.

    Take a sneeky look:
    [Only registered and activated users can see links. ]

    And because I'm kind:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var c = 0;
    var t;
    var timer_is_on = 0;
    
    var strength = 30; //Your strength level
    var health = 100; //Your health level
    
    var ostrength = 30; //Opponents strength level
    var ohealth = 100; //Opponents health level
    
    function fight() //Begin the fight
    {
    //update each turn
    document.getElementById('status').value = status;
    document.getElementById('ohealth').value = ohealth;
    document.getElementById('health').value = health;
    
    
    	if(health > 0 & ohealth > 0){
    	
    	    //Your turn
    		hit = Math.random()*strength;
    		hit = Math.round(hit); 
    		ohealth = ohealth - hit;
    		document.getElementById('ohealth').value = ohealth;
    		status = "You hit a " + hit;
            document.getElementById('status').value = status;
    		
    		pausecomp(1000);
    
    		//Opponents turn
    		ohit = Math.random()*ostrength;
    		ohit = Math.round(ohit); 
    		health = health - ohit;
    		document.getElementById('health').value = health;
    		status = "Your opponent hit a " + ohit;
    		document.getElementById('status').value = status;
    		
    		
    		t=setTimeout("fight()",2000);
    		
    	} else {
    	
    	if(health <= 0) {
    	status = "You Died.";
    	} else {
    	status = "You Won.";
    	}
    	document.getElementById('status').value = status;
    	}
    
    }
    
    function pausecomp(millis)
    {
    var date = new Date();
    var curDate = null;
    
    do { curDate = new Date(); }
    while(curDate-date < millis);
    } 
    
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Fight!" onClick="fight()"><br>
    Opponents Health:<input type="text" size="1" id="ohealth">
     Health:<input type="text" size="1" id="health">
     <br>
     Status:<input type="text" size="30" id="status">
    </form>
    </body>
    </html>

    Reply With Quote  
     

  2. #2  
    Valar Morghulis

    Laxika's Avatar
    Join Date
    Sep 2006
    Age
    29
    Posts
    2,813
    Thanks given
    1,804
    Thanks received
    274
    Rep Power
    2128
    Uhh nice. I never thinking to do somthing like this, cuz it's not secure at real games. But it's looks nice.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. #3  
    Registered Member
    Logical's Avatar
    Join Date
    Jan 2008
    Posts
    1,284
    Thanks given
    11
    Thanks received
    29
    Rep Power
    328
    Thanks, yeh just did it for a bit of fun.

    Reply With Quote  
     

  4. #4  
    Rawr.


    Join Date
    Oct 2008
    Age
    25
    Posts
    2,166
    Thanks given
    10
    Thanks received
    51
    Rep Power
    1326
    wow thats cool you just gotta fix the -4



    Was good while it lasted

    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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