[advanced search]
Results from the most recent live auction are here.
16 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 03-01-2008, 10:33 AM   · #1
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,561
NP$: 93.00 (Donate)
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'] . '"'));
        
$your_pack = mysql_fetch_array(mysql_query('SELECT * FROM `pack` WHERE `mecha_owner` = "' . $your_mecha['id'] . '"'));
        
        
$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'];
        
    
// fighting
    /* determine who is first by who has better agility */
    
if ($your['agility'] > $enemy['agility'])
    {
        
    }
        
    else
    {
    }
        

    
// if both alive fight again
}


Please register or log-in into NamePros to hide ads
liam_d is offline   Reply With Quote
Old 03-01-2008, 04:06 PM   · #2
JFS
DNOA Member
 
JFS's Avatar
 
Name: Joćo Fernandes Silva
Location: Portugal
Trader Rating: (29)
Join Date: Oct 2005
Posts: 698
NP$: 14.95 (Donate)
JFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really nice
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
Your Proxy Host - Currently not acepting new customers - for custom packages contact me
JFS is offline   Reply With Quote
Old 03-02-2008, 01:18 PM   · #3
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,561
NP$: 93.00 (Donate)
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'] . '"'));

        

    
$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'];

    
//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 05:06 AM.
liam_d is offline   Reply With Quote
Old 03-05-2008, 03:35 PM   · #4
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,561
NP$: 93.00 (Donate)
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   Reply With Quote
Old 03-13-2008, 06:58 PM   · #5
xlusive
Pro Coder & Designer
 
xlusive's Avatar
 
Name: Karim
Location: Netherlands
Trader Rating: (37)
Join Date: Apr 2005
Posts: 962
NP$: 62.00 (Donate)
xlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive 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);

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
    /*
    $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 {

    }

}
?>
__________________
Capix
Dragonball RPG
Mamuzin
xlusive is offline   Reply With Quote
Old 03-14-2008, 05:26 AM   · #6
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,561
NP$: 93.00 (Donate)
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   Reply With Quote
Old 03-14-2008, 07:51 AM   · #7
xlusive
Pro Coder & Designer
 
xlusive's Avatar
 
Name: Karim
Location: Netherlands
Trader Rating: (37)
Join Date: Apr 2005
Posts: 962
NP$: 62.00 (Donate)
xlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive 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?
__________________
Capix
Dragonball RPG
Mamuzin
xlusive is offline   Reply With Quote
Old 03-18-2008, 11:59 PM   · #8
jessemiller
New Member
 
Trader Rating: (0)
Join Date: Mar 2008
Posts: 5
NP$: 0.00 (Donate)
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 12:04 AM.
jessemiller is offline   Reply With Quote
Old 04-06-2008, 02:55 PM   · #9
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,561
NP$: 93.00 (Donate)
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   Reply With Quote
Old 04-07-2008, 06:45 AM   · #10
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,561
NP$: 93.00 (Donate)
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'] . '"'));
                
            
$this->enemy['strength'] = $this->enemy_mecha['strength'] + $enemy_weapon['power'];
            
$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<