From 2db3e3da852261cc44bffc818600aaaf506df6e3 Mon Sep 17 00:00:00 2001 From: ritwik-69 <72665321+ritwik-69@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:08:44 +0530 Subject: [PATCH] server:Add game event handler for JOIN_GAME event This commit creates the event handler for JOIN_GAME event to let new players join the server before the game is started by the host. Fixes:#93 --- backend/src/uno-game-engine/events/joinGame.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 backend/src/uno-game-engine/events/joinGame.ts diff --git a/backend/src/uno-game-engine/events/joinGame.ts b/backend/src/uno-game-engine/events/joinGame.ts new file mode 100644 index 0000000..1697a57 --- /dev/null +++ b/backend/src/uno-game-engine/events/joinGame.ts @@ -0,0 +1,12 @@ +import { assert } from 'console'; +import { GameEngine } from '../engine'; +import { registerEventHandler } from '../gameEvents'; + +export function joinGame(game: GameEngine, event: GameEvent): EventResult { + assert(event.type === 'JOIN_GAME', 'Invalid event type'); + const player: Player = { id: event.playerId, cards: [] }; + game.addPlayer(player); + return { type: 'SUCCESS', message: 'player joined successfully' }; +} + +registerEventHandler('JOIN_GAME', joinGame);