|
@ -109,17 +109,18 @@ export class Game { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async stop (): Promise<void> { |
|
|
stop (): void { |
|
|
if (this.timer !== null) { |
|
|
if (this.timer !== null && this.playing) { |
|
|
await this.pongService.saveResult(this.players, this.ranked) |
|
|
this.playing = false |
|
|
if (this.players.length !== 0) { |
|
|
|
|
|
this.gameStoppedCallback(this.players[0].name) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clearInterval(this.timer) |
|
|
clearInterval(this.timer) |
|
|
this.timer = null |
|
|
this.timer = null |
|
|
|
|
|
this.pongService.saveResult(this.players, this.ranked).then(() => { |
|
|
|
|
|
this.gameStoppedCallback(this.players[0].name) |
|
|
this.players = [] |
|
|
this.players = [] |
|
|
this.playing = false |
|
|
}).catch(() => { |
|
|
|
|
|
this.gameStoppedCallback(this.players[0].name) |
|
|
|
|
|
this.players = [] |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -161,7 +162,7 @@ export class Game { |
|
|
this.players[indexPlayerScored].score += 1 |
|
|
this.players[indexPlayerScored].score += 1 |
|
|
if (this.players[indexPlayerScored].score >= DEFAULT_WIN_SCORE) { |
|
|
if (this.players[indexPlayerScored].score >= DEFAULT_WIN_SCORE) { |
|
|
console.log(`${this.players[indexPlayerScored].name} won`) |
|
|
console.log(`${this.players[indexPlayerScored].name} won`) |
|
|
void this.stop() |
|
|
this.stop() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|