game: fix: update score on goal
This commit is contained in:
@ -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);
|
||||||
|
@ -38,7 +38,7 @@ class PongPlayer(APlayer):
|
|||||||
def receive(self, data: dict):
|
def receive(self, data: dict):
|
||||||
|
|
||||||
detail: str = data.get("detail")
|
detail: str = data.get("detail")
|
||||||
|
|
||||||
if (detail is None):
|
if (detail is None):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user