Hey guys, I've got a bit of a weird problem...
I'm working on a temporary battle system for a game, and the thing acts... Weird. I have a variable that keeps unsettling, and I can't quite figure out why, It's the $mhp variable.
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Broken Battle System</title>
<style type='text/css'>
<!--
.style1 {
color: #FF0000;
font-weight: bold;
}
.style4 {color: #FF0000; font-weight: bold; }
.style5 {color: #FF0000; font-weight: bold;}
.style6 {color: #00CC33; font-weight: bold;}
-->
</style>
</head>
<body>
<div align='center'>
<p>You are fighting: A monster?</p>
<p>There normally would be a image here, but there is not.</p>
<p>You are fighting a firece monster, the<br />
likes of which you have never seen...<br />
Hence, why there is no picture here.</p>
<p>
<?php
$inbattle = $_REQUEST['inbattle'];
$frmmnu = $_REQUEST['frmmnu'];
$plhp = $_REQUEST['plhp'];
$mhp = $_REQUEST['mhp'];
$ml = 1;
$hit = rand(1, 20);
$atk = rand(1, 10);
$dmg = rand($ml, $ml * 4);
$mbp = $mhp;
if ( $hit <=5 ) {
if ( $atk <= 5 ) {
echo "It bites your ankle for <span class='style5'> ".$dmg." damage</span>.<br />";
$mhp = $mbp - $dmg;
} else {
echo "It fails to bite you. It's obviously a failsaurous.<br />";
}
}
elseif ( $hit >= 5 && $hit <= 10 ) {
if ($atk <= 5) {
echo "It knees you in the crotch for <span class='style5'> ".$dmg." damage</span>.<br />";
$mhp = $mbp - $dmg;
} else {
echo "It tries to kick you, but ends up wrenching it's leg in the process.<br />";
}
}
elseif ( $hit >= 10 && $hit <= 15)
{ if ( $atk <= 5 ) {
echo "It bites your nose for <span class='style5'> ".$dmg." damage</span>.<br />";
$mhp = $mbp - $dmg;
} else {
echo "It flies at you like a bat out of the night, and finds nothing but wall.<br />";
}
} else {
$dmg = $dmg * 2;
echo "It stabs you in the back with it's slimy claws for <span class='style5'> ".$dmg." damage</span>.<br/>";
$mhp = $mbp - $dmg;
}
echo "Posted: ".$mhp." <br />";
/*End of Section 1*/
$lvl = 1;
$phit = rand(1, 20);
$patk = rand(1, 10);
$pdmg = rand($lvl, $lvl * 4);
if ( $phit <=5 ) {
if ( $patk <= 5 ) {
echo "You catch it in the ribs for <span class='style6'> ".$pdmg." damage</span>.<br />";
} else {
echo "You swing, and you miss.</br>";
}
}
elseif ( $phit >= 5 && $phit <= 10 ) {
if ($patk <= 5) {
echo "You hit it in the face for <span class='style6'> ".$pdmg." damage</span>.<br />";
} else {
echo "You punch it in the face, but it's made of stronger stuff then that.<br />";
}
}
elseif ( $phit >= 10 && $phit <= 15)
{ if ( $patk <= 5 ) {
echo "You kick it in the groin for <span class='style6'> ".$pdmg." damage</span>.<br />";
} else {
echo "You try to kick it, but you slip on a well placed banana peel and fall down.</p>";
}
} else {
echo "You take out your confused, angsty fury on it for <span class='style6'> ".$pdmg." damage</span>.<br/>";
}
if ($mhp = 0) {
$frmmnu = 0;
echo"
<p>You win the Fight!<br />
You gain ??? Substats.<br />
<br />
You find a Wand of Many Glitches!<br />
You find the Ring of Power!</p>
"; }
if ($frmmnu = 1) { // 1
echo "
<form id='form1' name='form1' method='post' action='battle.php'>
<input type='submit' name='atk' id='atk' value='Attack' />
<input type='hidden' name='hiddenField' id='inbattle' value='1'>
<input type='hidden' name='hiddenField2' id='frmmnu' value='".$frmmnu."'>
<input type='hidden' name='hiddenField3' id='plhp' value='".$plhp."'>
<input type='hidden' name='hiddenField4' id='mhp' value='".$mhp."'>
</form>
<form id='form2' name='form2' method='post' action=''>
Use Skill(not working yet)
<select name='skl' id='skl'>
</select>
<input type='submit' name='cmbuit' id='cmbuit' value='Do this!' />
</form>
<form id='form3' name='form3' method='post' action=''>
Use Item(not working yet)
<select name='itm' id='itm'>
</select>
<input type='submit' name='itmdis' id='itmdis' value='Do this!' />
</form>
<form id='form4' name='form4' method='post' action=''>
Use Power(not working yet)
<select name='dp' id='dp'>
</select>
<input type='submit' name='dpuse' id='dpuse' value='Use the POWER!' />
</form><br /><br />
";}
else {
echo " <form id='form1' name='form1' method='post' action='entry.php'>
<input type='submit' name='atk' id='atk' value='Try Again?' />
</form><br /><br />";
}
echo "Debug monster: ".$atk."-attack-".$dmg."-Damage-".$hit."-hit-".$mhp."-Monster HP<br />";
echo "Debug player: ".$patk."-attack-".$pdmg."-Damage-".$phit."-hit";
?>
</div>
</body>
</html>
I also have a live version. To enter the program main, you have to be shepherded through another page. The page is here.
I've played with variable outputs throughout the thing, and my own exploring finds that it seems to disappear just before the section I've marked "// 1". Any thoughts?