-
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.
- Converted .d.ts to .ts in the backend. - Importing types wherever necessary. - implemented endpoints for join and create game. - Implement api calls in the frontend form join and create game - Attached id attribute to GameEngine. - converted userRoutes to typescript - setup nodemon
- Loading branch information
Showing
24 changed files
with
213 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"watch": ["src/**/*.ts", "src/**/*.js"], | ||
"ext": "js,ts", | ||
"ignore": ["**/*.test.ts", "**/*.spec.ts", "node_modules"], | ||
"exec": "ts-node ./src/index.ts" | ||
} |
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
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
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
File renamed without changes.
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
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
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,27 @@ | ||
// some utility functions shared by event handlers | ||
|
||
import { Player, EventResult } from '../../types'; | ||
import { GameEngine } from '../engine'; | ||
|
||
export function getPlayer(game: GameEngine, playerId: string) { | ||
return game.players.find((p) => p.id === playerId); | ||
} | ||
|
||
export function getPlayerCard(player: Player, cardId: string) { | ||
return player.cards.find((c) => c.id === cardId); | ||
} | ||
|
||
export function checkCurrentPlayer( | ||
game: GameEngine, | ||
player: Player | ||
): EventResult { | ||
const { currentPlayerIndex, players } = game; | ||
const currentPlayer = players[currentPlayerIndex]; | ||
|
||
// check if the player is the current player | ||
if (currentPlayer.id !== player.id) { | ||
return { type: 'ERROR', message: 'It is not your turn' }; | ||
} | ||
|
||
return { type: 'SUCCESS', message: 'Can draw/throw card' }; | ||
} |
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import { assert } from 'console'; | ||
import { GameEngine } from '../engine'; | ||
import { registerEventHandler } from '../gameEvents'; | ||
import { EventResult, GameEvent, Player } from '../../types'; | ||
|
||
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); |
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
Oops, something went wrong.