/**
  * @ApiDoc(
  *  description="Create a new game",
  *  requirements={
  *      {"name"="roomId", "dataType"="integer", "requirement"="\d+", "description"="room id"}
  *  }
  * )
  */
 public function postGameAction($roomId)
 {
     $game = new Game($this->getRoom($roomId));
     $game->castRoles();
     $this->persist($game);
     $this->refresh($game);
     return $this->view($game, Codes::HTTP_CREATED)->setRoute('get_game')->setRouteParameters(['gameId' => $game->getId()])->setSerializationContext(SerializationContext::create()->setGroups(['Default']));
 }
Esempio n. 2
0
 /**
  * @JMS\VirtualProperty
  * @JMS\SerializedName("reward")
  * @JMS\Groups({"finished"})
  *
  * @return int | null
  */
 public function computeReward()
 {
     if (!$this->game->hasFinished()) {
         return null;
     }
     if (!$this->isWon()) {
         return 0;
     }
     /** @var RoleConfig $roleConfig */
     $roleConfig = $this->game->getRoom()->getRoleConfigs()->filter(function (RoleConfig $roleConfig) {
         return $roleConfig->getRole()->getId() == $this->getActualRole()->getId();
     })->first();
     return $this->isAlive() ? $roleConfig->getRewardForSurvivor() : $roleConfig->getRewardForDead();
 }