diff --git a/client/src/game/scenes/GameScene.js b/client/src/game/scenes/GameScene.js index b89bcb3..83ba3f3 100644 --- a/client/src/game/scenes/GameScene.js +++ b/client/src/game/scenes/GameScene.js @@ -68,33 +68,49 @@ export class GameScene extends Phaser.Scene { color: '#a08060' }).setOrigin(0.5) - // 4 emplacements de cartes jouées (zone centrale) + // Les slots sont créés dynamiquement dans _buildSlots(n) une fois le nb de joueurs connu this.playSlots = [] - const slotY = height / 2 - 60 - const totalW = 4 * 140 - const startX = width / 2 - totalW / 2 + 70 - - for (let i = 0; i < 4; i++) { - const x = startX + i * 140 - const slot = this.add.graphics() - slot.lineStyle(1, 0xd4a73240) - slot.strokeRoundedRect(-65, -95, 130, 190, 8) - slot.x = x - slot.y = slotY - this.playSlots.push({ x, y: slotY, graphics: slot }) - - // Label joueur - this.add.text(x, slotY + 108, `J${i + 1}`, { - fontSize: '11px', - fontFamily: 'Georgia', - color: '#4a3020' - }).setOrigin(0.5) - } + this.slotObjects = [] // pour pouvoir les détruire/recréer // Légende attributs (coin en bas à droite, au-dessus de la marge Windows) this._buildAttrLegend(width - 10, height - BOTTOM_MARGIN - 10) } + _buildSlots(playerCount) { + const { width, height } = this.scale + + // Détruire les anciens slots + this.slotObjects.forEach(o => o.destroy()) + this.slotObjects = [] + this.playSlots = [] + + const slotY = height / 2 - 60 + const spacing = 140 + const totalW = playerCount * spacing + const startX = width / 2 - totalW / 2 + spacing / 2 + + for (let i = 0; i < playerCount; i++) { + const x = startX + i * spacing + + const g = this.add.graphics() + g.lineStyle(1, 0xd4a73240) + g.strokeRoundedRect(-65, -95, 130, 190, 8) + g.x = x + g.y = slotY + this.slotObjects.push(g) + + const label = this.add.text(x, slotY + 108, + this.store.players[i]?.name ?? `J${i + 1}`, { + fontSize: '11px', + fontFamily: 'Georgia', + color: '#4a3020' + }).setOrigin(0.5) + this.slotObjects.push(label) + + this.playSlots.push({ x, y: slotY }) + } + } + _buildAttrLegend(x, y) { const entries = [ { attr: 'food', label: '🟡 Nourriture — haut gauche' }, @@ -343,6 +359,10 @@ export class GameScene extends Phaser.Scene { this.phaseText.setText('Choisissez une carte puis confirmez') this.readyText.setText('') this._deactivateBtn() + // (Re)construire les slots si le nombre de joueurs a changé ou premier tour + if (this.playSlots.length !== state.players.length) { + this._buildSlots(state.players.length) + } this._buildHand(state.hand) }