Jump to content

php game help


ksun

Recommended Posts

hi this is the skeleton code for a simple game thats suppose to take away 10 hp from enemy_hp each time the fight button is pressed but there seems to be something wrong with it, if anyone can help out, that would be gr8. the enemy hp seems to not fall below 90.

<?php


include('config.php');
include('user.php');
if(!loggedin())
{
header("Location: login.php");
}
$fight = $_POST['fight'];
if($fight)
{
$defult = false;
$enemy_hp = $enemy_hp - 10;
echo $enemy_hp;
}

if(defult){
$user_hp = 100;
$enemy_hp = 100;
}
$defult = true;
?>
<body>
<table width="444" height="278" border="3">
 <tr>
   <td width="212"><form id="form1" name="form1" method="POST" action="">
  <?php
echo $user."\n <br>";

echo "hp = ".$user_hp;
?>
  <p><img src="images/monkey.png" width="108" height="97" /></p>
  <p>
    <input type="radio" name="attack"  value="attack" />
    attack</p>
  <p>
    <input type="radio" name="attack"  value="radio" />
    defend</p>
  <p>
    <input type="radio" name="attack"  value="radio" />
    skill 1 </p>
  <p>
    <input type="radio" name="attack"  value="radio" />
    <label for="radio"></label>
    skill 2</p>
  <p>
    <input type="radio" name="attack"  value="radio" />
    skill 3</p>
  <p>
    <input type="radio" name="attack"  value="radio" />
    skill 4</p>
  <p>
    <input type="submit" name="fight"  value="fight" />
  </p>
   </form></td>
   <td width="212"> 
<?php
echo "ENEMY <br>";

echo "hp = ".$enemy_hp;
?>
 </tr>
</table>
</body>

Link to comment
Share on other sites

It's because your script don't save $enemy_hp. PHP is server scripting language that means it's executed on server side so your code is terminated. You must save values to text file or better would be write it to database and then when script is executed, it must read $enemy_hp value. Maybe you would be interested with javascript and jQuery to do such things because variables are still available in memory of your computer.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.