/**
  * @param int $teamIndex
  *
  * @return Player
  */
 protected function createEntity($teamIndex)
 {
     $player = new Player();
     $player->setSkillDefense(rand(1, 100));
     $player->setSkillOffense(rand(1, 100));
     return $player;
 }
 /**
  * @param UserEvent $event
  */
 public function onRegister(UserEvent $event)
 {
     /** @var User $user */
     $user = $event->getUser();
     $player = new Player();
     $player->setName($user->getUsername());
     $player->setSkillDefense(rand(1, 100));
     $player->setSkillOffense(rand(1, 100));
     /** @var Team[] $teams */
     $teams = $this->entityManager->getRepository('CoreBundle:Team')->findAll();
     $player->setTeam($teams[rand(0, count($teams) - 1)]);
     $this->entityManager->persist($player);
     $user->setPlayer($player);
     $this->entityManager->flush();
 }
 public function testCompareAverageSkill()
 {
     $this->setUpPlayer(50, 50);
     $comparePlayer = new Player();
     $comparePlayer->setSkillDefense(60);
     $comparePlayer->setSkillOffense(60);
     $this->assertTrue(Player::compareAverageSkill($this->player, $comparePlayer));
     $comparePlayer = new Player();
     $comparePlayer->setSkillDefense(50);
     $comparePlayer->setSkillOffense(50);
     $this->assertFalse(Player::compareAverageSkill($this->player, $comparePlayer));
     $comparePlayer = new Player();
     $comparePlayer->setSkillDefense(40);
     $comparePlayer->setSkillOffense(40);
     $this->assertFalse(Player::compareAverageSkill($this->player, $comparePlayer));
 }
Exemple #4
0
 public function testLineup()
 {
     $player1 = new Player();
     $player1->setId(1);
     $player1->setSkillDefense(40);
     $player1->setSkillOffense(40);
     $this->team->addPlayer($player1);
     for ($i = 2; $i <= 12; $i++) {
         $player = new Player();
         $player->setId($i);
         $player->setSkillDefense(50);
         $player->setSkillOffense(50);
         $this->team->addPlayer($player);
     }
     $player2 = new Player();
     $player2->setId(13);
     $player2->setSkillDefense(40);
     $player2->setSkillOffense(40);
     $this->team->addPlayer($player2);
     $this->assertCount(11, $this->team->getLineup());
     $this->assertNotContains($player1, $this->team->getLineup());
     $this->assertNotContains($player2, $this->team->getLineup());
 }
 public function testCreateTransferOffer()
 {
     $originTeam = new Team();
     $targetTeam = new Team();
     $this->manager->setTeam($targetTeam);
     $player = new Player();
     $player->setSkillDefense(10);
     $player->setSkillOffense(10);
     $player->setTeam($originTeam);
     $transferOffer = $this->manager->createTransferOffer($player);
     $this->assertEquals($originTeam, $transferOffer->getOriginTeam());
     $this->assertEquals($targetTeam, $transferOffer->getTargetTeam());
     $this->assertEquals($player, $transferOffer->getPlayer());
     $this->assertEquals(100, $transferOffer->getAmount());
 }
 /**
  * @param int $skillDefense
  * @param int $skillOffense
  *
  * @return Player
  */
 private function createPlayer($skillDefense, $skillOffense)
 {
     $player = new Player();
     $player->setSkillDefense($skillDefense);
     $player->setSkillOffense($skillOffense);
     return $player;
 }