public function attack() { return parent::attack(); }
public function receiveAttack($ap) { $this->hp = $this->hp - $ap; } } test('A hero starts with 100HP.', function () { return (new Hero())->hp() === 100; }); test('A monster starts with 100HP.', function () { return (new Monster())->hp() === 100; }); test('Levensvormen vallen elkaar aan', function () { $hero = new Hero(); $monster = new Monster(); $hero->bewapen(new Wapen(10)); $hero->attack($monster); return $monster->hp() === 90; }); class Levensvorm { protected $hp = 100; public function hp() { return $this->hp; } } class Wapen { protected $ap; public function ap() {
{ } $rat = new Monster('Rat', 30); $goblin = new Monster('Goblin', 5); $ogre = new Monster('Ogre', 60); $hero = new Hero('Hero', 100); $monsters = array($rat, $goblin, $ogre); echo "<h3>Protecting our monsters</h3>"; foreach ($monsters as $monster) { // Fix the line below! echo "<p>" . $monster->getName() . ": " . $monster->getHealth() . "</p>"; } echo "<h3>A hero emerges!</h3>"; echo "<p>The noble {$hero->getName()} has vowed to defeat the monsters and save the realm.</p>"; echo "<p>Will they be victorious?</p>"; $hero->fight($monsters); if ($hero->isAlive()) { echo "<p>The hero {$hero->getName()} prevailed!</p>"; } else { echo "<p>{$hero->getName()} was bested by the monsters. We are doomed.</p>"; } $hero->attack($rat); echo "<br>"; echo "Hero health is " . $hero->getHealth(); echo "Monster health is " . $rat->getHealth(); ?> </p> </body> </html>