Jump to content

Two Variables, Equal Values - ?


Cheeseweasel

Recommended Posts

After seeing a script programmed by a user in the beta-test section, I copied its premise - a man vs. dragon battle, with random damage being done.

 

It just takes random numbers each time the page loads for damage values. That's all it does.

 

However, whenever I play it, the end HP for both man and dragon are exactly the same.

 

I need 2 things done, or at least to know how to do them -

 

1) I need to know how to fix the equal-HP problem

2) I would like it if someone could tell me how to achieve the effect of a

<br>

...tag within a PHP script.

 

Here's the script!

 

<center>A Very Very Simple RPG<br>
<i>You are man. Man must kill dragon. Refresh page for new battle!</i></center><

<?php
$dragonhealth = 10;
$manhealth = 10;
echo("Your health = $manhealth");
echo("Dragon's health = $dragonhealth");
echo("You attack the dragon!");
srand(time());
$random = (rand()%10);
print("You do $random damage to the dragon!");
$dragonhealth2 = $dragonhealth - $random;
echo("Your health = $manhealth");
echo("Dragon's health = $dragonhealth2");
?>

<?php
echo("The dragon breathes fire at you...");
srand(time());
$random2 = (rand()%10);
print("Dragon does $random2 damage...");
$manhealth2 = $manhealth - $random2;
echo("Your health = $manhealth2");
echo("Dragon's health = $dragonhealth2");
?>

<?PHP
if ( $manhealth2 > $dragonhealth2  ) {
echo "Man wins!";
} else {
echo "Dragon wins!";
}
?>

 

Thanks in advance

-C.W

Link to comment
https://forums.phpfreaks.com/topic/47036-two-variables-equal-values/
Share on other sites

As for your 2nd question, just include the br tag in the text

 

<?php
$dragonhealth = 10;
$manhealth = 10;
echo("Your health = $manhealth<br>");
echo("Dragon's health = $dragonhealth<br>");
echo("You attack the dragon!<br>");
srand(time());
$random = (rand()%10);
print("You do $random damage to the dragon!<br>");
$dragonhealth2 = $dragonhealth - $random;
echo("Your health = $manhealth<br>");
echo("Dragon's health = $dragonhealth2<br>");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.