public function removeUserFromGame(User $user, Game $game)
 {
     if ($game->isUserInGame($user)) {
         $em = $this->getEntityManager();
         $player = $game->getPlayerByUserId($user->getId());
         // note it is important that we remove the player from the game before deleting them so that game state is updated to reflect this change
         $game->removePlayer($player);
         $em->remove($player);
         $em->flush();
     }
 }
 /**
  * @Route("/secure/game-play/{id}", requirements={"id" = "\d+"}, name="game_play")
  */
 public function playAction(Game $game, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $user = $this->getUser();
     //make sure only game players can see this page
     if (!$game->isUserInGame($user)) {
         return $this->redirectToRoute('game_home');
     }
     $player = $game->getPlayerByUserId($user->getId());
     $player->setViewedGame(true);
     $em->flush();
     $template = 'game/play.html.twig';
     $isPopup = $request->query->get('popup', false);
     if ($isPopup) {
         $template = 'game/play_popup.html.twig';
     }
     return $this->render($template, array('game' => $game));
 }