function testFightEnemies() { $hero = new Hero('Batman'); $result = $hero->fight(array('Joker', 'Bane')); $this->assertEquals(true, $result); $this->expectOutputString('Batman defeated: Joker, Bane!' . PHP_EOL); }
{ //Attacks every living thing in an array if ($this->isAlive()) { foreach ($monsters as $monster) { while ($monster->isAlive() && $this->isAlive()) { $this->attack($monster); } } } } } $rat = new LivingThing("Rat", 5); $goblin = new LivingThing("Goblin", 30); $ogre = new LivingThing("Ogre", 80); $hero = new Hero("Batman", 100); $monsters = array($rat, $goblin, $ogre); 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>"; } ?> </p> </body> </html>