feature/MAPG-235-basic-challenge-mode #48
@ -325,6 +325,8 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
||||
});
|
||||
|
||||
Game.showSummary();
|
||||
|
||||
document.getElementById('continueButton').style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ use MapGuesser\Repository\PlaceInChallengeRepository;
|
||||
use MapGuesser\Repository\PlaceRepository;
|
||||
use MapGuesser\Repository\UserInChallengeRepository;
|
||||
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
||||
use MapGuesser\Repository\UserRepository;
|
||||
|
||||
class GameFlowController
|
||||
{
|
||||
@ -36,6 +37,8 @@ class GameFlowController
|
||||
|
||||
private MapRepository $mapRepository;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
private UserPlayedPlaceRepository $userPlayedPlaceRepository;
|
||||
|
||||
private ChallengeRepository $challengeRepository;
|
||||
@ -54,6 +57,7 @@ class GameFlowController
|
||||
$this->multiRoomRepository = new MultiRoomRepository();
|
||||
$this->placeRepository = new PlaceRepository();
|
||||
$this->mapRepository = new MapRepository();
|
||||
$this->userRepository = new UserRepository();
|
||||
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
||||
$this->challengeRepository = new ChallengeRepository();
|
||||
$this->userInChallengeRepository = new UserInChallengeRepository();
|
||||
@ -156,7 +160,7 @@ class GameFlowController
|
||||
|
||||
$response['history'] = [];
|
||||
|
||||
$guesses = iterator_to_array($this->guessRepository->getAllInChallenge($userId, $challenge));
|
||||
$guesses = iterator_to_array($this->guessRepository->getAllInChallengeByUser($userId, $challenge));
|
||||
$places = iterator_to_array($this->placeRepository->getAllInChallenge($challenge));
|
||||
|
||||
for($i = 0; $i < $currentRound; ++$i)
|
||||
@ -298,6 +302,18 @@ class GameFlowController
|
||||
$map = $this->mapRepository->getByPlace($currentPlace);
|
||||
$placeInChallenge = $this->placeInChallengeRepository->getByPlaceAndChallenge($currentPlace, $challenge);
|
||||
|
||||
// fill in all other results for the round
|
||||
$response['allResults'] = [];
|
||||
foreach($this->guessRepository->getAllInChallengeByRound($currentRound, $challenge) as $guess) {
|
||||
$user = $this->userRepository->getByGuess($guess);
|
||||
$response['allResults'][] = [
|
||||
'userName' => $user->getDisplayName(),
|
||||
'guessPosition' => $guess->getPosition()->toArray(),
|
||||
'distance' => $guess->getDistance(),
|
||||
'score' => $guess->getScore()
|
||||
];
|
||||
}
|
||||
|
||||
$guessPosition = new Position((float) $this->request->post('lat'), (float) $this->request->post('lng'));
|
||||
$result = $this->evaluateGuess($currentPlace->getPosition(), $guessPosition, $map->getArea());
|
||||
|
||||
@ -310,10 +326,12 @@ class GameFlowController
|
||||
$guess->setScore($result['score']);
|
||||
$this->pdm->saveToDb($guess);
|
||||
|
||||
$response = [
|
||||
'position' => $currentPlace->getPosition()->toArray(),
|
||||
'result' => $result
|
||||
];
|
||||
// $response = [
|
||||
// 'position' => $currentPlace->getPosition()->toArray(),
|
||||
// 'result' => $result
|
||||
// ];
|
||||
$response['position'] = $currentPlace->getPosition()->toArray();
|
||||
$response['result'] = $result;
|
||||
|
||||
// update round
|
||||
$nextRound = $currentRound + 1;
|
||||
@ -331,6 +349,9 @@ class GameFlowController
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$this->saveVisit($currentPlace->getId());
|
||||
|
||||
return new JsonContent($response);
|
||||
|
@ -323,10 +323,6 @@ class Select
|
||||
$value = $this->generateColumn($value);
|
||||
});
|
||||
|
||||
if(count($columns) > 0 && $columns[0] == Utils::backtick('id')) {
|
||||
$columns[0] = Utils::backtick($this->table) . '.' . Utils::backtick('id');
|
||||
}
|
||||
|
||||
return implode(',', $columns);
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,10 @@ class PersistentDataManager
|
||||
$table = call_user_func([$type, 'getTable']);
|
||||
$fields = call_user_func([$type, 'getFields']);
|
||||
|
||||
array_walk($fields, function (&$value, $key, $table) {
|
||||
$value = [$table, $value];
|
||||
}, $table);
|
||||
|
||||
$select->from($table);
|
||||
|
||||
//TODO: only with some relations?
|
||||
|
@ -39,7 +39,7 @@ class GuessRepository
|
||||
return $this->pdm->selectFromDb($select, Guess::class);
|
||||
}
|
||||
|
||||
public function getAllInChallenge(int $userId, Challenge $challenge): Generator
|
||||
public function getAllInChallengeByUser(int $userId, Challenge $challenge): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']);
|
||||
@ -49,4 +49,25 @@ class GuessRepository
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
||||
}
|
||||
|
||||
public function getAllInChallenge(Challenge $challenge): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
|
||||
$select->where('challenge_id', '=', $challenge->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
||||
}
|
||||
|
||||
public function getAllInChallengeByRound(int $round, Challenge $challenge): Generator
|
||||
{
|
||||
$order = $round + 1;
|
||||
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
|
||||
$select->where('challenge_id', '=', $challenge->getId());
|
||||
$select->where('order', '=', $order);
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,7 @@ class MapRepository
|
||||
|
||||
public function getByPlace(Place $place): ?Map
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('id', '=', $place->getMapId());
|
||||
|
||||
return $this->pdm->selectFromDb($select, Map::class);
|
||||
return $this->getById($place->getMapId());
|
||||
}
|
||||
|
||||
public function getByChallenge(Challenge $challenge): ?Map
|
||||
|
@ -3,6 +3,7 @@
|
||||
use DateTime;
|
||||
use Generator;
|
||||
use MapGuesser\Database\Query\Select;
|
||||
use MapGuesser\PersistentData\Model\Guess;
|
||||
use MapGuesser\PersistentData\Model\User;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
|
||||
@ -44,4 +45,9 @@ class UserRepository
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, User::class);
|
||||
}
|
||||
|
||||
public function getByGuess(Guess $guess): ?User
|
||||
{
|
||||
return $this->getById($guess->getUserId());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user