NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [PHP] making a battle script

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-01-2008, 11:33 AM THREAD STARTER               #1 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




[PHP] making a battle script


Well i have started making a battle script for use in my game but i am really stuck

i have all the values ready to use but i'm not exactly sure how to make the you and them battle?

PHP Code:
function fight($you$them)
{
    
$get_your_mecha mysql_query('SELECT * FROM `mecha` WHERE `owner` = "' . (int) $you '"');
    
$your_mecha mysql_fetch_array($get_your_mecha);
        
    
$get_enemy_mecha mysql_query('SELECT * FROM `mecha` WHERE `owner` = "' . (int) $them '"');
    
$enemy_mecha mysql_fetch_array($get_your_mecha);
        
        if (
$your_mecha['armour'] <= 0)
        {
            echo 
'You need to repair your Mecha before you can battle!';
        }
        
        if (
$your_mecha['armour'] <= 0)
        {
            echo 
'You need to repair your Mecha before you can battle!';
        }
        
        
// set your stats here
        
$your_weapon mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));
        
$your_armour mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));
????: NamePros.com http://www.namepros.com/programming/439066-php-making-a-battle-script.html
        
$your_pack mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));
        
        
$your['strength'] = $your_mecha['strength'] + $your_weapon['power'];
????: NamePros.com http://www.namepros.com/showthread.php?t=439066
        
$your['armour'] = $your_mecha['armour'] + $your_armour['power'];
        
$your['agility'] = $your_mecha['agility'] +  + $your_agility['power'];
        
        
// set enemy stats here
        
$enemy_weapon mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));
        
$enemy_armour mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));
        
$enemy_pack mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));
        
    
$enemy['strength'] = $enemy_mecha['strength'] + $enemy_weapon['power'];
    
$enemy['armour'] = $enemy_mecha['armour'] + $enemy_armour['power'];
    
$enemy['agility'] = $enemy_mecha['agility'] +  + $enemy_agility['power'];
        
    
// fighting
    /* determine who is first by who has better agility */
    
if ($your['agility'] > $enemy['agility'])
    {
        
    }
        
    else
    {
    }
        

    
// if both alive fight again

liam_d is offline  
Old 03-01-2008, 05:06 PM   #2 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
Join Date: Oct 2005
Location: Portugal
Posts: 800
JFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to all
 



here are some thoughts:

Hit chance:

$your['hitchance'] = $your_mecha['agility'] / ( $your['agility'] - $enemy_mecha['agility'] )
$enemy['hitchance']= $enemy_mecha['agility'] / ( $enemy['agility'] - $your_mecha['agility'] )

Combat damage:

$your['maxdamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour']
$your['mindamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'] + $enemy_armour['power']

( the same for the enemy )
__________________
Joćo Fernandes Silva
JFS is offline  
Old 03-02-2008, 02:18 PM THREAD STARTER               #3 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Thanks for the input, here is what i have now, think all that is left is to actually do the battle, to which i am unsure about how to do?

PHP Code:
<?php

function fight($you$them)

{

    
$get_your_mecha mysql_query('SELECT * FROM `mecha` WHERE `owner` = "' . (int) $you '"');

    
$your_mecha mysql_fetch_array($get_your_mecha);

        

    
$get_enemy_mecha mysql_query('SELECT * FROM `mecha` WHERE `owner` = "' . (int) $them '"');

    
$enemy_mecha mysql_fetch_array($get_your_mecha);

        

    if (
$your_mecha['armour'] <= 0)

    {

        echo 
'You need to repair your Mecha before you can battle!';

    }

        

    if (
$your_mecha['armour'] <= 0)

    {

        echo 
'You need to repair your Mecha before you can battle!';

    }

        

    
// set your stats here

    
$your_weapon mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));

    
$your_armour mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));

    
$your_pack mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));

        
????: NamePros.com http://www.namepros.com/showthread.php?t=439066

    
$your['strength'] = $your_mecha['strength'] + $your_weapon['power'];

    
$your['armour'] = $your_mecha['armour'] + $your_armour['power'];

    
$your['agility'] = $your_mecha['agility'] +  + $your_agility['power'];

        

    
// set enemy stats here

    
$enemy_weapon mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));

    
$enemy_armour mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));

    
$enemy_pack mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));

        

    
$enemy['strength'] = $enemy_mecha['strength'] + $enemy_weapon['power'];

    
$enemy['armour'] = $enemy_mecha['armour'] + $enemy_armour['power'];

    
$enemy['agility'] = $enemy_mecha['agility'] +  + $enemy_agility['power'];



    
// chance of hitting first



    
$your['hitchance'] = $your_mecha['agility'] / ( $your['agility'] - $enemy_mecha['agility'] );

    
$enemy['hitchance'] = $enemy_mecha['agility'] / ( $enemy['agility'] - $your_mecha['agility'] );

    

    
//Combat damage:

    

    
$your['maxdamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'];

    
$your['mindamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'] + $enemy_armour['power'];
????: NamePros.com http://www.namepros.com/showthread.php?t=439066

    
//Combat damage:

    

    
$enemy['maxdamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'];

    
$enemy['mindamage'] = $enemy_mecha['strength'] + $enemy_weapon['power'] - $your_mecha['armour'] + $your_armour['power'];

    

    
// if your go first

    
if ($your['hitchance'] > $enemy['hitchance'])

    {

    }

    

    
// if enemy go first

    
else

    {

    }

}

?>
Last edited by liam_d; 03-06-2008 at 06:06 AM.
liam_d is offline  
Old 03-05-2008, 04:35 PM THREAD STARTER               #4 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




friendly bump, any ideas?
liam_d is offline  
Old 03-13-2008, 07:58 PM   #5 (permalink)
Pro Coder & Designer
 
aween's Avatar
Join Date: Apr 2005
Location: Netherlands
Posts: 967
aween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really nice
 



This is how i would do it :
This is not tested- just written to give you a idea

PHP Code:
<?php
function fight($you$them) { 

$get_your_mecha mysql_query('
SELECT 
user.id,user.strength,user.armour,user.agility, 
weapon.power as weapon_power, 
armour.power as armour_power, 
agility.power as agility_power

FROM mecha as user
LEFT JOIN weapon
ON weapon.mecha_owner = $you
AND
LEFT JOIN armour
ON armour.mecha_owner = $you
AND
LEFT JOIN pack
ON pack.mecha_owner = $you

WHERE user.owner = "' 
. (int) $you '"'); 
$you mysql_fetch_array($get_your_mecha); 

$get_enemy_mecha mysql_query('
SELECT 
user.id,user.strength,user.armour,user.agility, 
weapon.power as weapon_power, 
armour.power as armour_power, 
agility.power as agility_power

FROM mecha as user
LEFT JOIN weapon
ON weapon.mecha_owner = $them
AND
LEFT JOIN armour
ON armor.mecha_owner = $them
AND
LEFT JOIN pack
ON pack.mecha_owner = $them

WHERE user.owner = "' 
. (int) $them '"'); 
); 
$enemy mysql_fetch_array($get_enemy_mecha); 

????: NamePros.com http://www.namepros.com/showthread.php?t=439066
if (
$you['armour_power'] <= 0)  {
echo 
'You need to repair your Mecha before you can battle!'
}
    
/*$your_weapon = mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' . $your_mecha['id'] . '"')); 
    $your_armour = mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' . $your_mecha['id'] . '"')); 
    $your_pack = mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' . $your_mecha['id'] . '"')); 
    */
         

    
$you['strength'] = $you['strength'] + $you['weapon_power']; 
    
$you['armour'] = $you['armour'] + $you['armour_power']; 
    
$you['agility'] = $you['agility'] + $you['agility_power']; 
    
// set enemy stats here 
????: NamePros.com http://www.namepros.com/showthread.php?t=439066
    /*
    $your['strength'] = $your_mecha['strength'] + $your_weapon['power']; 

    $your['armour'] = $your_mecha['armour'] + $your_armour['power']; 

    $your['agility'] = $your_mecha['agility'] +  + $your_agility['power']; 
    

    $enemy_weapon = mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' . $enemy_mecha['id'] . '"')); 
    $enemy_armour = mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' . $enemy_mecha['id'] . '"')); 
    $enemy_pack = mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' . $enemy_mecha['id'] . '"')); 
    $enemy['strength'] = $enemy_mecha['strength'] + $enemy_weapon['power']; 
    $enemy['armour'] = $enemy_mecha['armour'] + $enemy_armour['power']; 
    $enemy['agility'] = $enemy_mecha['agility'] +  + $enemy_agility['power']; 
*/
    
    
$enemy['strength'] = $enemy['strength'] + $enemy['weapon_power']; 
    
$enemy['armour'] = $enemy['armour'] + $enemy['armour_power']; 
    
$enemy['agility'] = $enemy['agility'] + $enemy['agility_power']; 


    
$your['hitchance'] = $you['agility'] / ( $you['agility'] - $enemy['agility'] ); 
    
$enemy['hitchance'] = $enemy['agility'] / ( $enemy['agility'] - $you['agility'] ); 
   
    
$your['maxdamage'] = $you['strength'] + $you['weapon_power'] - $enemy['armour_power']; 
    
$your['mindamage'] = $you['strength'] + $you['weapon_power'] - $enemy['armour_power'] + $enemy['armour_power']; 

    
//Combat damage: 
    
$enemy['maxdamage'] = $you['strength'] + $your['weapon_power'] - $enemy['weapon_armour']; 
    
$enemy['mindamage'] = $enemy['strength'] + $enemy['weapon_power'] - $you['armour'] + $your['weapon_power']; 

    
// if your go first 

    
if ($your['hitchance'] > $enemy['hitchance']) { 
    } else { 

    } 


?>
__________________
aween web development
aween is offline  
Old 03-14-2008, 06:26 AM THREAD STARTER               #6 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Thanks for the post this will help quite a lot i think and will definitely make it faster since using less queries .

What i need now is to do the actual battle, which i have no idea how to do properly

Thanks!
liam_d is offline  
Old 03-14-2008, 08:51 AM   #7 (permalink)
Pro Coder & Designer
 
aween's Avatar
Join Date: Apr 2005
Location: Netherlands
Posts: 967
aween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really nice
 



basically - you can do like the above - you have to add certain health (which is i guess armour) to be deducted from the total amount untill one of them drops to zero
might be handy if they can choose what attack - since i assume every attack has their own strength?
__________________
aween web development
aween is offline  
Old 03-19-2008, 12:59 AM   #8 (permalink)
New Member
Join Date: Mar 2008
Posts: 5
jessemiller is an unknown quantity at this point
 



I wrote this up in this post when i saw your post, so i definately didnt test it, but its a very good start to the direction your heading in

Code:
<?
session_start();

// lets tell the script that if the user is not logged in they cannot access
// the game, when the user is logging in, some variable should be
// set that they are logged in, a basic easy one is
// $_SESSION['loggedin']=1;
// and when they logout destroy the session, google is your friend.

if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }

$userid=$_SESSION['userid']; //assuming you have sessions set
$id=$_GET['userid']; // assuming the url uses a GET function

$z=mysql_query("SELECT * FROM users WHERE userid='$userid'");
$x=mysql_fetch_array($z);

// Protect the admin, you.

if($_GET['userid'] == '1') {
print "You cannot attack the admin, i am all powerful"; die;
}

// Lets make sure they are not attacking themselves

if($_GET['userid'] == '$userid') {
print "You cannot attack yourself"; die;
}

if(isset($_GET['userid'])) {
$q=mysql_query("SELECT * FROM users WHERE userid='$id'");
$r=mysql_fetch_array($q);

// Set some variables

$offender=$x['name'];
$defender=$r['name'];
$offhealth=$x['health'];
$defhealth=$r['health'];
$offstat1=$x['stat1'];
$defstat1=$r['stat1'];
$offstat2=$x['stat2'];
$defstat2=$r['stat2'];

// Lets make sure the user isn't trying to kill a dead user
// Or trying to kill people even though they are dead

if($offhealth<1) {
print "You are dead, you cannot attack while dead, jerk."; die;
}

if($defhealth<1) {
print "This Player Is Dead"; die;
}

// Set a random factor so the most powerful is not always the winner

$offrand=rand(0,100);
$defrand=rand(0,100);
$rand=rand(100,999);

// Do some math

$offpower=($offstat1+$offstat2+$offrand);
$defpower=($defstat1+$defstat2+$defrand);

$offdamage=($defpower-$defrand/*3);
$defdamage=($offpower-$offrand/*3);

// This is where you let the user know what is going on
// Send them to a link
// attack.php?userid=$id&math=$rand
// Print the names and health of each user

if($offpower>$defpower){

// print the action that took place, defense lost health

mysql_query("UPDATE users SET health=health-'$defdamamge' WHERE userid='$id'"); }

if($offpower<$defpower){

// print the action that took place, offense lost health

mysql_query("UPDATE users SET health=health-'$offdamamge' WHERE userid='$userid'"); }

// when a player reaches 1 health or lower it will state the player is dead
// this script will need editing if stats are involved
// but this is a good start to get you on your way
}
?>
I hope this helps you bud.
Last edited by jessemiller; 03-19-2008 at 01:04 AM.
jessemiller is offline  
Old 04-06-2008, 03:55 PM THREAD STARTER               #9 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Originally Posted by JFS
here are some thoughts:

Hit chance:

$your['hitchance'] = $your_mecha['agility'] / ( $your['agility'] - $enemy_mecha['agility'] )
$enemy['hitchance']= $enemy_mecha['agility'] / ( $enemy['agility'] - $your_mecha['agility'] )

Combat damage:

$your['maxdamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour']
$your['mindamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'] + $enemy_armour['power']

( the same for the enemy )
Just a question about the hitchance here, why is the hitchance for myself for example be my agility divided by my agility take the enemys agility?
Is that the best way?
liam_d is offline  
Old 04-07-2008, 07:45 AM THREAD STARTER               #10 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Okay i have gotten it working for all but one thing, the attack_back function and the hitchance dont seem to work properly, for one thing i seem to always attack first even if the enemy hitchance is bigger and i always attack_back not the enemy?

PHP Code:
<?php
class attacking
{
    var 
$your;
    var 
$enemy;
    var 
$your_mecha;
    var 
$enemy_mecha;
    
    function 
fight($you$them)
    {
        
$get_your_mecha mysql_query('SELECT * FROM `mecha` WHERE `owner` = "' . (int) $you '"');
        
$this->your_mecha mysql_fetch_array($get_your_mecha);
            
        
$get_enemy_mecha mysql_query('SELECT * FROM `mecha` WHERE `owner` = "' . (int) $them '"');
        
$this->enemy_mecha mysql_fetch_array($get_enemy_mecha);
        
        if (
$this->your_mecha['armour'] <= 0)
        {
            echo 
'You need to repair your Mecha before you can battle!';
        }
            
        else if (
$this->enemy_mecha['armour'] <= 0)
        {
            echo 
'The enemy has already been disabled!!';
        }
        
        else
        {
            
            
// set your stats here
            
$your_weapon mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));
            
$your_armour mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));
            
$your_pack mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' $your_mecha['id'] . '"'));
                
            
$this->your['strength'] = $this->your_mecha['strength'] + $your_weapon['power'];
            
$this->your['armour'] = $this->your_mecha['armour'] + $your_armour['power'];
            
$this->your['agility'] = $this->your_mecha['agility'] +  + $your_agility['power'];
                
            
// set enemy stats here
            
$enemy_weapon mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));
            
$enemy_armour mysql_fetch_array(mysql_query('SELECT * FROM `armour` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));
            
$enemy_pack mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' $enemy_mecha['id'] . '"'));
????: NamePros.com http://www.namepros.com/showthread.php?t=439066
                
            
$this->enemy['strength'] = $this->enemy_mecha['strength'] + $enemy_weapon['power'];
????: NamePros.com http://www.namepros.com/showthread.php?t=439066
            
$this->enemy['armour'] = $this->enemy_mecha['armour'] + $enemy_armour['power'];
            
$this->enemy['agility'] = $this->enemy_mecha['agility'] +  + $enemy_agility['power'];
        
            
// chance of hitting first
        
            
$this->your['hitchance'] = $this->your_mecha['agility'] - $this->enemy_mecha['agility'];
            
$this->enemy['hitchance'] = $this->enemy_mecha['agility'] - $this->your_mecha['agility'];
            
            
//Combat damage:
            
            
$this->your['maxdamage'] = $this->your_mecha['strength'] + $your_weapon['power'];
            
$this->your['mindamage'] = $this->your_mecha['strength'] + $your_weapon['power'] / 3;
        
            
//Combat damage:
            
            
$this->enemy['maxdamage'] = $this->enemy_mecha['strength'] + $enemy_weapon['power'];
            
$this->enemy['mindamage'] = $this->enemy_mecha['strength'] + $enemy_weapon['power'] / 3;
            
            
// if your go first
            
if ($this->your['hitchance'] > $this->enemy['hitchance'])
            {
                
$this->attack(1);
            }
            
            
// if enemy go first
            
else
            {
                
$this->attack(2);
            }
        }
    }
    
    
// for first attack
    
function attack ($first)
    {
        if (
$first 1)
        {
            
// Get power of attack as a random number between min and max damage you can cause
            
$power rand($this->your['mindamage'], $this->your['maxdamage']);
            
            
// take that power away from enemy armour
            
$this->enemy['armour'] = $this->enemy['armour'] - $power;
            
            echo 
"You attack the enemy and cause {$power} damage. Enemy armour is now at {$this->enemy['armour']}<br />";
            
            if (
$this->enemy['armour'] <= 0)
            {
                
mysql_query("UPDATE `mecha` SET `armour` = '0' WHERE `id` = '{$this->enemy_mecha['id']}'");
                echo 
'You have disabled the enemy, you have won the battle!<br />';
            }
                
            else
            {
                
$this->attack_back(2);
            }
        }
        
        else if (
$first 2)
        {
            
// Get power of attack as a random number between min and max damage you can cause
            
$power rand($this->enemy['mindamage'], $this->enemy['maxdamage']);
            
            
// take that power away from enemy armour
            
$this->your['armour'] = $this->your['armour'] - $power;
            
            echo 
"The enemy attacks and causes {$power} damage. Your armour is now at {$this->your['armour']}<br />";
            
            if (
$this->your['armour'] <= 0)
            {
                
mysql_query("UPDATE `mecha` SET `armour` = '0' WHERE `id` = '{$this->your_mecha['id']}'");
                echo 
'You have disabled the enemy, you have won the battle!<br />';
            }
                
            else
            {
                
$this->attack_back(1);
            }
        }
    }
    
    
// for all other attacking
    
function attack_back ($who)
    {
        if (
$who 1)
        {
            
// Get power of attack as a random number between min and max damage you can cause
            
$power rand($this->your['mindamage'], $this->your['maxdamage']);
            
            
// take that power away from enemy armour
            
$this->enemy['armour'] = $this->enemy['armour'] - $power;
            
            echo 
"You attack the enemy again and cause {$power} damage. Enemy armour is now at {$this->enemy['armour']}<br />";
            
            if (
$this->enemy['armour'] <= 0)
            {
                
mysql_query("UPDATE `mecha` SET `armour` = '0' WHERE `id` = '{$this->enemy_mecha['id']}'");
                echo 
'You have disabled the enemy, you have won the battle!<br />';
            }
                
            else
            {
                
$this->attack_back(2);
            }
        }
        
        else if (
$who 2)
        {
            
// Get power of attack as a random number between min and max damage you can cause
            
$power rand($this->enemy['mindamage'], $this->enemy['maxdamage']);
            
            
// take that power away from enemy armour
            
$this->your['armour'] = $this->your['armour'] - $power;
            
            echo 
"The enemy attacks again and causes {$power} damage. Your armour is now at {$this->your['armour']}<br />";
            
            if (
$this->your['armour'] <= 0)
            {
                
mysql_query("UPDATE `mecha` SET `armour` = '0' WHERE `id` = '{$this->your_mecha['id']}'");
                echo 
'You have disabled the enemy, you have won the battle!<br />';
            }
                
            else
            {
                
$this->attack_back(1);
            }
        }
    }
}
?>
liam_d is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:43 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger