fix: per-player phase state so 2nd player can still play after 1st played
This commit is contained in:
1 parent
78adeb7920
commit
25ab76c4ac
3 files changed
+25
-14
No files matched your search
@@ -30,6 +30,7 @@ export class GameScene extends Phaser.Scene {
|
||||
this.handCards = []
|
||||
this.selectedCard = null
|
||||
this.resolveObjects = []
|
||||
this._canPlay = false // true uniquement quand c'est la phase 'selecting' locale
|
||||
}
|
||||
|
||||
create() {
|
||||
@@ -164,7 +165,10 @@ export class GameScene extends Phaser.Scene {
|
||||
}
|
||||
|
||||
_playSelectedCard() {
|
||||
if (!this.selectedCard || this.store.phase !== 'selecting') return
|
||||
if (!this.selectedCard || !this._canPlay) return
|
||||
|
||||
// Bloquer immédiatement pour éviter le double clic
|
||||
this._canPlay = false
|
||||
|
||||
this.socket.emit('play-card', {
|
||||
roomId: this.roomId,
|
||||
@@ -286,6 +290,7 @@ export class GameScene extends Phaser.Scene {
|
||||
this.turnText.setText(`Tour ${state.currentTurn} / ${state.maxTurns}`)
|
||||
|
||||
if (state.phase === 'selecting') {
|
||||
this._canPlay = true
|
||||
this.resolveObjects.forEach(o => o.destroy())
|
||||
this.resolveObjects = []
|
||||
this.phaseText.setText('Sélectionnez une carte')
|
||||
@@ -293,8 +298,13 @@ export class GameScene extends Phaser.Scene {
|
||||
}
|
||||
|
||||
if (state.phase === 'waiting') {
|
||||
this._canPlay = false
|
||||
this.phaseText.setText('En attente des autres joueurs...')
|
||||
}
|
||||
|
||||
if (state.phase === 'resolve' || state.phase === 'end') {
|
||||
this._canPlay = false
|
||||
}
|
||||
})
|
||||
|
||||
this.socket.on('round-result', ({ playedCards, attrResults }) => {
|
||||
|
||||
@@ -72,11 +72,8 @@ class Room {
|
||||
const [card] = player.hand.splice(cardIndex, 1)
|
||||
this.pendingPlays.set(socketId, { player, card })
|
||||
|
||||
// Si tous ont joué → passer en "waiting" visible côté client
|
||||
if (this.pendingPlays.size === this.players.length) {
|
||||
this.phase = 'waiting'
|
||||
}
|
||||
|
||||
// La phase globale reste 'selecting' tant que tout le monde n'a pas joué
|
||||
// (seul le joueur qui vient de jouer passe en 'waiting' côté client via son état perso)
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -178,14 +175,19 @@ class Room {
|
||||
}))
|
||||
}
|
||||
|
||||
/** État envoyé à UN joueur spécifique (inclut sa main) */
|
||||
/** État envoyé à UN joueur spécifique (inclut sa main et sa phase personnelle) */
|
||||
getStateFor(socketId) {
|
||||
const player = this.players.find(p => p.socketId === socketId)
|
||||
// Si ce joueur a déjà joué ce tour → sa phase perso est 'waiting'
|
||||
// Sinon il est encore en 'selecting'
|
||||
const hasPlayed = this.pendingPlays.has(socketId)
|
||||
const personalPhase = this.phase === 'selecting' && hasPlayed ? 'waiting' : this.phase
|
||||
|
||||
return {
|
||||
players: this.getPlayersInfo(),
|
||||
currentTurn: this.currentTurn,
|
||||
maxTurns: this.maxTurns,
|
||||
phase: this.phase,
|
||||
phase: personalPhase,
|
||||
hand: player ? player.hand : [],
|
||||
myTeamIndex: player ? player.teamIndex : 0
|
||||
}
|
||||
|
||||
+5
-6
@@ -69,12 +69,11 @@ io.on('connection', (socket) => {
|
||||
return
|
||||
}
|
||||
|
||||
// Informer tous que quelqu'un a joué (sans révéler la carte)
|
||||
io.to(roomId).emit('game-state', {
|
||||
players: room.getPlayersInfo(),
|
||||
currentTurn: room.currentTurn,
|
||||
maxTurns: room.maxTurns,
|
||||
phase: room.phase
|
||||
// Envoyer à chaque joueur son état personnalisé :
|
||||
// - celui qui vient de jouer reçoit phase='waiting'
|
||||
// - les autres restent en phase='selecting'
|
||||
room.players.forEach(player => {
|
||||
io.to(player.socketId).emit('game-state', room.getStateFor(player.socketId))
|
||||
})
|
||||
|
||||
// Tous les joueurs ont joué → résolution automatique
|
||||
|
||||
Reference in new issue
Block a user