-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server:Implement the START_GAME event handler in the engine
This commit adds the START_GAME event handler in the engine.The event handler can be found in event folder.This event handler starts the game and distributes the cards among players fixes #148
- Loading branch information
Showing
4 changed files
with
54 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import assert from 'assert'; | ||
import { GameEngine } from '../engine'; | ||
import { EventResult, GameEvent } from '../../types'; | ||
|
||
export function startGame(game: GameEngine, event: GameEvent): EventResult { | ||
assert(event.type === 'START_GAME', 'Invalid event type'); | ||
if (event.playerId === game.players[0].id) { | ||
game.status = 'STARTED'; | ||
game.allotCards(); | ||
return { type: 'SUCCESS', message: 'Game started successfully' }; | ||
} else { | ||
return { | ||
type: 'ERROR', | ||
message: 'Only the Host can start the game', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.