MAPG-73 pass mapId to GameController and PositionController

adapt JS to send mapId
make separate JS for the game
This commit is contained in:
bence committed 2020-05-30 15:33:28 +02:00
1 parent 1ca023e612
commit 92c35a2087
6 files changed
+38 -51

No files matched your search

+5 -5
View File
@@ -10,13 +10,13 @@ use MapGuesser\Interfaces\View\IView;
class GameController implements IController
{
private int $mapId;
private bool $jsonResponse;
// demo map
private int $mapId = 1;
public function __construct($jsonResponse = false)
public function __construct(int $mapId, $jsonResponse = false)
{
$this->mapId = $mapId;
$this->jsonResponse = $jsonResponse;
}
@@ -32,7 +32,7 @@ class GameController implements IController
];
}
$data = ['bounds' => $bounds->toArray()];
$data = ['mapId' => $this->mapId, 'bounds' => $bounds->toArray()];
if ($this->jsonResponse) {
return new JsonView($data);
+7 -3
View File
@@ -13,8 +13,12 @@ class PositionController implements IController
const NUMBER_OF_ROUNDS = 5;
const MAX_SCORE = 1000;
// demo map
private int $mapId = 1;
private int $mapId;
public function __construct(int $mapId)
{
$this->mapId = $mapId;
}
public function run(): IView
{
@@ -120,7 +124,7 @@ class PositionController implements IController
$select->where('id', 'NOT IN', $exclude);
$select->where('map_id', '=', $this->mapId);
$numberOfPlaces = $select->count();
$numberOfPlaces = $select->count();// TODO: what if 0
$randomOffset = random_int(0, $numberOfPlaces - 1);
$select->orderBy('id');