Commit ee4d70dc authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: local-multi mode celebrations, capture feedback, and dice shake

- afterMove: use boardSlot for firework/flash colors (not player index)
- afterMove: in local-multi, ANY human capturing triggers celebration
  (not just player 0)
- botLoop: capture detection checks all human players in local-multi
  (not just myPlayerIndex=0)
- animateDice: shake dice-area for all human players in local-multi
  (previously only shook for player 0, panel for others)
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 41f869f8
......@@ -446,8 +446,10 @@ async function botLoop(el) {
rules.applyMove(game, game.currentPlayer, move);
if (move.type === 'capture') {
const capturedMe = move._capturedPlayers && move._capturedPlayers.includes(myPlayerIndex);
if (capturedMe) {
const capturedHuman = move._capturedPlayers && move._capturedPlayers.some(p =>
game.mode === 'local-multi' ? game.humanPlayers.includes(p) : p === myPlayerIndex
);
if (capturedHuman) {
audio.play('lose', 'game');
juice.hapticError();
juice.shake(el, 8, 400);
......@@ -836,17 +838,17 @@ function fireworkBurst(x, y, color) {
function afterMove(el, move) {
game.rolled = false;
const mover = game.currentPlayer;
const moverSlot = game.players[mover]?.boardSlot ?? mover;
const isHumanMover = game.mode === 'local-multi' ? game.humanPlayers.includes(mover) : mover === myPlayerIndex;
if (move.type === 'capture') {
if (mover === myPlayerIndex) {
// I captured someone — celebrate!
if (isHumanMover) {
audio.play('capture', 'reward');
juice.hapticSuccess();
juice.confetti(window.innerWidth / 2, window.innerHeight / 2, 30);
juice.starBurst(window.innerWidth / 2, window.innerHeight / 2, 10);
juice.screenFlash('rgba(76,175,80,0.2)', 400);
} else {
// A bot/opponent captured — check if MY pawn was the victim
const capturedMe = move._capturedPlayers && move._capturedPlayers.includes(myPlayerIndex);
if (capturedMe) {
audio.play('lose', 'game');
......@@ -859,12 +861,12 @@ function afterMove(el, move) {
}
}
} else if (move.type === 'finish') {
if (mover === myPlayerIndex) {
if (isHumanMover) {
audio.play('sfx_piece_home', 'reward');
juice.hapticSuccess();
const boardRect = canvas.getBoundingClientRect();
fireworkBurst(boardRect.left + boardRect.width / 2, boardRect.top + boardRect.height / 2, COLORS[mover]);
juice.screenFlash(COLORS[mover] + '22', 500);
fireworkBurst(boardRect.left + boardRect.width / 2, boardRect.top + boardRect.height / 2, COLORS[moverSlot]);
juice.screenFlash(COLORS[moverSlot] + '22', 500);
} else {
audio.play('sfx_piece_home', 'game');
}
......@@ -1269,7 +1271,7 @@ function animateDice(el, playerIdx) {
return new Promise(resolve => {
const mainDice = el.querySelector('#dice-box');
const miniDice = el.querySelector(`#dice-${playerIdx}`);
const isMe = playerIdx === myPlayerIndex;
const isMe = game.mode === 'local-multi' ? game.humanPlayers.includes(playerIdx) : playerIdx === myPlayerIndex;
// Show mini dice in rolling state
if (miniDice) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment