示例#1
0
 /**
  * @param Combatant $defender
  * @return bool|mixed
  */
 public function attack(Combatant $defender)
 {
     // Stunning blow
     $rand = mt_rand(1, 100);
     if ($rand <= 2) {
         $defender->stun();
     }
     return parent::attack($defender);
 }
示例#2
0
 public function getStrength()
 {
     // Lucky Strike
     $strength = parent::getStrength();
     $rand = mt_rand(1, 100);
     if ($rand <= 5) {
         $strength = $strength * 2;
     }
     return $strength;
 }
示例#3
0
 /**
  * @param Combatant $attacker
  * @return bool
  */
 public function defend(Combatant $attacker)
 {
     $defended = parent::defend($attacker);
     // Counter attack
     if ($defended) {
         $health = $attacker->getHealth();
         $attacker->setHealth($health - 10);
     }
     return $defended;
 }
示例#4
0
 public function describeCombatant(Combatant $combatant)
 {
     $this->displayTemplate(['name' => $combatant->getName(), 'class' => get_class($combatant), 'health' => $combatant->getHealth(), 'strength' => $combatant->getStrength(), 'defence' => $combatant->getDefence(), 'speed' => $combatant->getSpeed(), 'luck' => round($combatant->getLuck(), 2)], self::COMBATANT_DESCRIPTION_TPL);
 }
示例#5
0
 /**
  * @param Combatant $defender
  * @return bool|mixed
  */
 public function attack(Combatant $defender)
 {
     // Damage = Attacker strength – Defender Defense
     $damage = $this->getStrength() - $defender->getDefense();
     if ($defender->defend($this)) {
         return false;
     }
     $health = $defender->getHealth();
     $defender->setHealth($health - $damage);
     return $damage;
 }