User prompt
Haz que el personaje aparezca aleatoriamente en cualquier casilla del tablero
User prompt
Acomoda la puntuación SCORE un poco más a la izquierda
User prompt
Existe un error que hace que al seleccionar una vez return no se regresa al estado anterior, el segundo click si regresa al estado anterior, haciendo que por ejemplo estando el turno 4, seleccionar RETURN -> turno 4, seleccionar RETURN -> turno 3, seleccionar RETURN -> turno 2, después de eso no puede bajar al turno 1, corrige para hacer que desde el primer click se pueda regresar al turno anterior, sino se acumula un offset de un turno, debe ser un error de selección de indices
User prompt
Que con solo un click en Return se pueda regresar al estado anterior, actualmente se requiere ssleccionarlo 2 veces
User prompt
Casi, la primera vez que se selecciona return solo se disminuye el turno, si se selecciona una segunda vez o más sí funciona, corrige para regresar al estado anterior desde la primera vez que se selecciona return
User prompt
EL botón RETURN disminuye el turno y sí elimina el edificio pero solo si estamos sobre la casilla del edificio, crea una estructura que almacene el historial de movimientos y construcciones, para manejar los estados anteriores
User prompt
El botón return no realiza el retorno de posición, BUILD funciona correctamente
User prompt
Los botones no están implementados, ya que al seleccionarlos no realizan ninguna acción
User prompt
El botón RETURN debe deshacer el último turno, es decir, regresar a la posición anterior, restar el turno, la puntuación y si se creó un edificio eliminarlo
User prompt
Que el botón RETURN esté arriba del botón BUILD
User prompt
Reorganicemos la idea, que ya no exista la opción de NEXT TURN, al mover al personaje se considera que se ha pasado el turno, pero se puede deshacer con el botón RETURN, además acomoda los botones RETURN y BUILD
User prompt
Correcto, agrega la opción de poder regresar a la casilla de donde viene el personaje antes de seleccionar NEXT TURN en caso de que el usuario quiera corregir el movimiento
User prompt
Ahora corrige que solo se pueda mover a una casilla adyacente yo regresar y después seleccionar NEXT TURN, actualmente se puede mover indefinidamente sin seleccionar el botón
Code edit (1 edits merged)
Please save this source code
User prompt
Hex Farm Builder
Initial prompt
Quiero un juego donde se tenga un mapa, este mapa está dividido en casillas con forma hexagonal todos del mismo color (verde) pero con la división remarcada para identificar cada casilla, en ciertas casillas deben existir características especiales representadas de distintos colores (rojo, azul, morado, amarillo, café). Se debe poder mover a un personaje que se pueda mover a una casilla adyacente. Esto está limitado a 1 movimiento por turno, en las casillas especiales se puede construir estructuras especiales que permitirán ganar puntos, el objetivo es obtener la mayor cantidad de puntos en 20 turnos, para pasar turno debe existir un botón y para construir una estructura especial debe existir otro botón, en las casillas comunes (verdes) no se puede construir nada. En la estructura más visual debe representar una granja y las casillas especiales aspectos de esta, color verde es el césped, rojo graneros, azul pozos, morado plantíos de frutas, amarillo plantaciones de trigo, café establos. El punto es que existan varias de estas casillas especiales y cuando se cree el edificio en las casillas especiales sea visible para el jugador
/**** * Classes ****/ var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.row = 0; self.col = 0; self.previousRow = 0; self.previousCol = 0; self.moveToTile = function (tile) { self.previousRow = self.row; self.previousCol = self.col; self.x = tile.x; self.y = tile.y; self.row = tile.row; self.col = tile.col; LK.getSound('move').play(); }; self.returnToPreviousPosition = function () { if (hexGrid[self.previousRow] && hexGrid[self.previousRow][self.previousCol]) { var previousTile = hexGrid[self.previousRow][self.previousCol]; self.x = previousTile.x; self.y = previousTile.y; self.row = self.previousRow; self.col = self.previousCol; LK.getSound('move').play(); } }; return self; }); var HexTile = Container.expand(function (type, row, col) { var self = Container.call(this); self.type = type; self.row = row; self.col = col; self.hasBuilding = false; self.building = null; var assetName = 'hexGrass'; if (type === 'barn') assetName = 'hexRed';else if (type === 'well') assetName = 'hexBlue';else if (type === 'orchard') assetName = 'hexPurple';else if (type === 'wheat') assetName = 'hexYellow';else if (type === 'stable') assetName = 'hexBrown'; var hexGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.addBuilding = function () { if (self.hasBuilding || self.type === 'grass') return false; var buildingAsset = null; var points = 0; if (self.type === 'barn') { buildingAsset = 'barn'; points = 15; } else if (self.type === 'well') { buildingAsset = 'well'; points = 10; } else if (self.type === 'orchard') { buildingAsset = 'orchard'; points = 20; } else if (self.type === 'wheat') { buildingAsset = 'wheat'; points = 12; } else if (self.type === 'stable') { buildingAsset = 'stable'; points = 18; } if (buildingAsset) { self.building = self.attachAsset(buildingAsset, { anchorX: 0.5, anchorY: 0.5 }); self.hasBuilding = true; LK.getSound('build').play(); return points; } return 0; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x8BC34A }); /**** * Game Code ****/ // Game state var currentTurn = 1; var maxTurns = 20; var score = 0; var character = null; var hexGrid = []; var selectedTile = null; var gameStarted = false; var hasMovedThisTurn = false; // Hex grid dimensions var gridWidth = 8; var gridHeight = 12; var hexSize = 120; var hexHeight = 104; // UI elements var turnText = new Text2('Turn: 1/20', { size: 60, fill: 0x000000 }); turnText.anchor.set(0.5, 0); LK.gui.top.addChild(turnText); var scoreText = new Text2('Score: 0', { size: 60, fill: 0x000000 }); scoreText.anchor.set(0, 0); LK.gui.topRight.addChild(scoreText); scoreText.x = -200; var buildButton = new Text2('BUILD', { size: 50, fill: 0xFFFFFF }); buildButton.anchor.set(0.5, 1); LK.gui.bottom.addChild(buildButton); buildButton.y = -100; var nextTurnButton = new Text2('NEXT TURN', { size: 50, fill: 0xFFFFFF }); nextTurnButton.anchor.set(0.5, 1); LK.gui.bottom.addChild(nextTurnButton); var returnButton = new Text2('RETURN', { size: 50, fill: 0xFFFFFF }); returnButton.anchor.set(0.5, 1); LK.gui.bottom.addChild(returnButton); returnButton.x = -200; returnButton.y = -100; // Create hex grid function createHexGrid() { var startX = 200; var startY = 300; for (var row = 0; row < gridHeight; row++) { hexGrid[row] = []; for (var col = 0; col < gridWidth; col++) { var xOffset = row % 2 * (hexSize * 0.75); var x = startX + col * (hexSize * 1.5) + xOffset; var y = startY + row * (hexHeight * 0.75); // Skip if position would be off screen if (x > 1900 || y > 2400) continue; var tileType = 'grass'; // Add special tiles randomly if (Math.random() < 0.2) { var specialTypes = ['barn', 'well', 'orchard', 'wheat', 'stable']; tileType = specialTypes[Math.floor(Math.random() * specialTypes.length)]; } var tile = new HexTile(tileType, row, col); tile.x = x; tile.y = y; hexGrid[row][col] = tile; game.addChild(tile); } } } // Get adjacent tiles function getAdjacentTiles(row, col) { var adjacent = []; var directions; if (row % 2 === 0) { directions = [[-1, -1], [-1, 0], [0, -1], [0, 1], [1, -1], [1, 0]]; } else { directions = [[-1, 0], [-1, 1], [0, -1], [0, 1], [1, 0], [1, 1]]; } for (var i = 0; i < directions.length; i++) { var newRow = row + directions[i][0]; var newCol = col + directions[i][1]; if (newRow >= 0 && newRow < gridHeight && newCol >= 0 && newCol < gridWidth && hexGrid[newRow] && hexGrid[newRow][newCol]) { adjacent.push(hexGrid[newRow][newCol]); } } return adjacent; } // Initialize game function initGame() { createHexGrid(); // Place character on first available tile for (var row = 0; row < gridHeight; row++) { for (var col = 0; col < gridWidth; col++) { if (hexGrid[row] && hexGrid[row][col]) { character = new Character(); character.moveToTile(hexGrid[row][col]); game.addChild(character); gameStarted = true; return; } } } } // Update UI function updateUI() { turnText.setText('Turn: ' + currentTurn + '/' + maxTurns); scoreText.setText('Score: ' + score); } // Check if character can move to tile function canMoveTo(tile) { var adjacents = getAdjacentTiles(character.row, character.col); return adjacents.indexOf(tile) !== -1; } // End turn function endTurn() { currentTurn++; selectedTile = null; hasMovedThisTurn = false; if (character) { character.previousRow = character.row; character.previousCol = character.col; } if (currentTurn > maxTurns) { LK.setScore(score); LK.showYouWin(); return; } updateUI(); } // Handle tile clicks game.down = function (x, y, obj) { if (!gameStarted || hasMovedThisTurn) return; // Check if clicking on a hex tile for (var row = 0; row < gridHeight; row++) { for (var col = 0; col < gridWidth; col++) { if (hexGrid[row] && hexGrid[row][col]) { var tile = hexGrid[row][col]; var distance = Math.sqrt(Math.pow(x - tile.x, 2) + Math.pow(y - tile.y, 2)); if (distance < 60) { if (canMoveTo(tile)) { character.moveToTile(tile); selectedTile = tile; hasMovedThisTurn = true; } return; } } } } }; // Build button handler buildButton.down = function (x, y, obj) { if (!gameStarted || !selectedTile) return; var currentTile = null; for (var row = 0; row < gridHeight; row++) { for (var col = 0; col < gridWidth; col++) { if (hexGrid[row] && hexGrid[row][col] && hexGrid[row][col].row === character.row && hexGrid[row][col].col === character.col) { currentTile = hexGrid[row][col]; break; } } } if (currentTile && currentTile.type !== 'grass' && !currentTile.hasBuilding) { var points = currentTile.addBuilding(); if (points > 0) { score += points; updateUI(); } } }; // Return button handler returnButton.down = function (x, y, obj) { if (!gameStarted || !hasMovedThisTurn) return; character.returnToPreviousPosition(); selectedTile = null; hasMovedThisTurn = false; }; // Next turn button handler nextTurnButton.down = function (x, y, obj) { if (!gameStarted) return; endTurn(); }; // Initialize the game initGame(); updateUI();
===================================================================
--- original.js
+++ change.js
@@ -8,15 +8,29 @@
anchorY: 0.5
});
self.row = 0;
self.col = 0;
+ self.previousRow = 0;
+ self.previousCol = 0;
self.moveToTile = function (tile) {
+ self.previousRow = self.row;
+ self.previousCol = self.col;
self.x = tile.x;
self.y = tile.y;
self.row = tile.row;
self.col = tile.col;
LK.getSound('move').play();
};
+ self.returnToPreviousPosition = function () {
+ if (hexGrid[self.previousRow] && hexGrid[self.previousRow][self.previousCol]) {
+ var previousTile = hexGrid[self.previousRow][self.previousCol];
+ self.x = previousTile.x;
+ self.y = previousTile.y;
+ self.row = self.previousRow;
+ self.col = self.previousCol;
+ LK.getSound('move').play();
+ }
+ };
return self;
});
var HexTile = Container.expand(function (type, row, col) {
var self = Container.call(this);
@@ -115,8 +129,16 @@
fill: 0xFFFFFF
});
nextTurnButton.anchor.set(0.5, 1);
LK.gui.bottom.addChild(nextTurnButton);
+var returnButton = new Text2('RETURN', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+returnButton.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(returnButton);
+returnButton.x = -200;
+returnButton.y = -100;
// Create hex grid
function createHexGrid() {
var startX = 200;
var startY = 300;
@@ -190,8 +212,12 @@
function endTurn() {
currentTurn++;
selectedTile = null;
hasMovedThisTurn = false;
+ if (character) {
+ character.previousRow = character.row;
+ character.previousCol = character.col;
+ }
if (currentTurn > maxTurns) {
LK.setScore(score);
LK.showYouWin();
return;
@@ -238,8 +264,15 @@
updateUI();
}
}
};
+// Return button handler
+returnButton.down = function (x, y, obj) {
+ if (!gameStarted || !hasMovedThisTurn) return;
+ character.returnToPreviousPosition();
+ selectedTile = null;
+ hasMovedThisTurn = false;
+};
// Next turn button handler
nextTurnButton.down = function (x, y, obj) {
if (!gameStarted) return;
endTurn();
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Hex Farm Builder" and with the description "Strategic turn-based farming game on a hexagonal grid where players move a character and build farm structures on special colored tiles to maximize points in 20 turns.". No text on banner!
Quítale el techo y aleja un poco la perspectiva
Un pozo con una cubeta llena de agua. In-Game asset. No shadows
Vuelve la parcela más densa de trigo
Una plantación de frutas rojas. In-Game asset. No shadows
Polvo de construcción denso. In-Game asset. No shadows
Rectángulo de madera color rojo. In-Game asset. 2d. High contrast. No shadows
Rectángulo de madera color café. In-Game asset. 2d. High contrast. No shadows
Elimina el fondo y que se vea derecho respecto al monitor
Cima de una colina redondeada con un sendero que lleva a la cima, mucho césped. In-Game asset. 2d. High contrast. No shadows