aboutsummaryrefslogtreecommitdiff
path: root/back
diff options
context:
space:
mode:
authorAnthony Wang2021-05-08 21:06:42 -0500
committerAnthony Wang2021-05-08 21:06:42 -0500
commite5c942c941ba648e70aa4143fda79768499db14a (patch)
tree549401d7bc25e3da79cd99e283f5785930fda9f3 /back
parent8cf4626e99c75e00a14169a549d58e42fd5cbab2 (diff)
Correctly implement end of game
Diffstat (limited to 'back')
-rw-r--r--back/src/Game.ts16
1 files changed, 7 insertions, 9 deletions
diff --git a/back/src/Game.ts b/back/src/Game.ts
index 9b0b5d6..61bbdf9 100644
--- a/back/src/Game.ts
+++ b/back/src/Game.ts
@@ -67,19 +67,17 @@ export default class Game {
}
const startingPlayer = this.players[0]; // Pick a random starting player instead??
this.playerTurn = this.players.indexOf(startingPlayer);
+ this.playersFinished = this.room.clients.length;
+ // Run the game
while (true) {
- // Check if game ended
- // Rewrite
const playersLeft: Player[] = [];
this.players.forEach((p: Player) => {
- if (!p.rank && !p.disconnected)
- playersLeft.push(p);
+ if (!p.rank && !p.disconnected) {
+ if (p.cards.length === 0) p.rank = this.playersFinished--;
+ else playersLeft.push(p);
+ }
});
- if (playersLeft.length < 2) {
- if (playersLeft.length === 1)
- playersLeft[0].rank = ++this.playersFinished; // rank is reversed, fix later
- break;
- }
+ if (playersLeft.length === 1) break;
await this.round();
}
this.broadcastGameState();