feat: draw one card after each turn with slide-in animation

This commit is contained in:
kevin.lhereec committed 2026-08-17 12:07:47 +02:00
1 parent ec5a7ec2c3
commit b46cb707cd
3 files changed
+102 -10

No files matched your search

+17 -6
View File
@@ -37,7 +37,8 @@ class Room {
name,
teamIndex: this.players.length,
gauges: { food: 0, war: 0, health: 0, diplo: 0 },
hand: []
hand: [],
deck: [] // cartes restantes à piocher
})
return true
}
@@ -49,9 +50,10 @@ class Room {
// ─── Démarrage ──────────────────────────────────────────────────────────────
startGame() {
const hands = dealHands(this.players.length, HAND_SIZE)
const dealt = dealHands(this.players.length, HAND_SIZE)
this.players.forEach((p, i) => {
p.hand = hands[i]
p.hand = dealt[i].hand
p.deck = dealt[i].deck
p.gauges = { food: 0, war: 0, health: 0, diplo: 0 }
})
this.currentTurn = 1
@@ -144,6 +146,13 @@ class Room {
// ─── Tour suivant ────────────────────────────────────────────────────────────
nextTurn() {
// Chaque joueur pioche une carte depuis son deck personnel
this.players.forEach(p => {
if (p.deck.length > 0) {
p.hand.push(p.deck.shift())
}
})
this.currentTurn++
if (this.isGameOver()) {
this.phase = 'end'
@@ -153,8 +162,9 @@ class Room {
}
isGameOver() {
const allEmpty = this.players.every(p => p.hand.length === 0)
return allEmpty || this.currentTurn >= this.maxTurns
// Partie terminée quand plus personne n'a de carte en main ET plus de deck
const allEmpty = this.players.every(p => p.hand.length === 0 && p.deck.length === 0)
return allEmpty || this.currentTurn > this.maxTurns
}
// ─── Données publiques ───────────────────────────────────────────────────────
@@ -165,7 +175,8 @@ class Room {
teamIndex: p.teamIndex,
gauges: { ...p.gauges },
score: ATTRS.reduce((sum, a) => sum + p.gauges[a], 0),
handSize: p.hand.length
handSize: p.hand.length,
deckSize: p.deck.length
}))
}
+9 -3
View File
@@ -165,13 +165,19 @@ function shuffle(arr) {
return a
}
/**
* Pour chaque joueur : retourne { hand, deck } (hand = les N premières cartes, deck = le reste)
*/
function dealHands(playerCount, handSize = 4) {
const hands = []
const result = []
for (let i = 0; i < playerCount; i++) {
const deck = shuffle(getDeckForTeam(i))
hands.push(deck.slice(0, handSize))
result.push({
hand: deck.slice(0, handSize),
deck: deck.slice(handSize) // cartes restantes à piocher
})
}
return hands
return result
}
module.exports = { CHARACTERS, TEAM_COLORS, ATTR_COLORS, getDeckForTeam, dealHands }