Skip to content

Commit

Permalink
server:Add game event handler for JOIN_GAME event
Browse files Browse the repository at this point in the history
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:shivansh-bhatnagar18#93
  • Loading branch information
ritwik-69 authored and kuv2707 committed Jun 13, 2024
1 parent ac6c815 commit 2db3e3d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/uno-game-engine/events/joinGame.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 2db3e3d

Please sign in to comment.