Batalla Por Terra <TRUSTED>
// Tipos de unidad const UNITS = INFANTRY: name: "⚔️", baseAtk: 8, baseDef: 5, range: 1, hp: 20, icon: "⚔️" , ARCHER: name: "🏹", baseAtk: 6, baseDef: 3, range: 3, hp: 15, icon: "🏹" , CAVALRY: name: "🐎", baseAtk: 10, baseDef: 4, range: 1, hp: 18, icon: "🐎" ;
function updateUI() renderGrid(); const turnSpan = document.getElementById("turn"); turnSpan.innerHTML = `🎲 Turno: $currentTurn === "attacker" ? "ATACANTE 🔥" : "DEFENSOR 🛡️"`; document.getElementById("attacker-stats").innerText = countUnits("attacker"); document.getElementById("defender-stats").innerText = countUnits("defender"); batalla por terra
// Verificar fin de batalla function checkVictory() const attackerCount = countUnits("attacker"); const defenderCount = countUnits("defender"); document.getElementById("attacker-stats").innerText = attackerCount; document.getElementById("defender-stats").innerText = defenderCount; if (attackerCount === 0) addLog("🏆 ¡VICTORIA DEL DEFENSOR! La tierra permanece firme."); return "defender"; if (defenderCount === 0) addLog("🏆 ¡VICTORIA DEL ATACANTE! La tierra es conquistada."); return "attacker"; return null; // Tipos de unidad const UNITS = INFANTRY:
// Renderizar grid function renderGrid() const gridContainer = document.getElementById("battle-grid"); gridContainer.innerHTML = ""; for (let i = 0; i < GRID_SIZE; i++) for (let j = 0; j < GRID_SIZE; j++) const cell = grid[i][j]; const cellDiv = document.createElement("div"); cellDiv.className = `cell $cell.terrain.name === "🌾" ? "plain" : (cell.terrain.name === "🌲" ? "forest" : "hill")`; if (selectedUnit && selectedUnit.x === i && selectedUnit.y === j) cellDiv.classList.add("selected"); let innerHtml = `<div class="unit $ """>$cell.terrain.name</div>`; if (cell.unit) const sideClass = cell.side === "attacker" ? "attacker" : "defender"; innerHtml = `<div class="unit $sideClass">$cell.unit.icon</div> <div class="hp">❤️$cell.unit.hp/$cell.unit.maxHp</div>`; cellDiv.innerHTML = innerHtml; cellDiv.addEventListener("click", (function(x,y) return function() handleCellClick(x,y); ; )(i,j)); gridContainer.appendChild(cellDiv); La tierra es conquistada