Esempio n. 1
0
 public function inflictDamage(FireManager $fires)
 {
     $physicShots = array();
     //doesn't matter who shot first, but who receive first the damage
     foreach ($fires->getIterator() as $fire) {
         $tmp = array();
         foreach ($this->getOrderedIterator() as $idShipTypeDefender => $shipTypeDefender) {
             $idShipTypeAttacker = $fire->getId();
             log_comment("---- firing from {$idShipTypeAttacker} to {$idShipTypeDefender} ----");
             $xs = $fire->getShotsFiredByAllToDefenderType($shipTypeDefender, true);
             $ps = $shipTypeDefender->inflictDamage($fire->getPower(), $xs->result);
             log_var('$xs', $xs);
             $tmp[$idShipTypeDefender] = $xs->rest;
             if ($ps != null) {
                 $physicShots[$idShipTypeDefender][] = $ps;
             }
         }
         log_var('$tmp', $tmp);
         // assign the last shot to the more likely shitType
         $m = 0;
         $f = 0;
         foreach ($tmp as $k => $v) {
             if ($v > $m) {
                 $m = $v;
                 $f = $k;
             }
         }
         if ($f != 0) {
             log_comment('adding 1 shot');
             $ps = $this->getShipType($f)->inflictDamage($fire->getPower(), 1);
             $physicShots[$f][] = $ps;
         }
     }
     return $physicShots;
 }
Esempio n. 2
0
 public function inflictDamage(FireManager $fires)
 {
     $physicShots = array();
     //doesn't matter who shot first, but who receive first the damage
     foreach ($fires->getIterator() as $fire) {
         foreach ($this->getOrderedIterator() as $idShipTypeDefender => $shipTypeDefender) {
             $idShipTypeAttacker = $fire->getId();
             echo "---- firing from {$idShipTypeAttacker} to {$idShipTypeDefender} ---- <br>";
             $xs = $fire->getShotsFiredByAllToDefenderType($shipTypeDefender, true);
             $ps = $shipTypeDefender->inflictDamage($fire->getPower(), $xs->result);
             if ($ps != null) {
                 $physicShots[$idShipTypeDefender][] = $ps;
             }
         }
     }
     return $physicShots;
 }