Skip to content

Commit

Permalink
i can do this anymote (game routes)
Browse files Browse the repository at this point in the history
  • Loading branch information
KotsiosDimis committed Jan 8, 2025
1 parent 27a8729 commit c2445b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 12 additions & 4 deletions blokus.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@
endGame((int)$gameId);
});

$router->add('GET', 'games/{id}/status', 'getGameStatus'); // Get the current status of the game
$router->add('GET', 'games/{id}/deadlock', 'checkDeadlock'); // Check for deadlock in the game
$router->add('GET', 'games/{id}/players/{playerId}/pieces', 'getPlayerPieces'); // Get the available pieces for a player

$router->add('GET', 'games/{id}/status', function($gameId) {
getGameStatus((int)$gameId);
});

$router->add('GET', 'games/{id}/deadlock', function($gameId) {
checkDeadlock((int)$gameId);
});

$router->add('GET', 'games/{id}/players/{playerId}/pieces', function($gameId, $playerId) {
getPlayerPieces((int)$gameId, (int)$playerId);
});



// Handle the request
Expand Down
8 changes: 5 additions & 3 deletions lib/game.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function getGameStatus($gameId) {
$pdo = getDatabaseConnection();

try {
$sql = "CALL GetGameStatus(:gameId);"; // Assuming a stored procedure for fetching game status
$sql = "CALL GetGameStatus(:gameId);";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':gameId', $gameId, PDO::PARAM_INT);
$stmt->execute();
Expand All @@ -111,7 +111,7 @@ function checkDeadlock($gameId) {
$pdo = getDatabaseConnection();

try {
$sql = "CALL CheckDeadlock(:gameId);"; // Assuming a stored procedure for checking deadlock
$sql = "CALL CheckDeadlock(:gameId);";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':gameId', $gameId, PDO::PARAM_INT);
$stmt->execute();
Expand All @@ -124,14 +124,15 @@ function checkDeadlock($gameId) {
}
}


/**
* Get the pieces available for a player.
*/
function getPlayerPieces($gameId, $playerId) {
$pdo = getDatabaseConnection();

try {
$sql = "CALL GetPlayerPieces(:gameId, :playerId);"; // Assuming a stored procedure for fetching player pieces
$sql = "CALL GetPlayerPieces(:gameId, :playerId);";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':gameId', $gameId, PDO::PARAM_INT);
$stmt->bindParam(':playerId', $playerId, PDO::PARAM_INT);
Expand All @@ -144,4 +145,5 @@ function getPlayerPieces($gameId, $playerId) {
echo json_encode(['error' => 'Database error in getPlayerPieces(): ' . $e->getMessage()]);
}
}

?>

0 comments on commit c2445b4

Please sign in to comment.