Esempio n. 1
0
    function bombardStrength()
    {
        $ret = 0;
        foreach ($this->units as $unit) {
            $ret += $unit->bombardStrength();
        }
        return $ret;
    }
}
class UnitException extends Exception
{
}
class Archer extends Unit
{
    function addUnit(Unit $unit)
    {
        throw new UnitException(get_class($this) . " is a leaf");
    }
    function removeUnit(Unit $unit)
    {
        throw new UnitException(get_class($this) . " is a leaf");
    }
    function bombardStrength()
    {
        return 4;
    }
}
$archer = new Archer();
$archer2 = new Archer();
$archer->addUnit($archer2);