User prompt
haz que las preguntas no se repitan
User prompt
avanza las casillas correspondientes al numero del dado solamente si la respuesta es correcta
User prompt
cuando responda de manera correcta arroja una ventana que diga: "CORRECTO!"
User prompt
traduce me las preguntas y respuestas en español
User prompt
al fallar una pregunta me debería quitar 5 tokens y al momento de quedar sin tokens el juego debe terminar
User prompt
arregla el gameover
User prompt
Please fix the bug: 'ReferenceError: showQuestion is not defined' in or related to this line: 'showQuestion();' Line Number: 89
User prompt
Please fix the bug: 'ReferenceError: showQuestion is not defined' in or related to this line: 'showQuestion();' Line Number: 89
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'K is not defined' in or related to this line: 'K.init.image('Mapa', {' Line Number: 129
Code edit (1 edits merged)
Please save this source code
User prompt
siguen sin funcionar las mecánicas de respuestas correctas
User prompt
puedes hacer todo el código de nuevo ya que las mecánicas de respuestas correctas no están funcionando
User prompt
crea todas las preguntas y respuestas desde 0 ya que no están funcionando las respuestas correctas
User prompt
arregla la mecánica de respuestas correctas, al responder correctamente me debería dejar lanzar el dado nuevamente y sumarme 5 fichas mas
User prompt
crea nuevas preguntas y respuestas
User prompt
sigue sin reconocer las respuestas correctas, marco la respuesta correcta y el juego la esta reconociendo como incorrecta ya que pierdo siempre
User prompt
las respuestas correctas no las reconoce
User prompt
me esta tomando todas las respuestas como incorrectas
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'children')' in or related to this line: 'LK.effects.flashObject(currentAnswers[answerIndex].children[0], 0xFF0000, 500);' Line Number: 451
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'children')' in or related to this line: 'LK.effects.flashObject(currentAnswers[answerIndex].children[0], 0xFF0000, 500);' Line Number: 451
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'graphics')' in or related to this line: 'LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0xFF0000, 500);' Line Number: 451
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'children')' in or related to this line: 'LK.effects.flashObject(currentAnswers[answerIndex].children[0], 0xFF0000, 500);' Line Number: 449
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'graphics')' in or related to this line: 'LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0xFF0000, 500);' Line Number: 450
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '__colorFlash_current_tick')' in or related to this line: 'LK.effects.flashObject(currentAnswers[answerIndex], 0xFF0000, 500);' Line Number: 449
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Castle = Container.expand(function () {
var self = Container.call(this);
var castleGraphics = self.attachAsset('castle', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Dice = Container.expand(function () {
var self = Container.call(this);
var diceGraphics = self.attachAsset('dice', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 1;
self.isRolling = false;
var diceText = new Text2('1', {
size: 60,
fill: 0x000000
});
diceText.anchor.set(0.5, 0.5);
self.addChild(diceText);
self.roll = function () {
if (self.isRolling) {
return;
}
self.isRolling = true;
LK.getSound('diceRoll').play();
var rollCount = 0;
var rollInterval = LK.setInterval(function () {
self.value = Math.floor(Math.random() * 6) + 1;
diceText.setText(self.value.toString());
rollCount++;
if (rollCount >= 10) {
LK.clearInterval(rollInterval);
self.isRolling = false;
moveKnight();
}
}, 100);
};
self.down = function (x, y, obj) {
if (!self.isRolling && !questionActive && !gameOver) {
self.roll();
}
};
return self;
});
var Knight = Container.expand(function () {
var self = Container.call(this);
var knightGraphics = self.attachAsset('knight', {
anchorX: 0.5,
anchorY: 0.5
});
self.currentTile = 0;
self.moveToTile = function (tileIndex) {
if (tileIndex < pathTiles.length) {
self.currentTile = tileIndex;
var targetTile = pathTiles[tileIndex];
tween(self, {
x: targetTile.x,
y: targetTile.y
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (tileIndex > 0 && tileIndex < pathTiles.length - 1) {
showQuestion();
} else if (tileIndex === pathTiles.length - 1) {
showVictory();
}
}
});
}
};
return self;
});
var Tile = Container.expand(function () {
var self = Container.call(this);
var tileGraphics = self.attachAsset('tile', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Village = Container.expand(function () {
var self = Container.call(this);
var villageGraphics = self.attachAsset('village', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
// Declaración simplificada de la imagen
var tokens = 5;
var questionActive = false;
var gameOver = false;
var currentQuestion = null;
var currentAnswers = [];
// Path tiles array
var pathTiles = [];
// Game objects
var knight = null;
var dice = null;
var tokenText = null;
var questionContainer = null;
var backgroundImage = null;
// Question database
var questions = [
// Easy questions (tiles 1-3)
{
question: "What is 2 + 2?",
answers: ["3", "4", "5", "6"],
correct: 1,
difficulty: 1
}, {
question: "What color do you get when you mix red and blue?",
answers: ["Green", "Purple", "Orange", "Yellow"],
correct: 1,
difficulty: 1
}, {
question: "How many days are in a week?",
answers: ["6", "7", "8", "9"],
correct: 1,
difficulty: 1
}, {
question: "What is the opposite of hot?",
answers: ["Warm", "Cool", "Cold", "Freezing"],
correct: 2,
difficulty: 1
},
// Medium questions (tiles 4-6)
{
question: "What is 15 × 3?",
answers: ["43", "45", "47", "49"],
correct: 1,
difficulty: 2
}, {
question: "Which planet is closest to the Sun?",
answers: ["Venus", "Mercury", "Mars", "Earth"],
correct: 1,
difficulty: 2
}, {
question: "What is the capital of France?",
answers: ["London", "Berlin", "Paris", "Rome"],
correct: 2,
difficulty: 2
}, {
question: "How many sides does a triangle have?",
answers: ["2", "3", "4", "5"],
correct: 1,
difficulty: 2
},
// Hard questions (tiles 7-9)
{
question: "What is the square root of 64?",
answers: ["6", "7", "8", "9"],
correct: 2,
difficulty: 3
}, {
question: "Who wrote Romeo and Juliet?",
answers: ["Charles Dickens", "William Shakespeare", "Jane Austen", "Mark Twain"],
correct: 1,
difficulty: 3
}, {
question: "What is the chemical symbol for gold?",
answers: ["Go", "Gd", "Au", "Ag"],
correct: 2,
difficulty: 3
}, {
question: "In which year did World War II end?",
answers: ["1944", "1945", "1946", "1947"],
correct: 1,
difficulty: 3
}];
// Función para verificar si la imagen existe (para debugging)
function checkImageExists() {
console.log("=== VERIFICANDO IMAGEN ===");
console.log("Texturas disponibles:", Object.keys(LK.textures || {}));
console.log("¿Existe 'Mapa'?", LK.textures && LK.textures['Mapa'] ? "SÍ" : "NO");
try {
var test1 = LK.getAsset('Mapa', {});
console.log("LK.getAsset('Mapa') funciona:", !!test1);
} catch (e) {
console.log("Error con LK.getAsset('Mapa'):", e.message);
}
}
// Initialize background con múltiples métodos
function initializeBackground() {
console.log("Intentando cargar imagen de fondo...");
// MÉTODO 1: Container + attachAsset
try {
backgroundImage = new Container();
game.addChild(backgroundImage);
backgroundImage.attachAsset('Mapa', {
anchorX: 0.5,
anchorY: 0.5
});
// Posicionar en el centro
backgroundImage.x = 1024;
backgroundImage.y = 1366;
// Escalar para cubrir pantalla
backgroundImage.scaleX = 10;
backgroundImage.scaleY = 10;
// Mover al fondo
game.setChildIndex(backgroundImage, 0);
console.log("¡Imagen cargada exitosamente con Container!");
return;
} catch (error) {
console.log("Error con método Container:", error.message);
}
// MÉTODO 2: LK.getAsset directo
try {
backgroundImage = game.addChild(LK.getAsset('Mapa', {
anchorX: 0.5,
anchorY: 0.5
}));
backgroundImage.x = 1024;
backgroundImage.y = 1366;
backgroundImage.scaleX = 10;
backgroundImage.scaleY = 10;
game.setChildIndex(backgroundImage, 0);
console.log("¡Imagen cargada exitosamente con LK.getAsset!");
return;
} catch (error) {
console.log("Error con método LK.getAsset:", error.message);
}
// MÉTODO 3: Sprite directo
try {
backgroundImage = new Sprite(LK.getTexture('Mapa'));
backgroundImage.anchor.set(0.5, 0.5);
backgroundImage.x = 1024;
backgroundImage.y = 1366;
backgroundImage.scale.set(10, 10);
game.addChild(backgroundImage);
game.setChildIndex(backgroundImage, 0);
console.log("¡Imagen cargada exitosamente con Sprite!");
return;
} catch (error) {
console.log("Error con método Sprite:", error.message);
}
console.log("❌ No se pudo cargar la imagen con ningún método");
console.log("Verifica que el ID de la imagen sea correcto: 685f1ffeecde5d1c2c6ebbae");
}
// Initialize path tiles
function initializePath() {
// Create village (start)
var village = game.addChild(new Village());
village.x = 300;
village.y = 2400;
pathTiles.push(village);
// Create path tiles in a winding pattern
var pathPositions = [{
x: 500,
y: 2200
},
// Tile 1
{
x: 700,
y: 2000
},
// Tile 2
{
x: 900,
y: 1800
},
// Tile 3
{
x: 1100,
y: 1600
},
// Tile 4
{
x: 1300,
y: 1400
},
// Tile 5
{
x: 1500,
y: 1200
},
// Tile 6
{
x: 1300,
y: 1000
},
// Tile 7
{
x: 1100,
y: 800
},
// Tile 8
{
x: 1300,
y: 600
} // Tile 9
];
for (var i = 0; i < pathPositions.length; i++) {
var tile = game.addChild(new Tile());
tile.x = pathPositions[i].x;
tile.y = pathPositions[i].y;
pathTiles.push(tile);
}
// Create castle (end)
var castle = game.addChild(new Castle());
castle.x = 1500;
castle.y = 400;
pathTiles.push(castle);
}
// Initialize UI
function initializeUI() {
// Token display
tokenText = new Text2('Tokens: 5', {
size: 80,
fill: 0xFFD700
});
tokenText.anchor.set(0.5, 0);
LK.gui.top.addChild(tokenText);
// Dice
dice = game.addChild(new Dice());
dice.x = 1700;
dice.y = 2400;
// Instructions
var instructionText = new Text2('Tap dice to roll and move!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
}
// Initialize knight
function initializeKnight() {
knight = game.addChild(new Knight());
knight.x = pathTiles[0].x;
knight.y = pathTiles[0].y;
}
// Move knight based on dice roll
function moveKnight() {
var newPosition = knight.currentTile + dice.value;
if (newPosition >= pathTiles.length - 1) {
newPosition = pathTiles.length - 1;
}
knight.moveToTile(newPosition);
}
// Show question
function showQuestion() {
questionActive = true;
// Get question based on difficulty
var difficulty = Math.min(3, Math.floor(knight.currentTile / 3) + 1);
var availableQuestions = questions.filter(function (q) {
return q.difficulty === difficulty;
});
currentQuestion = availableQuestions[Math.floor(Math.random() * availableQuestions.length)];
// Create question container
questionContainer = game.addChild(LK.getAsset('questionBox', {
anchorX: 0.5,
anchorY: 0.5
}));
questionContainer.x = 1024;
questionContainer.y = 1366;
// Question text
var questionText = new Text2(currentQuestion.question, {
size: 70,
fill: 0x000000
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 0;
questionText.y = -150;
questionContainer.addChild(questionText);
// Answer buttons
currentAnswers = [];
for (var i = 0; i < currentQuestion.answers.length; i++) {
var answerButton = game.addChild(new Container());
var buttonGraphics = answerButton.attachAsset('tile', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 0.8
});
answerButton.x = questionContainer.x + (i % 2 * 400 - 200);
answerButton.y = questionContainer.y + (Math.floor(i / 2) * 120 + 50);
answerButton.answerIndex = i;
// Initialize flash properties to prevent errors
buttonGraphics.__colorFlash_current_tick = 0;
buttonGraphics.__colorFlash_total_ticks = 0;
buttonGraphics.__colorFlash_original_tint = 0xFFFFFF;
answerButton.graphics = buttonGraphics;
var answerText = new Text2(currentQuestion.answers[i], {
size: 50,
fill: 0x000000
});
answerText.anchor.set(0.5, 0.5);
answerButton.addChild(answerText);
answerButton.down = function (x, y, obj) {
selectAnswer(obj.answerIndex);
};
currentAnswers.push(answerButton);
}
}
// Handle answer selection
function selectAnswer(answerIndex) {
if (!questionActive) {
return;
}
questionActive = false;
if (answerIndex === currentQuestion.correct) {
// Correct answer
tokens += 5;
LK.getSound('correctAnswer').play();
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0x00FF00, 500);
} else {
// Wrong answer
tokens -= 5;
LK.getSound('wrongAnswer').play();
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0xFF0000, 500);
}
updateTokenDisplay();
// Check game over condition
if (tokens <= 0) {
gameOver = true;
LK.setTimeout(function () {
hideQuestion();
showGameOver();
}, 1000);
} else {
LK.setTimeout(function () {
hideQuestion();
}, 1500);
}
}
// Hide question
function hideQuestion() {
if (questionContainer) {
questionContainer.destroy();
questionContainer = null;
}
// Destroy answer buttons
for (var i = 0; i < currentAnswers.length; i++) {
if (currentAnswers[i]) {
currentAnswers[i].destroy();
}
}
currentAnswers = [];
}
// Update token display
function updateTokenDisplay() {
tokenText.setText('Tokens: ' + tokens);
}
// Show victory
function showVictory() {
LK.showYouWin();
}
// Show game over
function showGameOver() {
LK.showGameOver();
}
// Initialize game
checkImageExists(); // Para debugging
initializeBackground(); // Cargar fondo PRIMERO
initializePath();
initializeUI();
initializeKnight();
// Play background music
LK.playMusic('medievalMusic');
// Game update loop
game.update = function () {
// Game logic handled by events and callbacks
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Castle = Container.expand(function () {
var self = Container.call(this);
var castleGraphics = self.attachAsset('castle', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Dice = Container.expand(function () {
var self = Container.call(this);
var diceGraphics = self.attachAsset('dice', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 1;
self.isRolling = false;
var diceText = new Text2('1', {
size: 60,
fill: 0x000000
});
diceText.anchor.set(0.5, 0.5);
self.addChild(diceText);
self.roll = function () {
if (self.isRolling) {
return;
}
self.isRolling = true;
LK.getSound('diceRoll').play();
var rollCount = 0;
var rollInterval = LK.setInterval(function () {
self.value = Math.floor(Math.random() * 6) + 1;
diceText.setText(self.value.toString());
rollCount++;
if (rollCount >= 10) {
LK.clearInterval(rollInterval);
self.isRolling = false;
moveKnight();
}
}, 100);
};
self.down = function (x, y, obj) {
if (!self.isRolling && !questionActive && !gameOver) {
self.roll();
}
};
return self;
});
var Knight = Container.expand(function () {
var self = Container.call(this);
var knightGraphics = self.attachAsset('knight', {
anchorX: 0.5,
anchorY: 0.5
});
self.currentTile = 0;
self.moveToTile = function (tileIndex) {
if (tileIndex < pathTiles.length) {
self.currentTile = tileIndex;
var targetTile = pathTiles[tileIndex];
tween(self, {
x: targetTile.x,
y: targetTile.y
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (tileIndex > 0 && tileIndex < pathTiles.length - 1) {
showQuestion();
} else if (tileIndex === pathTiles.length - 1) {
showVictory();
}
}
});
}
};
return self;
});
var Tile = Container.expand(function () {
var self = Container.call(this);
var tileGraphics = self.attachAsset('tile', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Village = Container.expand(function () {
var self = Container.call(this);
var villageGraphics = self.attachAsset('village', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
// Declaración simplificada de la imagen
var tokens = 5;
var questionActive = false;
var gameOver = false;
var currentQuestion = null;
var currentAnswers = [];
// Path tiles array
var pathTiles = [];
// Game objects
var knight = null;
var dice = null;
var tokenText = null;
var questionContainer = null;
var backgroundImage = null;
// Question database
var questions = [
// Easy questions (tiles 1-3)
{
question: "What is 2 + 2?",
answers: ["3", "4", "5", "6"],
correct: 1,
difficulty: 1
}, {
question: "What color do you get when you mix red and blue?",
answers: ["Green", "Purple", "Orange", "Yellow"],
correct: 1,
difficulty: 1
}, {
question: "How many days are in a week?",
answers: ["6", "7", "8", "9"],
correct: 1,
difficulty: 1
}, {
question: "What is the opposite of hot?",
answers: ["Warm", "Cool", "Cold", "Freezing"],
correct: 2,
difficulty: 1
},
// Medium questions (tiles 4-6)
{
question: "What is 15 × 3?",
answers: ["43", "45", "47", "49"],
correct: 1,
difficulty: 2
}, {
question: "Which planet is closest to the Sun?",
answers: ["Venus", "Mercury", "Mars", "Earth"],
correct: 1,
difficulty: 2
}, {
question: "What is the capital of France?",
answers: ["London", "Berlin", "Paris", "Rome"],
correct: 2,
difficulty: 2
}, {
question: "How many sides does a triangle have?",
answers: ["2", "3", "4", "5"],
correct: 1,
difficulty: 2
},
// Hard questions (tiles 7-9)
{
question: "What is the square root of 64?",
answers: ["6", "7", "8", "9"],
correct: 2,
difficulty: 3
}, {
question: "Who wrote Romeo and Juliet?",
answers: ["Charles Dickens", "William Shakespeare", "Jane Austen", "Mark Twain"],
correct: 1,
difficulty: 3
}, {
question: "What is the chemical symbol for gold?",
answers: ["Go", "Gd", "Au", "Ag"],
correct: 2,
difficulty: 3
}, {
question: "In which year did World War II end?",
answers: ["1944", "1945", "1946", "1947"],
correct: 1,
difficulty: 3
}];
// Función para verificar si la imagen existe (para debugging)
function checkImageExists() {
console.log("=== VERIFICANDO IMAGEN ===");
console.log("Texturas disponibles:", Object.keys(LK.textures || {}));
console.log("¿Existe 'Mapa'?", LK.textures && LK.textures['Mapa'] ? "SÍ" : "NO");
try {
var test1 = LK.getAsset('Mapa', {});
console.log("LK.getAsset('Mapa') funciona:", !!test1);
} catch (e) {
console.log("Error con LK.getAsset('Mapa'):", e.message);
}
}
// Initialize background con múltiples métodos
function initializeBackground() {
console.log("Intentando cargar imagen de fondo...");
// MÉTODO 1: Container + attachAsset
try {
backgroundImage = new Container();
game.addChild(backgroundImage);
backgroundImage.attachAsset('Mapa', {
anchorX: 0.5,
anchorY: 0.5
});
// Posicionar en el centro
backgroundImage.x = 1024;
backgroundImage.y = 1366;
// Escalar para cubrir pantalla
backgroundImage.scaleX = 10;
backgroundImage.scaleY = 10;
// Mover al fondo
game.setChildIndex(backgroundImage, 0);
console.log("¡Imagen cargada exitosamente con Container!");
return;
} catch (error) {
console.log("Error con método Container:", error.message);
}
// MÉTODO 2: LK.getAsset directo
try {
backgroundImage = game.addChild(LK.getAsset('Mapa', {
anchorX: 0.5,
anchorY: 0.5
}));
backgroundImage.x = 1024;
backgroundImage.y = 1366;
backgroundImage.scaleX = 10;
backgroundImage.scaleY = 10;
game.setChildIndex(backgroundImage, 0);
console.log("¡Imagen cargada exitosamente con LK.getAsset!");
return;
} catch (error) {
console.log("Error con método LK.getAsset:", error.message);
}
// MÉTODO 3: Sprite directo
try {
backgroundImage = new Sprite(LK.getTexture('Mapa'));
backgroundImage.anchor.set(0.5, 0.5);
backgroundImage.x = 1024;
backgroundImage.y = 1366;
backgroundImage.scale.set(10, 10);
game.addChild(backgroundImage);
game.setChildIndex(backgroundImage, 0);
console.log("¡Imagen cargada exitosamente con Sprite!");
return;
} catch (error) {
console.log("Error con método Sprite:", error.message);
}
console.log("❌ No se pudo cargar la imagen con ningún método");
console.log("Verifica que el ID de la imagen sea correcto: 685f1ffeecde5d1c2c6ebbae");
}
// Initialize path tiles
function initializePath() {
// Create village (start)
var village = game.addChild(new Village());
village.x = 300;
village.y = 2400;
pathTiles.push(village);
// Create path tiles in a winding pattern
var pathPositions = [{
x: 500,
y: 2200
},
// Tile 1
{
x: 700,
y: 2000
},
// Tile 2
{
x: 900,
y: 1800
},
// Tile 3
{
x: 1100,
y: 1600
},
// Tile 4
{
x: 1300,
y: 1400
},
// Tile 5
{
x: 1500,
y: 1200
},
// Tile 6
{
x: 1300,
y: 1000
},
// Tile 7
{
x: 1100,
y: 800
},
// Tile 8
{
x: 1300,
y: 600
} // Tile 9
];
for (var i = 0; i < pathPositions.length; i++) {
var tile = game.addChild(new Tile());
tile.x = pathPositions[i].x;
tile.y = pathPositions[i].y;
pathTiles.push(tile);
}
// Create castle (end)
var castle = game.addChild(new Castle());
castle.x = 1500;
castle.y = 400;
pathTiles.push(castle);
}
// Initialize UI
function initializeUI() {
// Token display
tokenText = new Text2('Tokens: 5', {
size: 80,
fill: 0xFFD700
});
tokenText.anchor.set(0.5, 0);
LK.gui.top.addChild(tokenText);
// Dice
dice = game.addChild(new Dice());
dice.x = 1700;
dice.y = 2400;
// Instructions
var instructionText = new Text2('Tap dice to roll and move!', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
}
// Initialize knight
function initializeKnight() {
knight = game.addChild(new Knight());
knight.x = pathTiles[0].x;
knight.y = pathTiles[0].y;
}
// Move knight based on dice roll
function moveKnight() {
var newPosition = knight.currentTile + dice.value;
if (newPosition >= pathTiles.length - 1) {
newPosition = pathTiles.length - 1;
}
knight.moveToTile(newPosition);
}
// Show question
function showQuestion() {
questionActive = true;
// Get question based on difficulty
var difficulty = Math.min(3, Math.floor(knight.currentTile / 3) + 1);
var availableQuestions = questions.filter(function (q) {
return q.difficulty === difficulty;
});
currentQuestion = availableQuestions[Math.floor(Math.random() * availableQuestions.length)];
// Create question container
questionContainer = game.addChild(LK.getAsset('questionBox', {
anchorX: 0.5,
anchorY: 0.5
}));
questionContainer.x = 1024;
questionContainer.y = 1366;
// Question text
var questionText = new Text2(currentQuestion.question, {
size: 70,
fill: 0x000000
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 0;
questionText.y = -150;
questionContainer.addChild(questionText);
// Answer buttons
currentAnswers = [];
for (var i = 0; i < currentQuestion.answers.length; i++) {
var answerButton = game.addChild(new Container());
var buttonGraphics = answerButton.attachAsset('tile', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 0.8
});
answerButton.x = questionContainer.x + (i % 2 * 400 - 200);
answerButton.y = questionContainer.y + (Math.floor(i / 2) * 120 + 50);
answerButton.answerIndex = i;
// Initialize flash properties to prevent errors
buttonGraphics.__colorFlash_current_tick = 0;
buttonGraphics.__colorFlash_total_ticks = 0;
buttonGraphics.__colorFlash_original_tint = 0xFFFFFF;
answerButton.graphics = buttonGraphics;
var answerText = new Text2(currentQuestion.answers[i], {
size: 50,
fill: 0x000000
});
answerText.anchor.set(0.5, 0.5);
answerButton.addChild(answerText);
answerButton.down = function (x, y, obj) {
selectAnswer(obj.answerIndex);
};
currentAnswers.push(answerButton);
}
}
// Handle answer selection
function selectAnswer(answerIndex) {
if (!questionActive) {
return;
}
questionActive = false;
if (answerIndex === currentQuestion.correct) {
// Correct answer
tokens += 5;
LK.getSound('correctAnswer').play();
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0x00FF00, 500);
} else {
// Wrong answer
tokens -= 5;
LK.getSound('wrongAnswer').play();
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0xFF0000, 500);
}
updateTokenDisplay();
// Check game over condition
if (tokens <= 0) {
gameOver = true;
LK.setTimeout(function () {
hideQuestion();
showGameOver();
}, 1000);
} else {
LK.setTimeout(function () {
hideQuestion();
}, 1500);
}
}
// Hide question
function hideQuestion() {
if (questionContainer) {
questionContainer.destroy();
questionContainer = null;
}
// Destroy answer buttons
for (var i = 0; i < currentAnswers.length; i++) {
if (currentAnswers[i]) {
currentAnswers[i].destroy();
}
}
currentAnswers = [];
}
// Update token display
function updateTokenDisplay() {
tokenText.setText('Tokens: ' + tokens);
}
// Show victory
function showVictory() {
LK.showYouWin();
}
// Show game over
function showGameOver() {
LK.showGameOver();
}
// Initialize game
checkImageExists(); // Para debugging
initializeBackground(); // Cargar fondo PRIMERO
initializePath();
initializeUI();
initializeKnight();
// Play background music
LK.playMusic('medievalMusic');
// Game update loop
game.update = function () {
// Game logic handled by events and callbacks
};