use unique key for mancala game
This commit is contained in:
parent
de33ee5f92
commit
f92248c6d3
13
src/index.ts
13
src/index.ts
@ -62,9 +62,7 @@ rtmt.listenMessage(channel_new_game, (userKey: string, message: Object) => {
|
|||||||
const gameStore = new Map<string, MancalaGame>();
|
const gameStore = new Map<string, MancalaGame>();
|
||||||
|
|
||||||
matchmaker.onPlayersPaired = (userKey1: string, userKey2: string) => {
|
matchmaker.onPlayersPaired = (userKey1: string, userKey2: string) => {
|
||||||
const game = new CommonMancalaGame(userKey1, userKey2);
|
const game = createMancalaGame(userKey1, userKey2);
|
||||||
gameStore.set(userKey1, game);
|
|
||||||
gameStore.set(userKey2, game);
|
|
||||||
|
|
||||||
rtmt.sendMessage(userKey1, channel_on_game_start, game);
|
rtmt.sendMessage(userKey1, channel_on_game_start, game);
|
||||||
rtmt.sendMessage(userKey2, channel_on_game_start, game);
|
rtmt.sendMessage(userKey2, channel_on_game_start, game);
|
||||||
@ -85,7 +83,7 @@ rtmt.listenMessage(channel_game_move, (userKey: string, message: Object) => {
|
|||||||
gameStore.delete(game.player2Id);
|
gameStore.delete(game.player2Id);
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
rtmt.sendMessage(game.player1Id, channel_on_game_crashed, err);
|
rtmt.sendMessage(game.player1Id, channel_on_game_crashed, err);
|
||||||
rtmt.sendMessage(game.player2Id, channel_on_game_crashed, err);
|
rtmt.sendMessage(game.player2Id, channel_on_game_crashed, err);
|
||||||
}
|
}
|
||||||
@ -109,3 +107,10 @@ const deleteGame = (game: MancalaGame) => {
|
|||||||
gameStore.delete(game.player2Id);
|
gameStore.delete(game.player2Id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createMancalaGame(userKey1: string, userKey2: string) {
|
||||||
|
const game = new CommonMancalaGame(generateKey(), userKey1, userKey2);
|
||||||
|
gameStore.set(userKey1, game);
|
||||||
|
gameStore.set(userKey2, game);
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user