/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var AnswerButton = Container.expand(function (text, isCorrect, onAnswer) {
var self = Container.call(this);
self.isCorrect = isCorrect;
self.onAnswer = onAnswer;
self.answered = false;
var buttonBg = self.attachAsset('answerButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 48,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setText = function (newText) {
buttonText.setText(newText);
};
self.setCorrect = function () {
self.removeChild(buttonBg);
buttonBg = self.attachAsset('correctButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
};
self.setIncorrect = function () {
self.removeChild(buttonBg);
buttonBg = self.attachAsset('incorrectButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
};
self.reset = function () {
self.answered = false;
self.removeChild(buttonBg);
buttonBg = self.attachAsset('answerButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
};
self.down = function (x, y, obj) {
if (!self.answered && self.onAnswer) {
self.onAnswer(self.isCorrect, self);
}
};
return self;
});
var Flag = Container.expand(function (countryData) {
var self = Container.call(this);
self.countryData = countryData;
var flagBg = self.attachAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0.5
});
// Create flag pattern based on country data
self.createFlagPattern = function () {
var pattern = self.countryData.pattern;
var colors = self.countryData.colors;
if (pattern === 'horizontal') {
var stripeHeight = 300 / colors.length;
for (var i = 0; i < colors.length; i++) {
var stripe = LK.getAsset('flagBackground', {
anchorX: 0.5,
anchorY: 0,
scaleY: stripeHeight / 300
});
stripe.tint = colors[i];
stripe.y = -150 + i * stripeHeight;
self.addChild(stripe);
}
} else if (pattern === 'vertical') {
var stripeWidth = 400 / colors.length;
for (var i = 0; i < colors.length; i++) {
var stripe = LK.getAsset('flagBackground', {
anchorX: 0,
anchorY: 0.5,
scaleX: stripeWidth / 400
});
stripe.tint = colors[i];
stripe.x = -200 + i * stripeWidth;
self.addChild(stripe);
}
} else if (pattern === 'solid') {
flagBg.tint = colors[0];
}
};
self.createFlagPattern();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Flag data - simplified flag patterns
var flagData = [{
name: 'France',
pattern: 'vertical',
colors: [0x0055a4, 0xffffff, 0xef4135]
}, {
name: 'Germany',
pattern: 'horizontal',
colors: [0x000000, 0xdd0000, 0xffce00]
}, {
name: 'Italy',
pattern: 'vertical',
colors: [0x009246, 0xffffff, 0xce2b37]
}, {
name: 'Spain',
pattern: 'horizontal',
colors: [0xaa151b, 0xf1bf00, 0xaa151b]
}, {
name: 'Netherlands',
pattern: 'horizontal',
colors: [0xae1c28, 0xffffff, 0x21468b]
}, {
name: 'Belgium',
pattern: 'vertical',
colors: [0x000000, 0xffd700, 0xed2939]
}, {
name: 'Poland',
pattern: 'horizontal',
colors: [0xffffff, 0xdc143c]
}, {
name: 'Ukraine',
pattern: 'horizontal',
colors: [0x005bbb, 0xffd700]
}, {
name: 'Ireland',
pattern: 'vertical',
colors: [0x169b62, 0xffffff, 0xff883e]
}, {
name: 'Austria',
pattern: 'horizontal',
colors: [0xed2939, 0xffffff, 0xed2939]
}, {
name: 'Hungary',
pattern: 'horizontal',
colors: [0xcd212a, 0xffffff, 0x436f4d]
}, {
name: 'Romania',
pattern: 'vertical',
colors: [0x002b7f, 0xfcd116, 0xce1126]
}, {
name: 'Bulgaria',
pattern: 'horizontal',
colors: [0xffffff, 0x00966e, 0xd62612]
}, {
name: 'Lithuania',
pattern: 'horizontal',
colors: [0xfdb462, 0x006a44, 0xc1272d]
}, {
name: 'Latvia',
pattern: 'horizontal',
colors: [0x9e3039, 0xffffff, 0x9e3039]
}, {
name: 'Estonia',
pattern: 'horizontal',
colors: [0x0072ce, 0x000000, 0xffffff]
}, {
name: 'Finland',
pattern: 'solid',
colors: [0xffffff]
}, {
name: 'Sweden',
pattern: 'solid',
colors: [0x006aa7]
}, {
name: 'Norway',
pattern: 'solid',
colors: [0xef2b2d]
}, {
name: 'Denmark',
pattern: 'solid',
colors: [0xc8102e]
}];
var currentFlag = null;
var answerButtons = [];
var correctAnswer = '';
var gameActive = true;
var nextQuestionTimer = null;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 100;
var questionText = new Text2('Which country does this flag belong to?', {
size: 48,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 1024;
questionText.y = 600;
game.addChild(questionText);
// Initialize answer buttons
for (var i = 0; i < 4; i++) {
var button = new AnswerButton('', false, handleAnswer);
button.x = 1024;
button.y = 800 + i * 150;
answerButtons.push(button);
game.addChild(button);
}
function getRandomCountries(correctCountry, count) {
var countries = [];
countries.push(correctCountry);
var availableCountries = flagData.filter(function (country) {
return country.name !== correctCountry.name;
});
while (countries.length < count && availableCountries.length > 0) {
var randomIndex = Math.floor(Math.random() * availableCountries.length);
countries.push(availableCountries[randomIndex]);
availableCountries.splice(randomIndex, 1);
}
return countries;
}
function shuffleArray(array) {
var shuffled = array.slice();
for (var i = shuffled.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled;
}
function generateNewQuestion() {
gameActive = true;
// Clear previous flag
if (currentFlag) {
currentFlag.destroy();
}
// Select random correct answer
var correctCountry = flagData[Math.floor(Math.random() * flagData.length)];
correctAnswer = correctCountry.name;
// Create flag
currentFlag = new Flag(correctCountry);
currentFlag.x = 1024;
currentFlag.y = 400;
game.addChild(currentFlag);
// Get 4 random countries including the correct one
var countries = getRandomCountries(correctCountry, 4);
var shuffledCountries = shuffleArray(countries);
// Set up answer buttons
for (var i = 0; i < answerButtons.length; i++) {
var button = answerButtons[i];
var country = shuffledCountries[i];
button.setText(country.name);
button.isCorrect = country.name === correctAnswer;
button.reset();
}
}
function handleAnswer(isCorrect, button) {
if (!gameActive) return;
gameActive = false;
button.answered = true;
// Mark all buttons as answered to prevent further clicks
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].answered = true;
}
if (isCorrect) {
button.setCorrect();
LK.setScore(LK.getScore() + 1);
scoreText.setText('Score: ' + LK.getScore());
LK.getSound('correct').play();
// Flash screen green briefly
LK.effects.flashScreen(0x7ed321, 300);
} else {
button.setIncorrect();
LK.getSound('incorrect').play();
// Show correct answer
for (var i = 0; i < answerButtons.length; i++) {
if (answerButtons[i].isCorrect) {
answerButtons[i].setCorrect();
break;
}
}
// Flash screen red briefly
LK.effects.flashScreen(0xd0021b, 300);
}
// Schedule next question
nextQuestionTimer = LK.setTimeout(function () {
generateNewQuestion();
}, 2000);
}
// Start first question
generateNewQuestion();
game.update = function () {
// Update score display
scoreText.setText('Score: ' + LK.getScore());
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,310 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var AnswerButton = Container.expand(function (text, isCorrect, onAnswer) {
+ var self = Container.call(this);
+ self.isCorrect = isCorrect;
+ self.onAnswer = onAnswer;
+ self.answered = false;
+ var buttonBg = self.attachAsset('answerButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(text, {
+ size: 48,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.setText = function (newText) {
+ buttonText.setText(newText);
+ };
+ self.setCorrect = function () {
+ self.removeChild(buttonBg);
+ buttonBg = self.attachAsset('correctButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChildAt(buttonBg, 0);
+ };
+ self.setIncorrect = function () {
+ self.removeChild(buttonBg);
+ buttonBg = self.attachAsset('incorrectButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChildAt(buttonBg, 0);
+ };
+ self.reset = function () {
+ self.answered = false;
+ self.removeChild(buttonBg);
+ buttonBg = self.attachAsset('answerButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChildAt(buttonBg, 0);
+ };
+ self.down = function (x, y, obj) {
+ if (!self.answered && self.onAnswer) {
+ self.onAnswer(self.isCorrect, self);
+ }
+ };
+ return self;
+});
+var Flag = Container.expand(function (countryData) {
+ var self = Container.call(this);
+ self.countryData = countryData;
+ var flagBg = self.attachAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create flag pattern based on country data
+ self.createFlagPattern = function () {
+ var pattern = self.countryData.pattern;
+ var colors = self.countryData.colors;
+ if (pattern === 'horizontal') {
+ var stripeHeight = 300 / colors.length;
+ for (var i = 0; i < colors.length; i++) {
+ var stripe = LK.getAsset('flagBackground', {
+ anchorX: 0.5,
+ anchorY: 0,
+ scaleY: stripeHeight / 300
+ });
+ stripe.tint = colors[i];
+ stripe.y = -150 + i * stripeHeight;
+ self.addChild(stripe);
+ }
+ } else if (pattern === 'vertical') {
+ var stripeWidth = 400 / colors.length;
+ for (var i = 0; i < colors.length; i++) {
+ var stripe = LK.getAsset('flagBackground', {
+ anchorX: 0,
+ anchorY: 0.5,
+ scaleX: stripeWidth / 400
+ });
+ stripe.tint = colors[i];
+ stripe.x = -200 + i * stripeWidth;
+ self.addChild(stripe);
+ }
+ } else if (pattern === 'solid') {
+ flagBg.tint = colors[0];
+ }
+ };
+ self.createFlagPattern();
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+// Flag data - simplified flag patterns
+var flagData = [{
+ name: 'France',
+ pattern: 'vertical',
+ colors: [0x0055a4, 0xffffff, 0xef4135]
+}, {
+ name: 'Germany',
+ pattern: 'horizontal',
+ colors: [0x000000, 0xdd0000, 0xffce00]
+}, {
+ name: 'Italy',
+ pattern: 'vertical',
+ colors: [0x009246, 0xffffff, 0xce2b37]
+}, {
+ name: 'Spain',
+ pattern: 'horizontal',
+ colors: [0xaa151b, 0xf1bf00, 0xaa151b]
+}, {
+ name: 'Netherlands',
+ pattern: 'horizontal',
+ colors: [0xae1c28, 0xffffff, 0x21468b]
+}, {
+ name: 'Belgium',
+ pattern: 'vertical',
+ colors: [0x000000, 0xffd700, 0xed2939]
+}, {
+ name: 'Poland',
+ pattern: 'horizontal',
+ colors: [0xffffff, 0xdc143c]
+}, {
+ name: 'Ukraine',
+ pattern: 'horizontal',
+ colors: [0x005bbb, 0xffd700]
+}, {
+ name: 'Ireland',
+ pattern: 'vertical',
+ colors: [0x169b62, 0xffffff, 0xff883e]
+}, {
+ name: 'Austria',
+ pattern: 'horizontal',
+ colors: [0xed2939, 0xffffff, 0xed2939]
+}, {
+ name: 'Hungary',
+ pattern: 'horizontal',
+ colors: [0xcd212a, 0xffffff, 0x436f4d]
+}, {
+ name: 'Romania',
+ pattern: 'vertical',
+ colors: [0x002b7f, 0xfcd116, 0xce1126]
+}, {
+ name: 'Bulgaria',
+ pattern: 'horizontal',
+ colors: [0xffffff, 0x00966e, 0xd62612]
+}, {
+ name: 'Lithuania',
+ pattern: 'horizontal',
+ colors: [0xfdb462, 0x006a44, 0xc1272d]
+}, {
+ name: 'Latvia',
+ pattern: 'horizontal',
+ colors: [0x9e3039, 0xffffff, 0x9e3039]
+}, {
+ name: 'Estonia',
+ pattern: 'horizontal',
+ colors: [0x0072ce, 0x000000, 0xffffff]
+}, {
+ name: 'Finland',
+ pattern: 'solid',
+ colors: [0xffffff]
+}, {
+ name: 'Sweden',
+ pattern: 'solid',
+ colors: [0x006aa7]
+}, {
+ name: 'Norway',
+ pattern: 'solid',
+ colors: [0xef2b2d]
+}, {
+ name: 'Denmark',
+ pattern: 'solid',
+ colors: [0xc8102e]
+}];
+var currentFlag = null;
+var answerButtons = [];
+var correctAnswer = '';
+var gameActive = true;
+var nextQuestionTimer = null;
+// UI Elements
+var scoreText = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 100;
+var questionText = new Text2('Which country does this flag belong to?', {
+ size: 48,
+ fill: 0xFFFFFF
+});
+questionText.anchor.set(0.5, 0.5);
+questionText.x = 1024;
+questionText.y = 600;
+game.addChild(questionText);
+// Initialize answer buttons
+for (var i = 0; i < 4; i++) {
+ var button = new AnswerButton('', false, handleAnswer);
+ button.x = 1024;
+ button.y = 800 + i * 150;
+ answerButtons.push(button);
+ game.addChild(button);
+}
+function getRandomCountries(correctCountry, count) {
+ var countries = [];
+ countries.push(correctCountry);
+ var availableCountries = flagData.filter(function (country) {
+ return country.name !== correctCountry.name;
+ });
+ while (countries.length < count && availableCountries.length > 0) {
+ var randomIndex = Math.floor(Math.random() * availableCountries.length);
+ countries.push(availableCountries[randomIndex]);
+ availableCountries.splice(randomIndex, 1);
+ }
+ return countries;
+}
+function shuffleArray(array) {
+ var shuffled = array.slice();
+ for (var i = shuffled.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = shuffled[i];
+ shuffled[i] = shuffled[j];
+ shuffled[j] = temp;
+ }
+ return shuffled;
+}
+function generateNewQuestion() {
+ gameActive = true;
+ // Clear previous flag
+ if (currentFlag) {
+ currentFlag.destroy();
+ }
+ // Select random correct answer
+ var correctCountry = flagData[Math.floor(Math.random() * flagData.length)];
+ correctAnswer = correctCountry.name;
+ // Create flag
+ currentFlag = new Flag(correctCountry);
+ currentFlag.x = 1024;
+ currentFlag.y = 400;
+ game.addChild(currentFlag);
+ // Get 4 random countries including the correct one
+ var countries = getRandomCountries(correctCountry, 4);
+ var shuffledCountries = shuffleArray(countries);
+ // Set up answer buttons
+ for (var i = 0; i < answerButtons.length; i++) {
+ var button = answerButtons[i];
+ var country = shuffledCountries[i];
+ button.setText(country.name);
+ button.isCorrect = country.name === correctAnswer;
+ button.reset();
+ }
+}
+function handleAnswer(isCorrect, button) {
+ if (!gameActive) return;
+ gameActive = false;
+ button.answered = true;
+ // Mark all buttons as answered to prevent further clicks
+ for (var i = 0; i < answerButtons.length; i++) {
+ answerButtons[i].answered = true;
+ }
+ if (isCorrect) {
+ button.setCorrect();
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText('Score: ' + LK.getScore());
+ LK.getSound('correct').play();
+ // Flash screen green briefly
+ LK.effects.flashScreen(0x7ed321, 300);
+ } else {
+ button.setIncorrect();
+ LK.getSound('incorrect').play();
+ // Show correct answer
+ for (var i = 0; i < answerButtons.length; i++) {
+ if (answerButtons[i].isCorrect) {
+ answerButtons[i].setCorrect();
+ break;
+ }
+ }
+ // Flash screen red briefly
+ LK.effects.flashScreen(0xd0021b, 300);
+ }
+ // Schedule next question
+ nextQuestionTimer = LK.setTimeout(function () {
+ generateNewQuestion();
+ }, 2000);
+}
+// Start first question
+generateNewQuestion();
+game.update = function () {
+ // Update score display
+ scoreText.setText('Score: ' + LK.getScore());
+};
\ No newline at end of file