Skip to content

Commit

Permalink
Now calling end-function when all players have disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Behringer committed Feb 26, 2024
1 parent cd870dc commit 24b2dbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/src/models/MauMau.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class MauMau {
}

end() {
this.room.state = 'done';
this.endTime = new Date();

const leaderboard: string[] = [ ];
Expand Down
8 changes: 6 additions & 2 deletions backend/src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Room {

id: string;
users: User[];
state: 'initialising'|'inGame';
state: 'initialising'|'inGame'|'done';
selectedGame: 'MauMau';
game: MauMau;
db: Db|undefined;
Expand Down Expand Up @@ -104,7 +104,11 @@ export class Room {
this.users = this.users.filter(u => u != user); // remove this user
// notify remaining
this.sendMessageToUsers('left', { id: user.id, name: user.name });
// return this.users.length;
// close game if we were the last one and game hasn't finished
if (this.users.length === 0) {
// all left :(
this.game.end();
}
}, 5 * 60 * 1000);
}

Expand Down

0 comments on commit 24b2dbe

Please sign in to comment.