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 && canRollDice) {
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
var tokens = 5;
var questionActive = false;
var gameOver = false;
var currentQuestion = null;
var currentAnswers = [];
var canRollDice = true;
// Path tiles array
var pathTiles = [];
// Game objects
var knight = null;
var dice = null;
var tokenText = null;
var questionContainer = null;
var backgroundImage = null;
// Question database with correct indexing (0-based)
var questions = [
// Easy questions (tiles 1-3) - difficulty 1
{
question: "What is 2 + 2?",
answers: ["3", "4", "5", "6"],
correct: 1,
// "4" is at index 1
difficulty: 1
}, {
question: "What color is the sun?",
answers: ["Yellow", "Blue", "Red", "Green"],
correct: 0,
// "Yellow" is at index 0
difficulty: 1
}, {
question: "How many fingers do you have on one hand?",
answers: ["5", "4", "6", "7"],
correct: 0,
// "5" is at index 0
difficulty: 1
}, {
question: "What sound does a cat make?",
answers: ["Woof", "Meow", "Moo", "Oink"],
correct: 1,
// "Meow" is at index 1
difficulty: 1
}, {
question: "What is the first letter of the alphabet?",
answers: ["A", "B", "C", "D"],
correct: 0,
// "A" is at index 0
difficulty: 1
}, {
question: "What do you use to write?",
answers: ["Pen", "Fork", "Spoon", "Hammer"],
correct: 0,
// "Pen" is at index 0
difficulty: 1
}, {
question: "What is 3 + 2?",
answers: ["4", "5", "6", "7"],
correct: 1,
// "5" is at index 1
difficulty: 1
}, {
question: "What animal goes 'woof'?",
answers: ["Cat", "Dog", "Cow", "Bird"],
correct: 1,
// "Dog" is at index 1
difficulty: 1
}, {
question: "What color is grass?",
answers: ["Green", "Red", "Blue", "Yellow"],
correct: 0,
// "Green" is at index 0
difficulty: 1
}, {
question: "How many eyes do you have?",
answers: ["1", "2", "3", "4"],
correct: 1,
// "2" is at index 1
difficulty: 1
},
// Medium questions (tiles 4-6) - difficulty 2
{
question: "What is 7 × 8?",
answers: ["54", "56", "58", "60"],
correct: 1,
// "56" is at index 1
difficulty: 2
}, {
question: "What is the capital of Spain?",
answers: ["Barcelona", "Madrid", "Seville", "Valencia"],
correct: 1,
// "Madrid" is at index 1
difficulty: 2
}, {
question: "How many months have 31 days?",
answers: ["6", "7", "8", "9"],
correct: 1,
// "7" is at index 1
difficulty: 2
}, {
question: "What is 100 ÷ 4?",
answers: ["24", "25", "26", "27"],
correct: 1,
// "25" is at index 1
difficulty: 2
}, {
question: "Which continent is Brazil in?",
answers: ["Europe", "South America", "Africa", "Asia"],
correct: 1,
// "South America" is at index 1
difficulty: 2
}, {
question: "What is the square of 9?",
answers: ["81", "79", "83", "85"],
correct: 0,
// "81" is at index 0
difficulty: 2
}, {
question: "How many seconds are in a minute?",
answers: ["50", "60", "70", "80"],
correct: 1,
// "60" is at index 1
difficulty: 2
}, {
question: "What is the freezing point of water in Celsius?",
answers: ["32", "0", "-10", "10"],
correct: 1,
// "0" is at index 1
difficulty: 2
}, {
question: "Which ocean is the largest?",
answers: ["Atlantic", "Pacific", "Indian", "Arctic"],
correct: 1,
// "Pacific" is at index 1
difficulty: 2
}, {
question: "What is 13 + 29?",
answers: ["41", "42", "43", "44"],
correct: 1,
// "42" is at index 1
difficulty: 2
},
// Hard questions (tiles 7-9) - difficulty 3
{
question: "What is the cube root of 27?",
answers: ["2", "3", "4", "5"],
correct: 1,
// "3" is at index 1
difficulty: 3
}, {
question: "Who invented the telephone?",
answers: ["Thomas Edison", "Alexander Graham Bell", "Nikola Tesla", "Albert Einstein"],
correct: 1,
// "Alexander Graham Bell" is at index 1
difficulty: 3
}, {
question: "What is the chemical formula for methane?",
answers: ["CO2", "CH4", "H2O", "NH3"],
correct: 1,
// "CH4" is at index 1
difficulty: 3
}, {
question: "In which year was the internet invented?",
answers: ["1967", "1969", "1971", "1973"],
correct: 1,
// "1969" is at index 1
difficulty: 3
}, {
question: "What is the smallest country in the world?",
answers: ["Vatican City", "Monaco", "San Marino", "Liechtenstein"],
correct: 0,
// "Vatican City" is at index 0
difficulty: 3
}, {
question: "Who wrote '1984'?",
answers: ["Aldous Huxley", "George Orwell", "Ray Bradbury", "H.G. Wells"],
correct: 1,
// "George Orwell" is at index 1
difficulty: 3
}, {
question: "What is the speed of light?",
answers: ["299,792,458 m/s", "300,000,000 m/s", "299,000,000 m/s", "301,000,000 m/s"],
correct: 0,
// "299,792,458 m/s" is at index 0
difficulty: 3
}, {
question: "What is 17 × 23?",
answers: ["390", "391", "392", "393"],
correct: 1,
// "391" is at index 1
difficulty: 3
}, {
question: "Which element has atomic number 79?",
answers: ["Silver", "Gold", "Platinum", "Copper"],
correct: 1,
// "Gold" is at index 1
difficulty: 3
}, {
question: "What is the capital of Kazakhstan?",
answers: ["Almaty", "Astana", "Shymkent", "Aktobe"],
correct: 1,
// "Astana" is at index 1
difficulty: 3
}];
// Initialize background
function initializeBackground() {
try {
backgroundImage = new Container();
game.addChild(backgroundImage);
backgroundImage.attachAsset('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("Background loaded successfully!");
} catch (error) {
console.log("Could not load background image:", error.message);
}
}
// 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;
canRollDice = false;
// 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)];
console.log("Selected question:", currentQuestion.question);
console.log("Correct answer index:", currentQuestion.correct);
console.log("Correct answer:", currentQuestion.answers[currentQuestion.correct]);
// 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;
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;
console.log("Answer selected:", answerIndex);
console.log("Correct answer:", currentQuestion.correct);
console.log("Selected answer text:", currentQuestion.answers[answerIndex]);
console.log("Correct answer text:", currentQuestion.answers[currentQuestion.correct]);
if (answerIndex === currentQuestion.correct) {
// Correct answer
console.log("CORRECT ANSWER!");
tokens += 5;
LK.getSound('correctAnswer').play();
if (currentAnswers[answerIndex] && currentAnswers[answerIndex].graphics) {
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0x00FF00, 500);
}
updateTokenDisplay();
// Hide question and allow another dice roll
LK.setTimeout(function () {
hideQuestion();
canRollDice = true; // Allow dice rolling again
dice.isRolling = false;
}, 1500);
} else {
// Wrong answer
console.log("WRONG ANSWER!");
tokens -= 5;
LK.getSound('wrongAnswer').play();
if (currentAnswers[answerIndex] && currentAnswers[answerIndex].graphics) {
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();
canRollDice = true; // Allow dice rolling again
}, 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[i] = null;
}
}
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
initializeBackground();
initializePath();
initializeUI();
initializeKnight();
// Play background music
LK.playMusic('medievalMusic');
// Game update loop
game.update = function () {
// Game logic handled by events and callbacks
}; ===================================================================
--- original.js
+++ change.js
@@ -47,9 +47,9 @@
}
}, 100);
};
self.down = function (x, y, obj) {
- if (!self.isRolling && !questionActive && !gameOver) {
+ if (!self.isRolling && !questionActive && !gameOver && canRollDice) {
self.roll();
}
};
return self;
@@ -109,269 +109,229 @@
/****
* Game Code
****/
-// Declaración simplificada de la imagen
// Game state variables
var tokens = 5;
var questionActive = false;
var gameOver = false;
var currentQuestion = null;
var currentAnswers = [];
+var canRollDice = true;
// Path tiles array
var pathTiles = [];
// Game objects
var knight = null;
var dice = null;
var tokenText = null;
var questionContainer = null;
var backgroundImage = null;
-// Question database - completely rebuilt with proper indexing
+// Question database with correct indexing (0-based)
var questions = [
// Easy questions (tiles 1-3) - difficulty 1
{
- question: "What is 1 + 1?",
- answers: ["1", "2", "3", "4"],
+ question: "What is 2 + 2?",
+ answers: ["3", "4", "5", "6"],
correct: 1,
+ // "4" is at index 1
difficulty: 1
}, {
question: "What color is the sun?",
- answers: ["Blue", "Yellow", "Red", "Green"],
- correct: 1,
+ answers: ["Yellow", "Blue", "Red", "Green"],
+ correct: 0,
+ // "Yellow" is at index 0
difficulty: 1
}, {
question: "How many fingers do you have on one hand?",
- answers: ["4", "5", "6", "7"],
- correct: 1,
+ answers: ["5", "4", "6", "7"],
+ correct: 0,
+ // "5" is at index 0
difficulty: 1
}, {
question: "What sound does a cat make?",
answers: ["Woof", "Meow", "Moo", "Oink"],
correct: 1,
+ // "Meow" is at index 1
difficulty: 1
}, {
question: "What is the first letter of the alphabet?",
- answers: ["B", "A", "C", "D"],
- correct: 1,
+ answers: ["A", "B", "C", "D"],
+ correct: 0,
+ // "A" is at index 0
difficulty: 1
}, {
question: "What do you use to write?",
- answers: ["Fork", "Pen", "Spoon", "Hammer"],
- correct: 1,
+ answers: ["Pen", "Fork", "Spoon", "Hammer"],
+ correct: 0,
+ // "Pen" is at index 0
difficulty: 1
}, {
question: "What is 3 + 2?",
answers: ["4", "5", "6", "7"],
correct: 1,
+ // "5" is at index 1
difficulty: 1
}, {
question: "What animal goes 'woof'?",
answers: ["Cat", "Dog", "Cow", "Bird"],
correct: 1,
+ // "Dog" is at index 1
difficulty: 1
}, {
question: "What color is grass?",
- answers: ["Red", "Green", "Blue", "Yellow"],
- correct: 1,
+ answers: ["Green", "Red", "Blue", "Yellow"],
+ correct: 0,
+ // "Green" is at index 0
difficulty: 1
}, {
question: "How many eyes do you have?",
answers: ["1", "2", "3", "4"],
correct: 1,
+ // "2" is at index 1
difficulty: 1
},
// Medium questions (tiles 4-6) - difficulty 2
{
question: "What is 7 × 8?",
answers: ["54", "56", "58", "60"],
correct: 1,
+ // "56" is at index 1
difficulty: 2
}, {
question: "What is the capital of Spain?",
answers: ["Barcelona", "Madrid", "Seville", "Valencia"],
correct: 1,
+ // "Madrid" is at index 1
difficulty: 2
}, {
question: "How many months have 31 days?",
answers: ["6", "7", "8", "9"],
correct: 1,
+ // "7" is at index 1
difficulty: 2
}, {
question: "What is 100 ÷ 4?",
answers: ["24", "25", "26", "27"],
correct: 1,
+ // "25" is at index 1
difficulty: 2
}, {
question: "Which continent is Brazil in?",
answers: ["Europe", "South America", "Africa", "Asia"],
correct: 1,
+ // "South America" is at index 1
difficulty: 2
}, {
question: "What is the square of 9?",
- answers: ["79", "81", "83", "85"],
- correct: 1,
+ answers: ["81", "79", "83", "85"],
+ correct: 0,
+ // "81" is at index 0
difficulty: 2
}, {
question: "How many seconds are in a minute?",
answers: ["50", "60", "70", "80"],
correct: 1,
+ // "60" is at index 1
difficulty: 2
}, {
question: "What is the freezing point of water in Celsius?",
answers: ["32", "0", "-10", "10"],
correct: 1,
+ // "0" is at index 1
difficulty: 2
}, {
question: "Which ocean is the largest?",
answers: ["Atlantic", "Pacific", "Indian", "Arctic"],
correct: 1,
+ // "Pacific" is at index 1
difficulty: 2
}, {
question: "What is 13 + 29?",
answers: ["41", "42", "43", "44"],
correct: 1,
+ // "42" is at index 1
difficulty: 2
},
// Hard questions (tiles 7-9) - difficulty 3
{
question: "What is the cube root of 27?",
answers: ["2", "3", "4", "5"],
correct: 1,
+ // "3" is at index 1
difficulty: 3
}, {
question: "Who invented the telephone?",
answers: ["Thomas Edison", "Alexander Graham Bell", "Nikola Tesla", "Albert Einstein"],
correct: 1,
+ // "Alexander Graham Bell" is at index 1
difficulty: 3
}, {
question: "What is the chemical formula for methane?",
answers: ["CO2", "CH4", "H2O", "NH3"],
correct: 1,
+ // "CH4" is at index 1
difficulty: 3
}, {
question: "In which year was the internet invented?",
answers: ["1967", "1969", "1971", "1973"],
correct: 1,
+ // "1969" is at index 1
difficulty: 3
}, {
question: "What is the smallest country in the world?",
- answers: ["Monaco", "Vatican City", "San Marino", "Liechtenstein"],
- correct: 1,
+ answers: ["Vatican City", "Monaco", "San Marino", "Liechtenstein"],
+ correct: 0,
+ // "Vatican City" is at index 0
difficulty: 3
}, {
question: "Who wrote '1984'?",
answers: ["Aldous Huxley", "George Orwell", "Ray Bradbury", "H.G. Wells"],
correct: 1,
+ // "George Orwell" is at index 1
difficulty: 3
}, {
question: "What is the speed of light?",
answers: ["299,792,458 m/s", "300,000,000 m/s", "299,000,000 m/s", "301,000,000 m/s"],
correct: 0,
+ // "299,792,458 m/s" is at index 0
difficulty: 3
}, {
question: "What is 17 × 23?",
answers: ["390", "391", "392", "393"],
correct: 1,
+ // "391" is at index 1
difficulty: 3
}, {
question: "Which element has atomic number 79?",
answers: ["Silver", "Gold", "Platinum", "Copper"],
correct: 1,
+ // "Gold" is at index 1
difficulty: 3
}, {
question: "What is the capital of Kazakhstan?",
answers: ["Almaty", "Astana", "Shymkent", "Aktobe"],
correct: 1,
+ // "Astana" is at index 1
difficulty: 3
-}, {
- question: "In what year did the Berlin Wall fall?",
- answers: ["1987", "1989", "1991", "1993"],
- correct: 1,
- difficulty: 3
-}, {
- question: "What is the largest prime number less than 100?",
- answers: ["96", "97", "98", "99"],
- correct: 1,
- difficulty: 3
-}, {
- question: "Who discovered penicillin?",
- answers: ["Louis Pasteur", "Alexander Fleming", "Marie Curie", "Jonas Salk"],
- correct: 1,
- difficulty: 3
-}, {
- question: "What is the deepest ocean trench?",
- answers: ["Puerto Rico Trench", "Mariana Trench", "Japan Trench", "Peru-Chile Trench"],
- 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
+// Initialize background
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;
+ console.log("Background loaded successfully!");
} catch (error) {
- console.log("Error con método Container:", error.message);
+ console.log("Could not load background image:", 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)
@@ -474,14 +434,18 @@
}
// Show question
function showQuestion() {
questionActive = true;
+ canRollDice = false;
// 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)];
+ console.log("Selected question:", currentQuestion.question);
+ console.log("Correct answer index:", currentQuestion.correct);
+ console.log("Correct answer:", currentQuestion.answers[currentQuestion.correct]);
// Create question container
questionContainer = game.addChild(LK.getAsset('questionBox', {
anchorX: 0.5,
anchorY: 0.5
@@ -509,14 +473,9 @@
});
answerButton.x = questionContainer.x + (i % 2 * 400 - 200);
answerButton.y = questionContainer.y + (Math.floor(i / 2) * 120 + 50);
answerButton.answerIndex = i;
- // Store reference to graphics for flashing
answerButton.graphics = buttonGraphics;
- // Initialize flash properties to prevent errors
- buttonGraphics.__colorFlash_current_tick = 0;
- buttonGraphics.__colorFlash_total_ticks = 0;
- buttonGraphics.__colorFlash_original_tint = 0xFFFFFF;
var answerText = new Text2(currentQuestion.answers[i], {
size: 50,
fill: 0x000000
});
@@ -533,10 +492,15 @@
if (!questionActive) {
return;
}
questionActive = false;
+ console.log("Answer selected:", answerIndex);
+ console.log("Correct answer:", currentQuestion.correct);
+ console.log("Selected answer text:", currentQuestion.answers[answerIndex]);
+ console.log("Correct answer text:", currentQuestion.answers[currentQuestion.correct]);
if (answerIndex === currentQuestion.correct) {
// Correct answer
+ console.log("CORRECT ANSWER!");
tokens += 5;
LK.getSound('correctAnswer').play();
if (currentAnswers[answerIndex] && currentAnswers[answerIndex].graphics) {
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0x00FF00, 500);
@@ -544,13 +508,14 @@
updateTokenDisplay();
// Hide question and allow another dice roll
LK.setTimeout(function () {
hideQuestion();
- // Reset dice to allow another roll without moving knight
+ canRollDice = true; // Allow dice rolling again
dice.isRolling = false;
}, 1500);
} else {
// Wrong answer
+ console.log("WRONG ANSWER!");
tokens -= 5;
LK.getSound('wrongAnswer').play();
if (currentAnswers[answerIndex] && currentAnswers[answerIndex].graphics) {
LK.effects.flashObject(currentAnswers[answerIndex].graphics, 0xFF0000, 500);
@@ -565,8 +530,9 @@
}, 1000);
} else {
LK.setTimeout(function () {
hideQuestion();
+ canRollDice = true; // Allow dice rolling again
}, 1500);
}
}
}
@@ -597,10 +563,9 @@
function showGameOver() {
LK.showGameOver();
}
// Initialize game
-checkImageExists(); // Para debugging
-initializeBackground(); // Cargar fondo PRIMERO
+initializeBackground();
initializePath();
initializeUI();
initializeKnight();
// Play background music