Cheeseweasel Posted April 14, 2007 Share Posted April 14, 2007 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 More sharing options...
Barand Posted April 14, 2007 Share Posted April 14, 2007 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>"); ?> Link to comment https://forums.phpfreaks.com/topic/47036-two-variables-equal-values/#findComment-229410 Share on other sites More sharing options...
Barand Posted April 14, 2007 Share Posted April 14, 2007 As for 1st question, just call srand() once (with later versions of PHP it's not needed at all) Link to comment https://forums.phpfreaks.com/topic/47036-two-variables-equal-values/#findComment-229413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.