Batalla Por Terra -
def in_range(self, ax, ay, dx, dy, rng): return abs(ax-dx) + abs(ay-dy) <= rng
// Colocar ejércitos (ejemplo equilibrado) function placeArmies() // Atacante (zona izquierda) const attackerPositions = [[0,0],[1,1],[2,0],[0,2],[3,1],[1,3],[4,2],[5,0],[0,4],[2,3]]; const defenderPositions = [[9,9],[8,8],[9,7],[7,9],[6,8],[9,6],[8,5],[7,7],[9,4],[6,9]]; // Tipos variados const unitTypes = [UNITS.INFANTRY, UNITS.ARCHER, UNITS.CAVALRY, UNITS.INFANTRY, UNITS.ARCHER, UNITS.CAVALRY, UNITS.INFANTRY, UNITS.ARCHER, UNITS.CAVALRY, UNITS.INFANTRY]; attackerPositions.forEach((pos, idx) => if (pos[0] < GRID_SIZE && pos[1] < GRID_SIZE) const type = unitTypes[idx % unitTypes.length]; grid[pos[0]][pos[1]].unit = ...type, hp: type.hp, maxHp: type.hp ; grid[pos[0]][pos[1]].side = "attacker"; ); defenderPositions.forEach((pos, idx) => if (pos[0] < GRID_SIZE && pos[1] < GRID_SIZE) const type = unitTypes[(idx+3) % unitTypes.length]; grid[pos[0]][pos[1]].unit = ...type, hp: type.hp, maxHp: type.hp ; grid[pos[0]][pos[1]].side = "defender"; ); batalla por terra
def change_turn(self): self.current_turn = "defender" if self.current_turn == "attacker" else "attacker" print(f"\n🔄 Turno cambiado a self.current_turn.upper()") def in_range(self, ax, ay, dx, dy, rng): return
def play(self): while True: self.display() if self.check_victory(): break print("\nOpciones: ") print("1. Atacar (coordenadas atacante x y | defensor x y)") print("2. Terminar turno") print("3. Rendirse") opt = input("Elige: ") if opt == "3": print(f"self.current_turn se rinde. Batalla terminada.") break elif opt == "2": self.change_turn() continue elif opt == "1": try: ax, ay, dx, dy = map(int, input("Atacante (x y) y Defensor (x y): ").split()) if 0<=ax<self.size and 0<=ay<self.size and 0<=dx<self.size and 0<=dy<self.size: success, msg = self.attack(ax, ay, dx, dy) print(msg) if success: if self.check_victory(): break self.change_turn() else: print("Coordenadas inválidas") except: print("Formato incorrecto. Ejemplo: 1 0 6 7") input("\nPresiona Enter para continuar...") if == " main ": game = LandBattle(8) game.play() Características del Feature "Batalla por Tierra" ✅ Campo de batalla con terreno variable ✅ Dos facciones (Atacante/Defensor) ✅ Unidades con atributos distintos (daño, defensa, rango, HP) ✅ El terreno modifica el daño y defensa ✅ Sistema por turnos ✅ Interfaz visual para web o consola Rendirse") opt = input("Elige: ") if opt ==
// 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: "🐎" ;







