deepseek-v3-0324· DeepSeek LMArena Human Preference 140K
создай скрипт поля боя герои 3 на javascript без установки node.js
- User
создай скрипт поля боя герои 3 на javascript без установки node.js
- Assistant
Герои 3 - Поле боя на JavaScript
Вот простой скрипт поля боя в стиле Heroes of Might and Magic 3, который работает прямо в браузере без необходимости установки Node.js.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Heroes 3 Battlefield</title> <style> body { font-family: Arial, sans-serif; background-color: #222; color: white; margin: 0; padding: 20px; } #battlefield { display: grid; grid-template-columns: repeat(11, 50px); grid-template-rows: repeat(9, 50px); gap: 2px; margin: 20px auto; width: fit-content; } .tile { width: 50px; height: 50px; background-color: #4a752c; border: 1px solid #3a5a1c; position: relative; display: flex; justify-content: center; align-items: center; cursor: pointer; } .tile.obstacle { background-color: #5a4a3a; } .unit { width: 40px; height: 40px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-weight: bold; font-size: 12px; text-shadow: 1px 1px 1px black; box-shadow: 0 0 5px rgba(0,0,0,0.5); } .ally { background-color: #3498db; } .enemy { background-color: #e74c3c; } #controls { margin: 20px auto; text-align: center; } button { padding: 8px 16px; margin: 0 5px; background-color: #4a752c; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #5a8a3c; } #info-panel { background-color: #333; padding: 15px; border-radius: 5px; margin: 20px auto; max-width: 600px; } </style> </head> <body> <h1>Heroes 3 Battlefield</h1> <div id="battlefield"></div> <div id="controls"> <button id="end-turn">End Turn</button> <button id="reset">Reset Battle</button> </div> <div id="info-panel"> <h3>Battle Info</h3> <p id="turn-info">Current turn: Player 1</p> <p id="selected-unit">No unit selected</p> <p id="action-info">Click on a unit to select it, then click on a tile to move</p> </div> <script> // Game state const gameState = { currentTurn: 1, // 1 for player 1, 2 for player 2 selectedUnit: null, units: [ // Format: { id, x, y, type, health, attack, defense, speed, player } { id: 1, x: 1, y: 4, type: 'Pikeman', health: 10, attack: 4, defense: 5, speed: 4, player: 1, hasMoved: false }, { id: 2, x: 2, y: 3, type: 'Archer', health: 8, attack: 6, defense: 3, speed: 4, player: 1, hasMoved: false }, { id: 3, x: 9, y: 4, type: 'Skeleton', health: 6, attack: 5, defense: 4, speed: 3, player: 2, hasMoved: false }, { id: 4, x: 8, y: 5, type: 'Zombie', health: 12, attack: 3, defense: 5, speed: 2, player: 2, hasMoved: false } ], obstacles: [ { x: 5, y: 2 }, { x: 5, y: 3 }, { x: 5, y: 4 }, { x: 5, y: 5 }, { x: 5, y: 6 } ] }; // DOM elements const battlefield = document.getElementById('battlefield'); const turnInfo = document.getElementById('turn-info'); const selectedUnitInfo = document.getElementById('selected-unit'); const actionInfo = document.getElementById('action-info'); const endTurnBtn = document.getElementById('end-turn'); const resetBtn = document.getElementById('reset'); // Initialize the battlefield function initBattlefield() { battlefield.innerHTML = ''; // Create 11x9 grid for (let y = 0; y < 9; y++) { for (let x = 0; x < 11; x++) { const tile = document.createElement('div'); tile.className = 'tile'; tile.dataset.x = x; tile.dataset.y = y; // Check if this tile is an obstacle const isObstacle = gameState.obstacles.some(obs => obs.x === x && obs.y === y); if (isObstacle) { tile.classList.add('obstacle'); } // Check if there's a unit on this tile const unit = gameState.units.find(u => u.x === x && u.y === y); if (unit) { const unitElement = document.createElement('div'); unitElement.className = `unit ${unit.player === 1 ? 'ally' : 'enemy'}`; unitElement.textContent = unit.type.charAt(0); unitElement.title = `${unit.type}\nHP: ${unit.health}\nATK: ${unit.attack}\nDEF: ${unit.defense}\nSPD: ${unit.speed}`; tile.appendChild(unitElement); } tile.addEventListener('click', () => handleTileClick(x, y)); battlefield.appendChild(tile); } } updateUI(); } // Handle tile clicks function handleTileClick(x, y) { // Check if there's a unit on this tile const clickedUnit = gameState.units.find(u => u.x === x && u.y === y); // If no unit is selected and we clicked on a unit if (!gameState.selectedUnit && clickedUnit) { // Only select if it's the current player's unit if (clickedUnit.player === gameState.currentTurn) { gameState.selectedUnit = clickedUnit; updateUI(); } } // If we have a selected unit and clicked on an empty tile else if (gameState.selectedUnit && !clickedUnit) { // Check if the tile is within movement range const distance = Math.abs(x - gameState.selectedUnit.x) + Math.abs(y - gameState.selectedUnit.y); if (distance <= gameState.selectedUnit.speed && !gameState.selectedUnit.hasMoved) { // Check if the path is clear (simple implementation) const isPathClear = isPathFree(gameState.selectedUnit.x, gameState.selectedUnit.y, x, y); if (isPathClear) { // Move the unit gameState.selectedUnit.x = x; gameState.selectedUnit.y = y; gameState.selectedUnit.hasMoved = true; gameState.selectedUnit = null; initBattlefield(); } else { actionInfo.textContent = "Path is blocked!"; } } } // If we have a selected unit and clicked on an enemy unit else if (gameState.selectedUnit && clickedUnit && clickedUnit.player !== gameState.currentTurn) { // Check if enemy is adjacent const distance = Math.abs(x - gameState.selectedUnit.x) + Math.abs(y - gameState.selectedUnit.y); if (distance === 1) { // Attack! const damage = Math.max(1, gameState.selectedUnit.attack - clickedUnit.defense); clickedUnit.health -= damage; actionInfo.textContent = `${gameState.selectedUnit.type} attacks ${clickedUnit.type} for ${damage} damage!`; // Check if unit died if (clickedUnit.health <= 0) { gameState.units = gameState.units.filter(u => u.id !== clickedUnit.id); actionInfo.textContent += ` ${clickedUnit.type} was defeated!`; } gameState.selectedUnit.hasMoved = true; gameState.selected
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.