\n\n\n","generatedCode":"
===================================================================\n--- original.js\n+++ change.js\n@@ -129,30 +129,66 @@\n \tquestion: "What is the name of the wall's black-cloaked defenders?",\n \tanswers: ["The Kingsguard", "The Night's Watch", "The Gold Cloaks", "The Brotherhood"],\n \tcorrect: 1\n }];\n+// Game state management\n+var gameState = 'menu'; // 'menu', 'playing', 'finished'\n var currentQuestionIndex = 0;\n var correctAnswers = 0;\n var totalQuestions = questions.length;\n var questionCard;\n var answerButtons = [];\n var scoreText;\n var isAnswering = false;\n+// Menu UI elements\n+var menuContainer;\n+var gameContainer;\n+var endContainer;\n // Create UI elements\n function initializeUI() {\n+\t// Create main containers\n+\tmenuContainer = game.addChild(new Container());\n+\tgameContainer = game.addChild(new Container());\n+\tendContainer = game.addChild(new Container());\n+\t// Setup menu screen\n+\tvar menuTitle = new Text2('Game of Thrones Quiz', {\n+\t\tsize: 80,\n+\t\tfill: 0xF39C12\n+\t});\n+\tmenuTitle.anchor.set(0.5, 0.5);\n+\tmenuTitle.x = 1024;\n+\tmenuTitle.y = 800;\n+\tmenuContainer.addChild(menuTitle);\n+\tvar menuSubtitle = new Text2('Test your knowledge of Westeros!', {\n+\t\tsize: 48,\n+\t\tfill: 0xFFFFFF\n+\t});\n+\tmenuSubtitle.anchor.set(0.5, 0.5);\n+\tmenuSubtitle.x = 1024;\n+\tmenuSubtitle.y = 950;\n+\tmenuContainer.addChild(menuSubtitle);\n+\tvar startButton = menuContainer.addChild(new AnswerButton());\n+\tstartButton.setAnswer('Start Game', false);\n+\tstartButton.x = 1024;\n+\tstartButton.y = 1200;\n+\tstartButton.down = function () {\n+\t\tstartGame();\n+\t};\n+\t// Setup game screen  \n+\tgameContainer.visible = false;\n \t// Question card\n-\tquestionCard = game.addChild(new QuestionCard());\n+\tquestionCard = gameContainer.addChild(new QuestionCard());\n \tquestionCard.x = 1024;\n \tquestionCard.y = 600;\n \t// Answer buttons\n \tfor (var i = 0; i < 4; i++) {\n-\t\tvar button = game.addChild(new AnswerButton());\n+\t\tvar button = gameContainer.addChild(new AnswerButton());\n \t\tbutton.x = i % 2 === 0 ? 524 : 1524;\n \t\tbutton.y = i < 2 ? 1200 : 1400;\n \t\tanswerButtons.push(button);\n \t}\n \t// Score display\n-\tvar scoreBackground = game.addChild(LK.getAsset('scoreBackground', {\n+\tvar scoreBackground = gameContainer.addChild(LK.getAsset('scoreBackground', {\n \t\tanchorX: 0.5,\n \t\tanchorY: 0.5\n \t}));\n \tscoreBackground.x = 1024;\n@@ -162,8 +198,10 @@\n \t\tfill: 0xFFFFFF\n \t});\n \tscoreText.anchor.set(0.5, 0.5);\n \tscoreBackground.addChild(scoreText);\n+\t// Setup end screen\n+\tendContainer.visible = false;\n }\n function displayQuestion() {\n \tif (currentQuestionIndex >= questions.length) {\n \t\tshowFinalScore();\n@@ -179,17 +217,58 @@\n }\n function updateScore() {\n \tscoreText.setText('Score: ' + correctAnswers + '/' + (currentQuestionIndex + 1));\n }\n+function startGame() {\n+\tgameState = 'playing';\n+\tcurrentQuestionIndex = 0;\n+\tcorrectAnswers = 0;\n+\tisAnswering = false;\n+\t// Hide menu, show game\n+\tmenuContainer.visible = false;\n+\tgameContainer.visible = true;\n+\tendContainer.visible = false;\n+\tdisplayQuestion();\n+}\n+function goToMenu() {\n+\tgameState = 'menu';\n+\t// Hide all screens, show menu\n+\tmenuContainer.visible = true;\n+\tgameContainer.visible = false;\n+\tendContainer.visible = false;\n+}\n function showFinalScore() {\n-\tvar finalText = new Text2('Quiz Complete!\\nFinal Score: ' + correctAnswers + '/' + totalQuestions, {\n+\tgameState = 'finished';\n+\t// Hide game screen, show end screen\n+\tgameContainer.visible = false;\n+\tendContainer.visible = true;\n+\t// Clear previous end screen content\n+\twhile (endContainer.children.length > 0) {\n+\t\tendContainer.removeChildAt(0);\n+\t}\n+\tvar endTitle = new Text2('Quiz Complete!', {\n \t\tsize: 80,\n \t\tfill: 0xF39C12\n \t});\n-\tfinalText.anchor.set(0.5, 0.5);\n-\tfinalText.x = 1024;\n-\tfinalText.y = 1366;\n-\tgame.addChild(finalText);\n+\tendTitle.anchor.set(0.5, 0.5);\n+\tendTitle.x = 1024;\n+\tendTitle.y = 1000;\n+\tendContainer.addChild(endTitle);\n+\tvar finalScoreText = new Text2('Final Score: ' + correctAnswers + '/' + totalQuestions, {\n+\t\tsize: 60,\n+\t\tfill: 0xFFFFFF\n+\t});\n+\tfinalScoreText.anchor.set(0.5, 0.5);\n+\tfinalScoreText.x = 1024;\n+\tfinalScoreText.y = 1200;\n+\tendContainer.addChild(finalScoreText);\n+\tvar menuButton = endContainer.addChild(new AnswerButton());\n+\tmenuButton.setAnswer('Return to Menu', false);\n+\tmenuButton.x = 1024;\n+\tmenuButton.y = 1500;\n+\tmenuButton.down = function () {\n+\t\tgoToMenu();\n+\t};\n \tif (correctAnswers >= totalQuestions * 0.8) {\n \t\tLK.showYouWin();\n \t} else if (correctAnswers < totalQuestions * 0.4) {\n \t\tLK.showGameOver();\n@@ -217,5 +296,5 @@\n \t}, 2000);\n };\n // Initialize the game\n initializeUI();\n-displayQuestion();\n\\ No newline at end of file\n+goToMenu();\n\\ No newline at end of file\n
"} Upit | Learn about creating the game Game of Thrones Quiz Challenge with gen AI