Is it possible to include one function inside another? To learn functions, I'm trying to create a combat sequence using PHP. The sequence would look like this:
- Dice would roll, assigning numbers to variables;
- Hero1 attack results are printed;
- Dice would roll, assigning numbers to variables;
- Hereo2 attack results are printed;
- Dice would roll, assigning numbers to variables;
- Hero3 attack results are printed.
The dice rolling would be an automated function. Here is the code:
<?
rollSim();
combatSim();
function rollSim() {
$hAttack = rand(1,20);
$mDefend = rand(1,20);
$mAttack = rand(1,20);
$hDefend = rand(1,20);
$mDamage = rand(10,25);
$hDamage = rand(1,20);
} // end rollSim
function combatSim() {
rollSim();
if ($hAttack>$mDefend) {
print "Hero hit monster for $hDamage damage.<br>";
} else if ($hAttack<=$mDefend) {
print "Hero missed monster.";
}
} // end combatSim
?>