Skip to content

Commit

Permalink
feat: #34
Browse files Browse the repository at this point in the history
  • Loading branch information
yazan-abu-obaideh committed Nov 24, 2024
1 parent 05bcbfa commit 4e900f1
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 391 deletions.
2 changes: 1 addition & 1 deletion backend/src/pathological/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ def new_connection():
def remove_from_game():
# noinspection PyUnresolvedReferences
connection_id = get_session_id()
print(f"Connection terminated {connection_id}")
player_data = connection_repository.remove_connection(connection_id)
# TODO: fix this. Should use the session ID to remove the player -
# because what happens now is, if someone tries to join a game
# with an existing name, the existing player is kicked out (LMAO)
multiplayer_game_service.leave_game(game_id=player_data["game_id"],
player_id=player_data["player_id"])
print(f"Connection terminated {connection_id}")


@app.route("/actuator/health")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ def leave_game(self, game_id: str, player_id: str):

def trigger_game_starting(self, game_id: str):
self._verify_exists(game_id)

game = self._game_repository.get_game(game_id)

if game.running:
raise UserInputException("Game already running!")

game.running = True
self._game_repository.update_game(game)

Expand Down Expand Up @@ -169,14 +172,7 @@ def _end_game(self, game_id: str):
self._game_repository.update_game(game)

self._publish_ended_event(game, game_id)

def delete_game():
self._game_repository.delete_game(game_id)

self._task_scheduler.run_after(
seconds_delay=self._get_delete_game_delay(),
f=delete_game
)
self._game_repository.delete_game(game_id)

def _publish_ended_event(self,
game: MultiplayerGame,
Expand Down
4 changes: 4 additions & 0 deletions backend/test/test_multiplayer_game_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def test_trigger_start_game(self):

self.task_scheduler.run_latest() # run delayed end game task!

@unittest.skip
def test_trigger_start_game_when_game_already_started(self):
pass

def test_full_game(self):
self.game_service.create_game("game_full", "player_1")
self.game_service.join_game("game_full", "player_2")
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function countDown() {
Number.parseInt(timerElement.textContent) || 15;
if (remainingSeconds - 1 <= 0) {
timerElement.textContent = "ZERO ";
document.getElementById("game-timer-div").setAttribute("style", "display: none");
document
.getElementById("current-challenge-div")
.setAttribute("style", "display: none");
Expand All @@ -100,7 +101,7 @@ async function showScore() {
const playerScoreResponse = await gameController.getScore(playerId);
console.log("Fetched response: " + JSON.stringify(playerScoreResponse));
const score = playerScoreResponse["player_score"] as number;
scoreDiv.appendChild(textDiv(`Player score: ${score}`));
scoreDiv.appendChild(textDiv(`Your score: ${score}`));
}

function sleep(ms: number): Promise<void> {
Expand Down
Loading

0 comments on commit 4e900f1

Please sign in to comment.