Example #1
0
 public static function set(TeamRepositoryInterface $team, array $players)
 {
     $order = 0;
     $team->resetPlayersPosition();
     //GoalKeeper
     $goalKeeper = array_pop($players);
     $team->addPlayerAtPosition(PlayerPositions::GoalKeeper, $goalKeeper["id"], ++$order);
     //Defenders
     for ($i = 0; $i < $team->getFormation()->defense; $i++) {
         $player = array_pop($players);
         $team->addPlayerAtPosition(PlayerPositions::Defense, $player["id"], ++$order);
     }
     //Midfielders
     for ($i = 0; $i < $team->getFormation()->midfield; $i++) {
         $player = array_pop($players);
         $team->addPlayerAtPosition(PlayerPositions::Midfield, $player["id"], ++$order);
     }
     //Attackers
     for ($i = 0; $i < $team->getFormation()->attack; $i++) {
         $player = array_pop($players);
         $team->addPlayerAtPosition(PlayerPositions::Attack, $player["id"], ++$order);
     }
     if ($team->getNumberOfEligiblePlayersForMatch() != 11) {
         $formation = new Formation($team->getFormation(), $team);
         $formation->spreadPlayersOnPositions();
         throw new \Exception("The team should have 11 players in order to be able to play a match");
     }
 }
 public function pickAttacker(TeamRepositoryInterface $team)
 {
     if ($team->pickPlayerPosition(PlayerPositions::Attack, $this)) {
         $this->_attack += 1;
     }
 }