/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Add a football field background
var footballBg = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 30,
scaleY: 20,
x: 2048 / 2,
y: 2732 / 2,
tint: 0x1e7f2f // green
});
footballBg.alpha = 0.25;
game.addChild(footballBg);
// State variables
// --- Text-based Football Career Game ---
var currentScreen = "teamSelect"; // "teamSelect", "match", "goal", "miss", "end", "transfer", "award"
var selectedTeam = null;
var matchStep = 0;
var score = 0;
// Transfer to international team
function showTransferScreen() {
currentScreen = "transfer";
clearMenu();
var txt = new Text2("Congratulations! You are transferring to Europe.\nChoose your new team:", {
size: 90,
fill: "#fff"
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 400;
game.addChild(txt);
menuTextObjs.push(txt);
var startY = 800;
var spacing = 220;
for (var i = 0; i < internationalTeams.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.1,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var teamTxt = new Text2(internationalTeams[idx], {
size: 90,
fill: "#222"
});
teamTxt.anchor.set(0.5, 0.5);
teamTxt.x = btn.x;
teamTxt.y = btn.y;
game.addChild(teamTxt);
menuTextObjs.push(teamTxt);
btn.down = function (x, y, obj) {
selectedInternationalTeam = internationalTeams[idx];
currentStage = "international";
showInternationalMatchIntro();
};
})(i);
}
}
// Step 6: End screen
var matchesPlayed = 0;
var totalGoals = 0;
var totalAssists = 0;
var totalYellowCards = 0;
var totalRedCards = 0;
var assistsThisMatch = 0;
var yellowCardsThisMatch = 0;
var redCardsThisMatch = 0;
var currentStage = "domestic"; // "domestic" or "international"
var internationalTeams = ["Barcelona", "Chelsea", "Liverpool"];
var selectedInternationalTeam = null;
var ballonDorAwarded = false;
// Menu option buttons
var menuOptions = [];
var menuTextObjs = [];
// Helper: Clear all menu option objects
function clearMenu() {
for (var i = 0; i < menuOptions.length; i++) {
if (menuOptions[i] && menuOptions[i].parent) {
menuOptions[i].parent.removeChild(menuOptions[i]);
}
}
menuOptions = [];
for (var j = 0; j < menuTextObjs.length; j++) {
if (menuTextObjs[j] && menuTextObjs[j].parent) {
menuTextObjs[j].parent.removeChild(menuTextObjs[j]);
}
}
menuTextObjs = [];
}
// Helper: Show a menu with options (array of {label, onSelect})
function showMenu(title, options) {
clearMenu();
// Title
var titleText = new Text2(title, {
size: 120,
fill: "#fff"
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 300;
game.addChild(titleText);
menuTextObjs.push(titleText);
// Options
var startY = 600;
var spacing = 220;
for (var i = 0; i < options.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 1.2,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2(options[idx].label, {
size: 90,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
options[idx].onSelect();
};
})(i);
}
}
// Step 1: Team selection
function showTeamSelect() {
currentScreen = "teamSelect";
selectedTeam = null;
score = 0;
matchStep = 0;
showMenu("Choose Your First Team", [{
label: "Galatasaray",
onSelect: function onSelect() {
selectedTeam = "Galatasaray";
showMatchIntro();
}
}, {
label: "Fenerbahçe",
onSelect: function onSelect() {
selectedTeam = "Fenerbahçe";
showMatchIntro();
}
}, {
label: "Beşiktaş",
onSelect: function onSelect() {
selectedTeam = "Beşiktaş";
showMatchIntro();
}
}]);
}
// Step 2: Match intro
function showMatchIntro() {
currentScreen = "match";
clearMenu();
var intro = "You joined " + selectedTeam + "!\nYour first match is about to begin.";
var introText = new Text2(intro, {
size: 90,
fill: "#fff"
});
introText.anchor.set(0.5, 0);
introText.x = 2048 / 2;
introText.y = 400;
game.addChild(introText);
menuTextObjs.push(introText);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.1,
x: 2048 / 2,
y: 900
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2("Start Match", {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
matchStep = 0;
score = 0;
showMatchStep();
};
}
// Step 3: Match steps (randomize correct option)
function showMatchStep() {
currentScreen = "match";
clearMenu();
var matchPrompts = [{
text: "You get the ball near the penalty area. What will you do?",
options: ["Shoot", "Pass", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "You see a teammate running into space. What will you do?",
options: ["Pass", "Shoot", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "Defender is closing in. What will you do?",
options: ["Dribble", "Pass", "Shoot", "Play Long"],
correct: Math.floor(Math.random() * 4)
}];
// Loop match steps, then end
if (matchStep >= matchPrompts.length) {
showEndScreen();
return;
}
var prompt = matchPrompts[matchStep];
var promptText = new Text2(prompt.text, {
size: 90,
fill: "#fff"
});
promptText.anchor.set(0.5, 0);
promptText.x = 2048 / 2;
promptText.y = 350;
game.addChild(promptText);
menuTextObjs.push(promptText);
var startY = 700;
var spacing = 180;
for (var i = 0; i < prompt.options.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2(prompt.options[idx], {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
if (idx === prompt.correct) {
score++;
showGoalScreen();
} else {
showMissScreen();
}
};
})(i);
}
}
// Step 4: Goal screen
function showGoalScreen() {
currentScreen = "goal";
clearMenu();
var txt = new Text2("GOAL! You scored for " + selectedTeam + "!", {
size: 110,
fill: 0xFFE600
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 600;
game.addChild(txt);
menuTextObjs.push(txt);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Next Play", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
matchStep++;
showMatchStep();
};
}
// Step 5: Miss screen
function showMissScreen() {
currentScreen = "miss";
clearMenu();
var txt = new Text2("Missed! The play didn't work out.", {
size: 100,
fill: 0xFF4444
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 600;
game.addChild(txt);
menuTextObjs.push(txt);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Next Play", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
matchStep++;
showMatchStep();
};
}
// Step 6: End screen
function showEndScreen() {
currentScreen = "end";
clearMenu();
matchesPlayed++;
totalGoals += score;
// --- Statistics logic ---
if (typeof totalAssists === "undefined") totalAssists = 0;
if (typeof totalYellowCards === "undefined") totalYellowCards = 0;
if (typeof totalRedCards === "undefined") totalRedCards = 0;
if (typeof assistsThisMatch === "undefined") assistsThisMatch = 0;
if (typeof yellowCardsThisMatch === "undefined") yellowCardsThisMatch = 0;
if (typeof redCardsThisMatch === "undefined") redCardsThisMatch = 0;
// Randomly generate assists, yellow/red cards for this match for fun
assistsThisMatch = Math.floor(Math.random() * 2); // 0 or 1
yellowCardsThisMatch = Math.random() < 0.25 ? 1 : 0; // 25% chance
redCardsThisMatch = yellowCardsThisMatch && Math.random() < 0.2 ? 1 : 0; // 20% if yellow
totalAssists += assistsThisMatch;
totalYellowCards += yellowCardsThisMatch;
totalRedCards += redCardsThisMatch;
// Show stats
var endMsg = "Match Over!\nGoals Scored: " + score + "\nAssists: " + assistsThisMatch + "\nYellow Cards: " + yellowCardsThisMatch + "\nRed Cards: " + redCardsThisMatch + "\n\nCareer Stats:" + "\nTotal Goals: " + totalGoals + "\nTotal Assists: " + totalAssists + "\nTotal Yellow Cards: " + totalYellowCards + "\nTotal Red Cards: " + totalRedCards + "\nMatches Played: " + matchesPlayed;
var txt = new Text2(endMsg, {
size: 90,
fill: "#fff"
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 520;
game.addChild(txt);
menuTextObjs.push(txt);
// After 3 matches, transfer to international team
if (currentStage === "domestic" && matchesPlayed >= 3) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Transfer to Europe", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
showTransferScreen();
};
return;
}
// After 6 matches, check for Ballon d'Or
if (currentStage === "international" && matchesPlayed >= 6 && !ballonDorAwarded) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Award Ceremony", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
showAwardCeremony();
};
return;
}
// Otherwise, play again or next match
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2(currentStage === "domestic" ? "Play Again" : "Next Match", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
if (currentStage === "domestic") {
showTeamSelect();
} else {
showInternationalMatchIntro();
}
};
}
// International match intro
function showInternationalMatchIntro() {
currentScreen = "match";
clearMenu();
var intro = "You joined " + selectedInternationalTeam + "!\nYour next match in Europe is about to begin.";
var introText = new Text2(intro, {
size: 90,
fill: "#fff"
});
introText.anchor.set(0.5, 0);
introText.x = 2048 / 2;
introText.y = 400;
game.addChild(introText);
menuTextObjs.push(introText);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.1,
x: 2048 / 2,
y: 900
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2("Start Match", {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
matchStep = 0;
score = 0;
showInternationalMatchStep();
};
}
// International match steps (same as domestic, but with new team)
function showInternationalMatchStep() {
currentScreen = "match";
clearMenu();
var matchPrompts = [{
text: "You get the ball in a Champions League match. What will you do?",
options: ["Shoot", "Pass", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "You see a world-class teammate open. What will you do?",
options: ["Pass", "Shoot", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "Defender is closing in. What will you do?",
options: ["Dribble", "Pass", "Shoot", "Play Long"],
correct: Math.floor(Math.random() * 4)
}];
if (matchStep >= matchPrompts.length) {
showEndScreen();
return;
}
var prompt = matchPrompts[matchStep];
var promptText = new Text2(prompt.text, {
size: 90,
fill: "#fff"
});
promptText.anchor.set(0.5, 0);
promptText.x = 2048 / 2;
promptText.y = 350;
game.addChild(promptText);
menuTextObjs.push(promptText);
var startY = 700;
var spacing = 180;
for (var i = 0; i < prompt.options.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2(prompt.options[idx], {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
if (idx === prompt.correct) {
score++;
showGoalScreen();
} else {
showMissScreen();
}
};
})(i);
}
}
// Award ceremony for Ballon d'Or
function showAwardCeremony() {
currentScreen = "award";
clearMenu();
ballonDorAwarded = true;
var awardMsg = "";
if (totalGoals >= 5) {
awardMsg = "Congratulations!\nYou scored " + totalGoals + " goals and won the Ballon d'Or!";
} else {
awardMsg = "Award Ceremony\nYou scored " + totalGoals + " goals.\nKeep playing to win the Ballon d'Or!";
}
// Show stats in ceremony
if (typeof totalAssists === "undefined") totalAssists = 0;
if (typeof totalYellowCards === "undefined") totalYellowCards = 0;
if (typeof totalRedCards === "undefined") totalRedCards = 0;
awardMsg += "\n\nCareer Stats:" + "\nTotal Assists: " + totalAssists + "\nTotal Yellow Cards: " + totalYellowCards + "\nTotal Red Cards: " + totalRedCards;
var txt = new Text2(awardMsg, {
size: 100,
fill: 0xFFD700
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 520;
game.addChild(txt);
menuTextObjs.push(txt);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Play Again", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
// Reset all state for a new career
matchesPlayed = 0;
totalGoals = 0;
totalAssists = 0;
totalYellowCards = 0;
totalRedCards = 0;
currentStage = "domestic";
selectedInternationalTeam = null;
ballonDorAwarded = false;
showTeamSelect();
};
}
// Start the game at team selection
showTeamSelect(); /****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Add a football field background
var footballBg = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 30,
scaleY: 20,
x: 2048 / 2,
y: 2732 / 2,
tint: 0x1e7f2f // green
});
footballBg.alpha = 0.25;
game.addChild(footballBg);
// State variables
// --- Text-based Football Career Game ---
var currentScreen = "teamSelect"; // "teamSelect", "match", "goal", "miss", "end", "transfer", "award"
var selectedTeam = null;
var matchStep = 0;
var score = 0;
// Transfer to international team
function showTransferScreen() {
currentScreen = "transfer";
clearMenu();
var txt = new Text2("Congratulations! You are transferring to Europe.\nChoose your new team:", {
size: 90,
fill: "#fff"
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 400;
game.addChild(txt);
menuTextObjs.push(txt);
var startY = 800;
var spacing = 220;
for (var i = 0; i < internationalTeams.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.1,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var teamTxt = new Text2(internationalTeams[idx], {
size: 90,
fill: "#222"
});
teamTxt.anchor.set(0.5, 0.5);
teamTxt.x = btn.x;
teamTxt.y = btn.y;
game.addChild(teamTxt);
menuTextObjs.push(teamTxt);
btn.down = function (x, y, obj) {
selectedInternationalTeam = internationalTeams[idx];
currentStage = "international";
showInternationalMatchIntro();
};
})(i);
}
}
// Step 6: End screen
var matchesPlayed = 0;
var totalGoals = 0;
var totalAssists = 0;
var totalYellowCards = 0;
var totalRedCards = 0;
var assistsThisMatch = 0;
var yellowCardsThisMatch = 0;
var redCardsThisMatch = 0;
var currentStage = "domestic"; // "domestic" or "international"
var internationalTeams = ["Barcelona", "Chelsea", "Liverpool"];
var selectedInternationalTeam = null;
var ballonDorAwarded = false;
// Menu option buttons
var menuOptions = [];
var menuTextObjs = [];
// Helper: Clear all menu option objects
function clearMenu() {
for (var i = 0; i < menuOptions.length; i++) {
if (menuOptions[i] && menuOptions[i].parent) {
menuOptions[i].parent.removeChild(menuOptions[i]);
}
}
menuOptions = [];
for (var j = 0; j < menuTextObjs.length; j++) {
if (menuTextObjs[j] && menuTextObjs[j].parent) {
menuTextObjs[j].parent.removeChild(menuTextObjs[j]);
}
}
menuTextObjs = [];
}
// Helper: Show a menu with options (array of {label, onSelect})
function showMenu(title, options) {
clearMenu();
// Title
var titleText = new Text2(title, {
size: 120,
fill: "#fff"
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 300;
game.addChild(titleText);
menuTextObjs.push(titleText);
// Options
var startY = 600;
var spacing = 220;
for (var i = 0; i < options.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 1.2,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2(options[idx].label, {
size: 90,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
options[idx].onSelect();
};
})(i);
}
}
// Step 1: Team selection
function showTeamSelect() {
currentScreen = "teamSelect";
selectedTeam = null;
score = 0;
matchStep = 0;
showMenu("Choose Your First Team", [{
label: "Galatasaray",
onSelect: function onSelect() {
selectedTeam = "Galatasaray";
showMatchIntro();
}
}, {
label: "Fenerbahçe",
onSelect: function onSelect() {
selectedTeam = "Fenerbahçe";
showMatchIntro();
}
}, {
label: "Beşiktaş",
onSelect: function onSelect() {
selectedTeam = "Beşiktaş";
showMatchIntro();
}
}]);
}
// Step 2: Match intro
function showMatchIntro() {
currentScreen = "match";
clearMenu();
var intro = "You joined " + selectedTeam + "!\nYour first match is about to begin.";
var introText = new Text2(intro, {
size: 90,
fill: "#fff"
});
introText.anchor.set(0.5, 0);
introText.x = 2048 / 2;
introText.y = 400;
game.addChild(introText);
menuTextObjs.push(introText);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.1,
x: 2048 / 2,
y: 900
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2("Start Match", {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
matchStep = 0;
score = 0;
showMatchStep();
};
}
// Step 3: Match steps (randomize correct option)
function showMatchStep() {
currentScreen = "match";
clearMenu();
var matchPrompts = [{
text: "You get the ball near the penalty area. What will you do?",
options: ["Shoot", "Pass", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "You see a teammate running into space. What will you do?",
options: ["Pass", "Shoot", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "Defender is closing in. What will you do?",
options: ["Dribble", "Pass", "Shoot", "Play Long"],
correct: Math.floor(Math.random() * 4)
}];
// Loop match steps, then end
if (matchStep >= matchPrompts.length) {
showEndScreen();
return;
}
var prompt = matchPrompts[matchStep];
var promptText = new Text2(prompt.text, {
size: 90,
fill: "#fff"
});
promptText.anchor.set(0.5, 0);
promptText.x = 2048 / 2;
promptText.y = 350;
game.addChild(promptText);
menuTextObjs.push(promptText);
var startY = 700;
var spacing = 180;
for (var i = 0; i < prompt.options.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2(prompt.options[idx], {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
if (idx === prompt.correct) {
score++;
showGoalScreen();
} else {
showMissScreen();
}
};
})(i);
}
}
// Step 4: Goal screen
function showGoalScreen() {
currentScreen = "goal";
clearMenu();
var txt = new Text2("GOAL! You scored for " + selectedTeam + "!", {
size: 110,
fill: 0xFFE600
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 600;
game.addChild(txt);
menuTextObjs.push(txt);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Next Play", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
matchStep++;
showMatchStep();
};
}
// Step 5: Miss screen
function showMissScreen() {
currentScreen = "miss";
clearMenu();
var txt = new Text2("Missed! The play didn't work out.", {
size: 100,
fill: 0xFF4444
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 600;
game.addChild(txt);
menuTextObjs.push(txt);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Next Play", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
matchStep++;
showMatchStep();
};
}
// Step 6: End screen
function showEndScreen() {
currentScreen = "end";
clearMenu();
matchesPlayed++;
totalGoals += score;
// --- Statistics logic ---
if (typeof totalAssists === "undefined") totalAssists = 0;
if (typeof totalYellowCards === "undefined") totalYellowCards = 0;
if (typeof totalRedCards === "undefined") totalRedCards = 0;
if (typeof assistsThisMatch === "undefined") assistsThisMatch = 0;
if (typeof yellowCardsThisMatch === "undefined") yellowCardsThisMatch = 0;
if (typeof redCardsThisMatch === "undefined") redCardsThisMatch = 0;
// Randomly generate assists, yellow/red cards for this match for fun
assistsThisMatch = Math.floor(Math.random() * 2); // 0 or 1
yellowCardsThisMatch = Math.random() < 0.25 ? 1 : 0; // 25% chance
redCardsThisMatch = yellowCardsThisMatch && Math.random() < 0.2 ? 1 : 0; // 20% if yellow
totalAssists += assistsThisMatch;
totalYellowCards += yellowCardsThisMatch;
totalRedCards += redCardsThisMatch;
// Show stats
var endMsg = "Match Over!\nGoals Scored: " + score + "\nAssists: " + assistsThisMatch + "\nYellow Cards: " + yellowCardsThisMatch + "\nRed Cards: " + redCardsThisMatch + "\n\nCareer Stats:" + "\nTotal Goals: " + totalGoals + "\nTotal Assists: " + totalAssists + "\nTotal Yellow Cards: " + totalYellowCards + "\nTotal Red Cards: " + totalRedCards + "\nMatches Played: " + matchesPlayed;
var txt = new Text2(endMsg, {
size: 90,
fill: "#fff"
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 520;
game.addChild(txt);
menuTextObjs.push(txt);
// After 3 matches, transfer to international team
if (currentStage === "domestic" && matchesPlayed >= 3) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Transfer to Europe", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
showTransferScreen();
};
return;
}
// After 6 matches, check for Ballon d'Or
if (currentStage === "international" && matchesPlayed >= 6 && !ballonDorAwarded) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Award Ceremony", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
showAwardCeremony();
};
return;
}
// Otherwise, play again or next match
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2(currentStage === "domestic" ? "Play Again" : "Next Match", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
if (currentStage === "domestic") {
showTeamSelect();
} else {
showInternationalMatchIntro();
}
};
}
// International match intro
function showInternationalMatchIntro() {
currentScreen = "match";
clearMenu();
var intro = "You joined " + selectedInternationalTeam + "!\nYour next match in Europe is about to begin.";
var introText = new Text2(intro, {
size: 90,
fill: "#fff"
});
introText.anchor.set(0.5, 0);
introText.x = 2048 / 2;
introText.y = 400;
game.addChild(introText);
menuTextObjs.push(introText);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 1.1,
x: 2048 / 2,
y: 900
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2("Start Match", {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
matchStep = 0;
score = 0;
showInternationalMatchStep();
};
}
// International match steps (same as domestic, but with new team)
function showInternationalMatchStep() {
currentScreen = "match";
clearMenu();
var matchPrompts = [{
text: "You get the ball in a Champions League match. What will you do?",
options: ["Shoot", "Pass", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "You see a world-class teammate open. What will you do?",
options: ["Pass", "Shoot", "Dribble", "Play Long"],
correct: Math.floor(Math.random() * 4)
}, {
text: "Defender is closing in. What will you do?",
options: ["Dribble", "Pass", "Shoot", "Play Long"],
correct: Math.floor(Math.random() * 4)
}];
if (matchStep >= matchPrompts.length) {
showEndScreen();
return;
}
var prompt = matchPrompts[matchStep];
var promptText = new Text2(prompt.text, {
size: 90,
fill: "#fff"
});
promptText.anchor.set(0.5, 0);
promptText.x = 2048 / 2;
promptText.y = 350;
game.addChild(promptText);
menuTextObjs.push(promptText);
var startY = 700;
var spacing = 180;
for (var i = 0; i < prompt.options.length; i++) {
(function (idx) {
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: startY + idx * spacing
});
game.addChild(btn);
menuOptions.push(btn);
var txt = new Text2(prompt.options[idx], {
size: 80,
fill: "#222"
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
menuTextObjs.push(txt);
btn.down = function (x, y, obj) {
if (idx === prompt.correct) {
score++;
showGoalScreen();
} else {
showMissScreen();
}
};
})(i);
}
}
// Award ceremony for Ballon d'Or
function showAwardCeremony() {
currentScreen = "award";
clearMenu();
ballonDorAwarded = true;
var awardMsg = "";
if (totalGoals >= 5) {
awardMsg = "Congratulations!\nYou scored " + totalGoals + " goals and won the Ballon d'Or!";
} else {
awardMsg = "Award Ceremony\nYou scored " + totalGoals + " goals.\nKeep playing to win the Ballon d'Or!";
}
// Show stats in ceremony
if (typeof totalAssists === "undefined") totalAssists = 0;
if (typeof totalYellowCards === "undefined") totalYellowCards = 0;
if (typeof totalRedCards === "undefined") totalRedCards = 0;
awardMsg += "\n\nCareer Stats:" + "\nTotal Assists: " + totalAssists + "\nTotal Yellow Cards: " + totalYellowCards + "\nTotal Red Cards: " + totalRedCards;
var txt = new Text2(awardMsg, {
size: 100,
fill: 0xFFD700
});
txt.anchor.set(0.5, 0);
txt.x = 2048 / 2;
txt.y = 520;
game.addChild(txt);
menuTextObjs.push(txt);
var btn = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.5,
scaleY: 1,
x: 2048 / 2,
y: 1000
});
game.addChild(btn);
menuOptions.push(btn);
var nextTxt = new Text2("Play Again", {
size: 80,
fill: "#222"
});
nextTxt.anchor.set(0.5, 0.5);
nextTxt.x = btn.x;
nextTxt.y = btn.y;
game.addChild(nextTxt);
menuTextObjs.push(nextTxt);
btn.down = function (x, y, obj) {
// Reset all state for a new career
matchesPlayed = 0;
totalGoals = 0;
totalAssists = 0;
totalYellowCards = 0;
totalRedCards = 0;
currentStage = "domestic";
selectedInternationalTeam = null;
ballonDorAwarded = false;
showTeamSelect();
};
}
// Start the game at team selection
showTeamSelect();