diff --git a/public/game.js b/public/game.js index c9697a4..f574e99 100644 --- a/public/game.js +++ b/public/game.js @@ -402,24 +402,25 @@ class GameUI { // Combat! Roll dice const attackRoll = Math.floor(Math.random() * attackStrength) + 1; const defenseRoll = Math.floor(Math.random() * defenseStrength) + 1; - + this.log(`Attack: ${attackStrength} vs ${defenseStrength} | Roll: ${attackRoll} vs ${defenseRoll}`); - + if (attackRoll > defenseRoll) { // Attacker wins const remainingStrength = attackRoll - 1; attacker.setStrength(1); - + if (remainingStrength > 0) { defender.setStrength(remainingStrength); this.map.setOwner(defender.q, defender.r, this.currentPlayer); this.log(`Victory! Captured cell with strength ${remainingStrength}`, 'victory'); } } else { - // Defender wins + // Defender wins - attacker loses all but 1 die const remainingDefense = defenseRoll - attackRoll; defender.setStrength(Math.max(1, remainingDefense)); - this.log(`Attack repelled! Defender has ${Math.max(1, remainingDefense)} strength`, 'defeat'); + attacker.setStrength(1); // Attacker reduced to 1 + this.log(`Attack repelled! Attacker reduced to 1, Defender has ${Math.max(1, remainingDefense)} strength`, 'defeat'); } } else { // Move to empty cell - transfer attackStrength (original - 1) @@ -465,25 +466,26 @@ class GameUI { distributeSupply(supply) { const playerCells = this.map.getPlayerCells(this.currentPlayer); - + // Find cells that can receive more dice const eligibleCells = playerCells.filter(cell => !cell.isMaxStrength()); - + if (eligibleCells.length === 0 || supply === 0) return; - - // Distribute supply randomly among eligible cells + + // Distribute supply one by one to random eligible cells let remainingSupply = supply; while (remainingSupply > 0 && eligibleCells.length > 0) { + // Pick random cell const randomCell = eligibleCells[Math.floor(Math.random() * eligibleCells.length)]; const currentStrength = randomCell.getStrength(); - + if (currentStrength < 48) { - const addStrength = Math.min(remainingSupply, 48 - currentStrength); - const newStrength = currentStrength + addStrength; - randomCell.setStrength(newStrength); - remainingSupply -= addStrength; + // Add 1 strength to this cell + randomCell.setStrength(currentStrength + 1); + remainingSupply--; } - + + // Remove cell from eligible if it's now at max strength if (randomCell.isMaxStrength()) { eligibleCells.splice(eligibleCells.indexOf(randomCell), 1); } @@ -530,7 +532,8 @@ class GameUI { const endTurnBtn = document.getElementById('end-turn-btn'); cancelBtn.disabled = !this.selectedCell; - endTurnBtn.disabled = !this.hasMoved; + // End turn is always enabled + endTurnBtn.disabled = false; } log(message, type = '') {