game: add: defeated by forfeit

This commit is contained in:
2024-02-25 17:52:48 +01:00
committed by AdrienLSH
parent d814363b36
commit d0e87066b0
3 changed files with 49 additions and 22 deletions

View File

@ -1,4 +1,4 @@
import { client } from "../index.js";
import { client, reloadView } from "../index.js";
import { Game } from "../api/game/Game.js";
import AbstractView from "./abstracts/AbstractView.js";
import { MyPlayer } from "../api/game/MyPlayer.js";
@ -9,11 +9,17 @@ export default class extends AbstractView
constructor(params)
{
super(params, "Game");
this.game = new Game(client, params.id, this.update_goal);
this.game = new Game(client, params.id, this.on_goal, this.on_finish);
this.keys_pressed = [];
this.my_player = undefined;
}
on_finish(data)
{
console.log(data)
reloadView()
}
keyReleaseHandler(event)
{
const idx = this.keys_pressed.indexOf(event.key);
@ -51,7 +57,7 @@ export default class extends AbstractView
/**
* @param {Object} data
*/
update_goal(data)
on_goal(data)
{
document.getElementById(`goal-${data.player}`).innerText = data.nb_goal;
}