aboutsummaryrefslogtreecommitdiff
path: root/back
diff options
context:
space:
mode:
authorAnthony Wang2021-05-07 21:10:54 -0500
committerAnthony Wang2021-05-07 21:10:54 -0500
commitd1c0d54c40b11c44c7531911bec37ebbe550d33e (patch)
tree211b3910bd31a5770358ed76153788a73bcfb7b2 /back
parent069e1d3a1fc80ae2d202b9e8ae4d2c9ee4102a81 (diff)
Fix some bugs
Diffstat (limited to 'back')
-rw-r--r--back/src/Game.ts11
1 files changed, 9 insertions, 2 deletions
diff --git a/back/src/Game.ts b/back/src/Game.ts
index 6dbe502..9b0b5d6 100644
--- a/back/src/Game.ts
+++ b/back/src/Game.ts
@@ -10,6 +10,7 @@ class Player {
client: Client;
cards: Card[] = [];
stack: Card[] = [];
+ flipped: Card[] = [];
disconnected = false;
disconnectListener?: () => void;
rank = 0;
@@ -26,6 +27,7 @@ class Player {
username: p.client.username,
numCards: p.cards.length,
stackSize: p.stack.length,
+ flipped: p.flipped,
rank: p.rank,
})),
phase: this.game.phase,
@@ -58,7 +60,7 @@ export default class Game {
const j = Math.floor(Math.random() * (i+1));
[cards[i], cards[j]] = [cards[j], cards[i]];
}
- const handSize = 5 - this.room.clients.length/7;
+ const handSize = 5; // 5 - this.room.clients.length/7;
for (let i = 0; i < this.room.clients.length; ++i) {
this.players.push(new Player(this, this.room.clients[i]));
this.players[i].cards = cards.slice(i * handSize, (i + 1) * handSize);
@@ -108,11 +110,13 @@ export default class Game {
}
while (this.lastPlayed > 0) { // Phase 2
await this.flip();
+ this.lastPlayed--;
if (this.phase === 3 as number) { // Oops, flipped over a red card!
await this.giveup(); // The player who called BS won and now the challenged player must give up a card!
return;
}
}
+ this.phase = 3;
await this.giveup(); // The player who called BS won and now they must give up a card!
}
async prepare() { // Players prepare their hand for this round
@@ -126,6 +130,8 @@ export default class Game {
delete p.disconnectListener;
(() => {
p.stack = stack;
+ p.cards = [...stack];
+ p.flipped = [];
return;
})();
resolve();
@@ -176,6 +182,7 @@ export default class Game {
if (this.players[selectedPlayer].stack.length > 0) {
if (this.players[selectedPlayer].stack[0].suit === Suit.Diamonds ||
this.players[selectedPlayer].stack[0].suit === Suit.Hearts) this.phase = 3; // Red card
+ this.players[selectedPlayer].flipped.push(this.players[selectedPlayer].stack[0]);
this.players[selectedPlayer].stack.splice(0, 1);
return;
}
@@ -192,7 +199,7 @@ export default class Game {
});
}
async giveup() { // Give up a card
- const p = this.players[this.lastPlayed ? this.lastPlayedPlayer : this.playerTurn];
+ const p = this.players[this.lastPlayed > 0 ? this.lastPlayedPlayer : this.playerTurn];
this.broadcastGameState();
await new Promise<void>(resolve => {
p.client.once('giveup', card => {