Add player count attribute
This commit is contained in:
parent
7b8ade6f4c
commit
8dfea57a7c
1 changed files with 8 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
export class Game {
|
export class Game {
|
||||||
readonly code: string;
|
readonly code: string;
|
||||||
public status: game_states;
|
public status: game_states;
|
||||||
|
private player_len: number = 0;
|
||||||
private banned_players: string[];
|
private banned_players: string[];
|
||||||
private _players: players;
|
private _players: players;
|
||||||
|
|
||||||
|
|
@ -22,7 +23,11 @@ export class Game {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return null;
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
get player_count(): number {
|
||||||
|
return this.player_len;
|
||||||
|
};
|
||||||
|
|
||||||
public add_player(player: string, id: string, is_host:boolean=false): void {
|
public add_player(player: string, id: string, is_host:boolean=false): void {
|
||||||
this._players[player] = {
|
this._players[player] = {
|
||||||
|
|
@ -31,6 +36,7 @@ export class Game {
|
||||||
host: is_host,
|
host: is_host,
|
||||||
socket: id,
|
socket: id,
|
||||||
};
|
};
|
||||||
|
this.player_len++;
|
||||||
};
|
};
|
||||||
|
|
||||||
public remove_player(player: string, ban: boolean): void {
|
public remove_player(player: string, ban: boolean): void {
|
||||||
|
|
@ -38,6 +44,7 @@ export class Game {
|
||||||
if (ban) {
|
if (ban) {
|
||||||
this.banned_players.push(player);
|
this.banned_players.push(player);
|
||||||
};
|
};
|
||||||
|
this.player_len--;
|
||||||
};
|
};
|
||||||
|
|
||||||
public toString(): string {
|
public toString(): string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue