|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
# Generic use statements |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use App\Observer\SessionSavingObserver; |
|
11
|
|
|
use App\Model\Game; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
13
|
|
|
|
|
14
|
|
|
class GameController extends AbstractController |
|
15
|
|
|
{ |
|
16
|
|
|
#[Route('/game', name: 'app_game')] |
|
17
|
|
|
public function index(): Response |
|
18
|
|
|
{ |
|
19
|
|
|
return $this->render('game/index.html.twig'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
#[Route('/game/doc', name: 'app_game_doc')] |
|
23
|
|
|
public function doc(): Response |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->render('game/doc.html.twig'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
#[Route('/game/play/post', name: 'app_post_game')] |
|
29
|
|
|
public function processMove(Request $request): RedirectResponse |
|
30
|
|
|
{ |
|
31
|
|
|
$session = $request->getSession(); |
|
32
|
|
|
$gameState = $session->get('game'); |
|
33
|
|
|
$game = Game::createFromSavedState((array) $gameState); |
|
34
|
|
|
|
|
35
|
|
|
$game->attach(new SessionSavingObserver($request, 'game')); |
|
36
|
|
|
|
|
37
|
|
|
try { |
|
38
|
|
|
$game->playRound($request->request->all()); |
|
39
|
|
|
} catch (\Exception $e) { |
|
40
|
|
|
$this->addFlash('error', $e->getMessage()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $this->redirectToRoute('app_play_game'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
#[Route('/game/play', name: 'app_play_game', methods: ['GET'], defaults: ['game_needed' => true ])] |
|
47
|
|
|
public function play(Request $request): Response |
|
48
|
|
|
{ |
|
49
|
|
|
$session = $request->getSession(); |
|
50
|
|
|
$gameState = $session->get('game'); |
|
51
|
|
|
$game = Game::createFromSavedState((array) $gameState); |
|
52
|
|
|
|
|
53
|
|
|
return $this->render('game/game.html.twig', [ |
|
54
|
|
|
'game' => $game |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
#[Route('/api/game', name: 'api_game')] |
|
59
|
|
|
public function game(Request $request): JsonResponse |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
|
|
62
|
|
|
$data = []; |
|
63
|
|
|
if ($request->getSession()->has('game')) { |
|
64
|
|
|
$game = Game::createFromSavedState((array) $request->getSession()->get('game')); |
|
65
|
|
|
$gameState = $game->getGameState(); |
|
66
|
|
|
$data = [ |
|
67
|
|
|
'players' => $gameState['players'], |
|
68
|
|
|
'currentPlayer' => $gameState['currentPlayer'], |
|
69
|
|
|
'pot' => $gameState['pot'], |
|
70
|
|
|
'gameStatus' => $gameState['gameStatus'], |
|
71
|
|
|
'bank_balance' => $game->getPlayers()['bank']->getBalance(), |
|
72
|
|
|
'player_balance' => $game->getPlayers()['human']->getBalance() |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
return new JsonResponse($data); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths