game: fix: update score on goal
This commit is contained in:
parent
eeea06609b
commit
5423240df4
@ -160,11 +160,26 @@ export class PongGame extends AGame
|
|||||||
else if (data.detail === "update_ball")
|
else if (data.detail === "update_ball")
|
||||||
this._updateBall(data);
|
this._updateBall(data);
|
||||||
else if (data.detail === "goal")
|
else if (data.detail === "goal")
|
||||||
await this._goalHandler(data); // TODO fix: extract goal data in separate function
|
await this._receiveGoal(data);
|
||||||
else if (data.detail === "finish")
|
else if (data.detail === "finish")
|
||||||
await this._finishHandler(data);
|
await this._finishHandler(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _receiveGoal(data)
|
||||||
|
{
|
||||||
|
const player = this.players.find((player) => player.id === data.player_id);
|
||||||
|
|
||||||
|
if (player === undefined)
|
||||||
|
{
|
||||||
|
console.error("error: unknown player.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
player.score.push(data.timestamp)
|
||||||
|
|
||||||
|
await this._goalHandler(player);
|
||||||
|
}
|
||||||
|
|
||||||
_updatePlayer(data)
|
_updatePlayer(data)
|
||||||
{
|
{
|
||||||
let player = this.players.find((player) => player.id === data.user_id);
|
let player = this.players.find((player) => player.id === data.user_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user