diff --git a/back/volume/src/pong/game/Game.ts b/back/volume/src/pong/game/Game.ts index 5481711..74304db 100644 --- a/back/volume/src/pong/game/Game.ts +++ b/back/volume/src/pong/game/Game.ts @@ -109,17 +109,18 @@ export class Game { } } - async stop (): Promise { - if (this.timer !== null) { - await this.pongService.saveResult(this.players, this.ranked) - if (this.players.length !== 0) { - this.gameStoppedCallback(this.players[0].name) - } - + stop (): void { + if (this.timer !== null && this.playing) { + this.playing = false clearInterval(this.timer) this.timer = null - this.players = [] - this.playing = false + this.pongService.saveResult(this.players, this.ranked).then(() => { + this.gameStoppedCallback(this.players[0].name) + this.players = [] + }).catch(() => { + this.gameStoppedCallback(this.players[0].name) + this.players = [] + }) } } @@ -161,7 +162,7 @@ export class Game { this.players[indexPlayerScored].score += 1 if (this.players[indexPlayerScored].score >= DEFAULT_WIN_SCORE) { console.log(`${this.players[indexPlayerScored].name} won`) - void this.stop() + this.stop() } } diff --git a/back/volume/src/pong/game/Games.ts b/back/volume/src/pong/game/Games.ts index df1da4a..2a794e1 100644 --- a/back/volume/src/pong/game/Games.ts +++ b/back/volume/src/pong/game/Games.ts @@ -109,7 +109,7 @@ export class Games { async leaveGame (name: string): Promise { const game: Game | undefined = this.playerGame(name) if (game !== undefined && !game.ranked) { - await game.stop() + game.stop() this.deleteGame(name) } } diff --git a/back/volume/src/pong/pong.gateway.ts b/back/volume/src/pong/pong.gateway.ts index db658a6..99c3e1d 100644 --- a/back/volume/src/pong/pong.gateway.ts +++ b/back/volume/src/pong/pong.gateway.ts @@ -47,7 +47,7 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect { const name: string | undefined = this.socketToPlayerName.get(client) const game: Game | undefined = this.games.playerGame(name) if (game?.isPlaying() !== undefined) { - void game.stop() + game.stop() } if (name !== undefined) { console.log('Disconnected ', this.socketToPlayerName.get(client))