added preference for places not seen by user in the selection of places for the game
This commit is contained in:
1 parent
66c871fbc2
commit
01f3c7c8cf
2 files changed
+151
-3
No files matched your search
@@ -7,8 +7,10 @@ use MapGuesser\Response\JsonContent;
|
||||
use MapGuesser\Interfaces\Response\IContent;
|
||||
use MapGuesser\Multi\MultiConnector;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
use MapGuesser\PersistentData\Model\UserPlayedPlace;
|
||||
use MapGuesser\Repository\MultiRoomRepository;
|
||||
use MapGuesser\Repository\PlaceRepository;
|
||||
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
||||
|
||||
class GameFlowController
|
||||
{
|
||||
@@ -25,6 +27,8 @@ class GameFlowController
|
||||
|
||||
private PlaceRepository $placeRepository;
|
||||
|
||||
private UserPlayedPlaceRepository $userPlayedPlaceRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
@@ -32,6 +36,7 @@ class GameFlowController
|
||||
$this->multiConnector = new MultiConnector();
|
||||
$this->multiRoomRepository = new MultiRoomRepository();
|
||||
$this->placeRepository = new PlaceRepository();
|
||||
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
||||
}
|
||||
|
||||
public function initialData(): IContent
|
||||
@@ -43,8 +48,10 @@ class GameFlowController
|
||||
return new JsonContent(['error' => 'no_session_found']);
|
||||
}
|
||||
|
||||
$userId = $session->get('userId');
|
||||
|
||||
if (!isset($state['currentRound']) || $state['currentRound'] == -1 || $state['currentRound'] >= static::NUMBER_OF_ROUNDS) {
|
||||
$this->startNewGame($state, $mapId);
|
||||
$this->startNewGame($state, $mapId, $userId);
|
||||
$session->set('state', $state);
|
||||
}
|
||||
|
||||
@@ -145,6 +152,22 @@ class GameFlowController
|
||||
|
||||
$session->set('state', $state);
|
||||
|
||||
// save the selected place for the round in UserPlayedPlace
|
||||
$userId = $session->get('userId');
|
||||
if(isset($userId)) {
|
||||
$placeId = $last['placeId'];
|
||||
$userPlayedPlace = $this->userPlayedPlaceRepository->getByUserIdAndPlaceId($userId, $placeId);
|
||||
if(!$userPlayedPlace) {
|
||||
$userPlayedPlace = new UserPlayedPlace();
|
||||
$userPlayedPlace->setUserId($userId);
|
||||
$userPlayedPlace->setPlaceId($placeId);
|
||||
} else {
|
||||
$userPlayedPlace->incrementOccurrences();
|
||||
}
|
||||
$userPlayedPlace->setLastTimeDate(new DateTime());
|
||||
$this->pdm->saveToDb($userPlayedPlace);
|
||||
}
|
||||
|
||||
return new JsonContent($response);
|
||||
}
|
||||
|
||||
@@ -222,9 +245,9 @@ class GameFlowController
|
||||
return ['distance' => $distance, 'score' => $score];
|
||||
}
|
||||
|
||||
private function startNewGame(array &$state, int $mapId): void
|
||||
private function startNewGame(array &$state, int $mapId, $userId = null): void
|
||||
{
|
||||
$places = $this->placeRepository->getRandomNForMapWithValidPano($mapId, static::NUMBER_OF_ROUNDS);
|
||||
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
||||
|
||||
$state['rounds'] = [];
|
||||
$state['currentRound'] = 0;
|
||||
|
||||
Reference in new issue
Block a user