public function execute(Troll $troll) { if ($troll->isRunawayState()) { $troll->runaway(); } else { // todo } }
$this->getWeapon()->useWeapon(); } } class Knight extends Character { public function fight() { print "Knight Fighting!!" . PHP_EOL; $this->getWeapon()->useWeapon(); } } class Troll extends Character { public function fight() { print "Troll Fighting!!" . PHP_EOL; $this->getWeapon()->useWeapon(); } } //Create a troll $troll = new Troll(); //Fight using a knife $troll->setWeapon(new KnifeBehavior())->fight(); //Fight using a Axe $troll->setWeapon(new AxeBehavior())->fight(); //Create a king $king = new King(); //Fight using a sword $king->setWeapon(new SwordBehavior())->fight(); //Fight using a bow and arrow $king->setWeapon(new BowAndArrowBehavior())->fight();
public function execute(Troll $troll) { if ($troll->isThirdState()) { $troll->third(); } }