} public function getHeatRay() { return $this->heatRay; } public function useHeatRay(&$target) { $remaining = $target->getHP() - $this->heatRay; // $superman->setHP(90); $target->setHP($remaining); } } $batman = new human(100, 10, 4); $batman->setUtilityDamage(1.2); $batman->setBatarangsDamage(4); $batman->setCritChance(10); $superman = new kryptonian(200, 10, 3); $superman->setHeatRay(18); $superman->setCritChance(20); do { if ($batman->speed > $superman->speed) { $batman->attack($superman); $superman->attack($batman); $batman->useBelt(); $batman->useBatarangs(); $superman->useHeatRay($batman); } elseif ($batman->speed == $superman->speed) { do { $batman = rand(0, 100); $superman = rand(0, 100); } while ($batman == $superman);
$this->heatRay = $h; } public function getHeatRay() { return $this->heatRay; } public function useHeatRay(&$target) { $remaining = $target->getHP() - $this->heatRay; // $superman->setHP(90); $target->setHP($remaining); } } $achilleas = new human(100, 10); $achilleas->setUtilityDamage(1.2); $achilleas->setCritChance(10); $achilleas->setRagePower(2); $superman = new kryptonian(100, 10); $superman->setHeatRay(18); $superman->setCritChance(20); $br = 0; while ($achilleas->getHP() && $superman->getHP() > 0) { $br++; if ($br % 2 == 0) { if (rand(0, 1) < 1) { $achilleas->useRagePower(); $achilleas->attack($superman); if ($superman->getHP() > 0) { $superman->useHeatRay($achilleas); $superman->attack($achilleas); }
<?php require_once "kryptonian.class.php"; require_once "human.class.php"; $batman = new human(100, 10); $batman->setUtilityDamage(1.2); $batman->setCritChance(20); $superman = new kryptonian(100, 10); $superman->setHeatRay(8); $superman->setCritChance(15); $winner = 'Noone'; $i = 0; echo "<pre>"; do { if ($i % 2 == 1) { $batman->useBelt(); $superman->useHeatRay($batman); echo 'Superattacks executed.' . "<br>"; if ($superman->getHP() <= 0 && $batman->getHP() > 0) { $winner = 'Batman'; } if ($batman->getHP() <= 0 && $superman->getHP() > 0) { $winner = 'Superman'; } if ($batman->getHP() <= 0 && $superman->getHP() <= 0) { break; } } else { $batman->attack($superman); $superman->attack($batman); if ($superman->getHP() <= 0 && $batman->getHP() > 0) {