diff options
-rw-r--r-- | back/src/Game.ts | 23 | ||||
-rw-r--r-- | core/src/Suit.ts | 2 |
2 files changed, 20 insertions, 5 deletions
diff --git a/back/src/Game.ts b/back/src/Game.ts index 9434226..6e0fb43 100644 --- a/back/src/Game.ts +++ b/back/src/Game.ts @@ -55,16 +55,31 @@ export default class Game { for (let i = 1; i <= 13; ++i) for (let j = 0; j < 4; ++j) cards.push({rank: i, suit: j}); - // Shuffle cards - for (let i = 0; i < 52; ++i) { + const handSize = 5 - Math.floor(this.room.clients.length/7); + // Shuffle red cards + for (let i = 0; i < 26; ++i) { const j = Math.floor(Math.random() * (i+1)); [cards[i], cards[j]] = [cards[j], cards[i]]; } - const handSize = 5 - Math.floor(this.room.clients.length/7); + // Shuffle black cards + for (let i = 0; i < 26; ++i) { + const j = Math.floor(Math.random() * (i+1)); + [cards[i+26], cards[j+26]] = [cards[j+26], cards[i+26]]; + } 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); + this.players[i].cards.push(cards[i], cards[i+26]); // Make sure everyone has a red and black card + } + const remainingCards = []; + for (let i = this.room.clients.length; i < 26; ++i) + remainingCards.push(cards[i], cards[i+26]); + // Shuffle remaining cards + for (let i = 0; i < remainingCards.length; ++i) { + const j = Math.floor(Math.random() * (i+1)); + [remainingCards[i], remainingCards[j]] = [remainingCards[j], remainingCards[i]]; } + for (let i = 0; i < this.room.clients.length; ++i) + this.players[i].cards = remainingCards.slice(i*(handSize-2), (i+1)*(handSize-2)); const startingPlayer = this.players[0]; // Pick a random starting player instead?? this.playerTurn = this.players.indexOf(startingPlayer); this.playersFinished = this.room.clients.length; diff --git a/core/src/Suit.ts b/core/src/Suit.ts index b0bb087..c71fc6c 100644 --- a/core/src/Suit.ts +++ b/core/src/Suit.ts @@ -1,7 +1,7 @@ enum Suit { - Clubs, Diamonds, Hearts, + Clubs, Spades } |