game: fix: update score on goal

This commit is contained in:
starnakin 2024-04-15 06:02:51 +02:00
parent eeea06609b
commit 5423240df4
2 changed files with 17 additions and 2 deletions

View File

@ -160,11 +160,26 @@ export class PongGame extends AGame
else if (data.detail === "update_ball")
this._updateBall(data);
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")
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)
{
let player = this.players.find((player) => player.id === data.user_id);

View File

@ -38,7 +38,7 @@ class PongPlayer(APlayer):
def receive(self, data: dict):
detail: str = data.get("detail")
if (detail is None):
return