User prompt
players should get the ballon d'or award for a certain goal and the prices are not visible in the transfer market, make it visible, expand
User prompt
expand it a little more so that it appears in the prices and pull it down a little bit
User prompt
The names and prices are not fully visible in the transfer market, expand a little and make it visible.
Code edit (1 edits merged)
Please save this source code
User prompt
Football Manager: League Challenge
Initial prompt
We will make a text-based football game. First of all, there will be a menu. We will be the coach. There will be a league in the game, there will be 10 teams in the league table, one of them is our team. We will play against all of them one by one. Every time we win a match, 500 money will come. The total money we have earned will be written on the top right. There will be a squad system. We will buy players from the market with money. Example: Messi 2,000 money, Yamal 1,000 money, Salah 1,000 money, Haaland 1,000 money, etc. and we will be able to see the statistics of our players, such as how many goals they scored and how many assists they made.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Player class var Player = Container.expand(function () { var self = Container.call(this); // Properties self.name = ''; self.isStar = false; self.goals = 0; self.assists = 0; self.price = 0; self.position = ''; self.team = ''; // Team name // Visual var icon = self.attachAsset(self.isStar ? 'starPlayer' : 'playerIcon', { anchorX: 0.5, anchorY: 0.5 }); // Set up player display self.setPlayer = function (playerData) { self.name = playerData.name; self.isStar = playerData.isStar; self.goals = playerData.goals || 0; self.assists = playerData.assists || 0; self.price = playerData.price || 0; self.position = playerData.position || ''; self.team = playerData.team || ''; // Change icon color for star icon.tint = self.isStar ? 0xff5733 : 0xf5d142; }; return self; }); // Button class var UIButton = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); var label = new Text2('', { size: 60, fill: 0xFFFFFF }); label.anchor.set(0.5, 0.5); self.addChild(label); self.setText = function (txt) { label.setText(txt); }; // Highlight on press self.down = function () { bg.tint = 0x1e90ff; }; self.up = function () { bg.tint = 0x333333; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0a1a2f }); /**** * Game Code ****/ // Team colors and player icons (simple shapes for now) // --- Data --- var ALL_PLAYERS = [ // Star players { name: "Messi", isStar: true, price: 120, position: "FW" }, { name: "Yamal", isStar: true, price: 100, position: "FW" }, { name: "Salah", isStar: true, price: 110, position: "FW" }, { name: "Haaland", isStar: true, price: 130, position: "FW" }, // Regulars { name: "Ramos", isStar: false, price: 60, position: "DF" }, { name: "Modric", isStar: false, price: 70, position: "MF" }, { name: "Kimmich", isStar: false, price: 80, position: "MF" }, { name: "Alisson", isStar: false, price: 75, position: "GK" }, { name: "Walker", isStar: false, price: 65, position: "DF" }, { name: "Pedri", isStar: false, price: 85, position: "MF" }, { name: "Foden", isStar: false, price: 90, position: "FW" }, { name: "Gvardiol", isStar: false, price: 60, position: "DF" }, { name: "Musiala", isStar: false, price: 80, position: "MF" }, { name: "Onana", isStar: false, price: 60, position: "GK" }, { name: "Araujo", isStar: false, price: 65, position: "DF" }, { name: "Bellingham", isStar: false, price: 95, position: "MF" }, { name: "Saka", isStar: false, price: 90, position: "FW" }, { name: "Kane", isStar: false, price: 110, position: "FW" }, { name: "De Bruyne", isStar: false, price: 100, position: "MF" }, { name: "Robertson", isStar: false, price: 70, position: "DF" }]; var TEAM_NAMES = ["Lions FC", "Eagles United", "Sharks", "Tigers", "Wolves", "Dragons", "Falcons", "Bulls", "Panthers", "Your Team"]; // --- State --- var leagueTable = []; // [{name, points, played, won, drawn, lost, gf, ga}] var fixtures = []; // [{home, away}] var currentMatchIndex = 0; var userTeamName = "Your Team"; var userSquad = []; // [{name, isStar, goals, assists, price, position}] var userMoney = 200; // Start money var transferMarket = []; // Available players to buy var userStats = {}; // {playerName: {goals, assists}} var matchResult = null; // {home, away, homeGoals, awayGoals} var leagueFinished = false; // --- UI Elements --- var mainPanel = null; var infoText = null; var moneyText = null; var tablePanel = null; var squadPanel = null; var marketPanel = null; var nextButton = null; var buyButtons = []; var lineupText = null; // --- Helper Functions --- function shuffleArray(arr) { for (var i = arr.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } // Generate league table function initLeagueTable() { leagueTable = []; for (var i = 0; i < TEAM_NAMES.length; i++) { leagueTable.push({ name: TEAM_NAMES[i], points: 0, played: 0, won: 0, drawn: 0, lost: 0, gf: 0, ga: 0 }); } } // Generate fixtures (single round robin) function initFixtures() { fixtures = []; var teams = TEAM_NAMES.slice(); for (var i = 0; i < teams.length; i++) { for (var j = i + 1; j < teams.length; j++) { fixtures.push({ home: teams[i], away: teams[j] }); } } shuffleArray(fixtures); currentMatchIndex = 0; } // Generate initial user squad (random 7 players) function initUserSquad() { userSquad = []; var pool = ALL_PLAYERS.slice(); shuffleArray(pool); for (var i = 0; i < 7; i++) { var p = Object.assign({}, pool[i]); userSquad.push(p); userStats[p.name] = { goals: 0, assists: 0 }; } } // Generate transfer market (players not in userSquad) function updateTransferMarket() { var owned = {}; for (var i = 0; i < userSquad.length; i++) { owned[userSquad[i].name] = true; } transferMarket = []; for (var j = 0; j < ALL_PLAYERS.length; j++) { if (!owned[ALL_PLAYERS[j].name]) { transferMarket.push(Object.assign({}, ALL_PLAYERS[j])); } } shuffleArray(transferMarket); transferMarket = transferMarket.slice(0, 5); // Show 5 at a time } // Find team in leagueTable function getTeamRow(name) { for (var i = 0; i < leagueTable.length; i++) { if (leagueTable[i].name === name) return leagueTable[i]; } return null; } // Simulate a match function simulateMatch(home, away) { // User team gets a small boost var homeSquad = home === userTeamName ? userSquad : []; var awaySquad = away === userTeamName ? userSquad : []; var homeStrength = 50 + (home === userTeamName ? getSquadStrength(userSquad) : getRandomInt(40, 70)); var awayStrength = 50 + (away === userTeamName ? getSquadStrength(userSquad) : getRandomInt(40, 70)); // Add random factor homeStrength += getRandomInt(-10, 10); awayStrength += getRandomInt(-10, 10); var homeGoals = Math.max(0, Math.round(homeStrength / 30 + getRandomInt(0, 2))); var awayGoals = Math.max(0, Math.round(awayStrength / 30 + getRandomInt(0, 2))); // If user team, assign goals/assists to players if (home === userTeamName || away === userTeamName) { var userIsHome = home === userTeamName; var userGoals = userIsHome ? homeGoals : awayGoals; var userAssists = 0; for (var g = 0; g < userGoals; g++) { var scorerIdx = getRandomInt(0, userSquad.length - 1); var assistIdx = getRandomInt(0, userSquad.length - 1); while (assistIdx === scorerIdx && userSquad.length > 1) { assistIdx = getRandomInt(0, userSquad.length - 1); } var scorer = userSquad[scorerIdx]; var assister = userSquad[assistIdx]; userStats[scorer.name].goals += 1; userStats[assister.name].assists += 1; } } return { home: home, away: away, homeGoals: homeGoals, awayGoals: awayGoals }; } // Calculate squad strength function getSquadStrength(squad) { var sum = 0; for (var i = 0; i < squad.length; i++) { sum += squad[i].price; if (squad[i].isStar) sum += 10; } return Math.round(sum / squad.length); } // Update league table with match result function updateLeagueTable(result) { var home = getTeamRow(result.home); var away = getTeamRow(result.away); home.played += 1; away.played += 1; home.gf += result.homeGoals; home.ga += result.awayGoals; away.gf += result.awayGoals; away.ga += result.homeGoals; if (result.homeGoals > result.awayGoals) { home.won += 1; home.points += 3; away.lost += 1; } else if (result.homeGoals < result.awayGoals) { away.won += 1; away.points += 3; home.lost += 1; } else { home.drawn += 1; away.drawn += 1; home.points += 1; away.points += 1; } } // Sort league table function sortLeagueTable() { leagueTable.sort(function (a, b) { if (b.points !== a.points) return b.points - a.points; var gdA = a.gf - a.ga, gdB = b.gf - b.ga; if (gdB !== gdA) return gdB - gdA; return b.gf - a.gf; }); } // --- UI Functions --- function clearPanel(panel) { if (panel && panel.children) { for (var i = panel.children.length - 1; i >= 0; i--) { var c = panel.children[i]; if (c.destroy) c.destroy(); panel.removeChild(c); } } } function showMainPanel() { if (!mainPanel) { mainPanel = new Container(); mainPanel.x = 0; mainPanel.y = 0; game.addChild(mainPanel); } clearPanel(mainPanel); // Title var title = new Text2("Football League Manager", { size: 100, fill: 0xFFFFFF }); title.anchor.set(0.5, 0); title.x = 2048 / 2; title.y = 120; mainPanel.addChild(title); // Money if (!moneyText) { moneyText = new Text2("", { size: 60, fill: 0xF5D142 }); moneyText.anchor.set(1, 0); moneyText.x = 2048 - 60; moneyText.y = 120; mainPanel.addChild(moneyText); } updateMoneyText(); // Info if (!infoText) { infoText = new Text2("", { size: 60, fill: 0xFFFFFF }); infoText.anchor.set(0.5, 0); infoText.x = 2048 / 2; infoText.y = 250; mainPanel.addChild(infoText); } // League Table showLeagueTable(); // Squad showSquad(); // Transfer Market showTransferMarket(); // Next Match Button if (!nextButton) { nextButton = new UIButton(); nextButton.x = 2048 / 2; nextButton.y = 2732 - 200; nextButton.setText("Play Next Match"); nextButton.up = function () { playNextMatch(); }; mainPanel.addChild(nextButton); } nextButton.visible = !leagueFinished; // If league finished, show message if (leagueFinished) { infoText.setText("Season Finished! Tap to restart."); nextButton.visible = false; mainPanel.down = function () { restartGame(); }; } else { infoText.setText("Manage your team, buy players, and win the league!"); mainPanel.down = undefined; } } function updateMoneyText() { if (moneyText) { moneyText.setText("Money: $" + userMoney); } } function showLeagueTable() { if (!tablePanel) { tablePanel = new Container(); tablePanel.x = 80; tablePanel.y = 350; mainPanel.addChild(tablePanel); } clearPanel(tablePanel); var tableTitle = new Text2("League Table", { size: 60, fill: 0x1E90FF }); tableTitle.anchor.set(0, 0); tableTitle.x = 0; tableTitle.y = 0; tablePanel.addChild(tableTitle); sortLeagueTable(); for (var i = 0; i < leagueTable.length; i++) { var row = leagueTable[i]; var y = 80 + i * 60; var txt = i + 1 + ". " + row.name + " " + row.points + "pts " + row.played + "P " + row.won + "W " + row.drawn + "D " + row.lost + "L " + row.gf + "-" + row.ga; var color = row.name === userTeamName ? "#f5d142" : "#ffffff"; var t = new Text2(txt, { size: 44, fill: color }); t.anchor.set(0, 0); t.x = 0; t.y = y; tablePanel.addChild(t); } } function showSquad() { if (!squadPanel) { squadPanel = new Container(); squadPanel.x = 1100; squadPanel.y = 350; mainPanel.addChild(squadPanel); } clearPanel(squadPanel); var squadTitle = new Text2("Your Squad", { size: 60, fill: 0x1E90FF }); squadTitle.anchor.set(0, 0); squadTitle.x = 0; squadTitle.y = 0; squadPanel.addChild(squadTitle); for (var i = 0; i < userSquad.length; i++) { var p = userSquad[i]; var y = 80 + i * 90; var icon = LK.getAsset(p.isStar ? 'starPlayer' : 'playerIcon', { anchorX: 0.5, anchorY: 0.5, x: 40, y: y + 40 }); squadPanel.addChild(icon); var stat = userStats[p.name] || { goals: 0, assists: 0 }; var txt = p.name + " (" + p.position + ")" + (p.isStar ? " ★" : "") + " G:" + stat.goals + " A:" + stat.assists; var t = new Text2(txt, { size: 44, fill: 0xFFFFFF }); t.anchor.set(0, 0.5); t.x = 90; t.y = y + 40; squadPanel.addChild(t); } } function showTransferMarket() { if (!marketPanel) { marketPanel = new Container(); marketPanel.x = 600; // Move panel further left for more width marketPanel.y = 1400; // Move panel further down mainPanel.addChild(marketPanel); } clearPanel(marketPanel); buyButtons = []; var marketTitle = new Text2("Transfer Market", { size: 60, fill: 0x1E90FF }); marketTitle.anchor.set(0, 0); marketTitle.x = 0; marketTitle.y = 0; marketPanel.addChild(marketTitle); // Increase width and spacing for better visibility for (var i = 0; i < transferMarket.length; i++) { var p = transferMarket[i]; var y = 100 + i * 160; // More vertical space var icon = LK.getAsset(p.isStar ? 'starPlayer' : 'playerIcon', { anchorX: 0.5, anchorY: 0.5, x: 80, y: y + 60 }); marketPanel.addChild(icon); var txt = p.name + " (" + p.position + ")" + (p.isStar ? " ★" : "") + " $" + p.price; var t = new Text2(txt, { size: 64, fill: 0xFFFFFF }); t.anchor.set(0, 0.5); t.x = 180; t.y = y + 60; marketPanel.addChild(t); // Buy button var btn = new UIButton(); btn.x = 600; btn.y = y + 60; btn.setText("Buy"); btn.up = function (player) { return function () { buyPlayer(player); }; }(p); marketPanel.addChild(btn); buyButtons.push(btn); } } function playNextMatch() { if (currentMatchIndex >= fixtures.length) { leagueFinished = true; showMainPanel(); return; } var match = fixtures[currentMatchIndex]; currentMatchIndex += 1; matchResult = simulateMatch(match.home, match.away); updateLeagueTable(matchResult); showMatchResult(matchResult); updateMoneyText(); showLeagueTable(); showSquad(); updateTransferMarket(); showTransferMarket(); } function showMatchResult(result) { var msg = result.home + " " + result.homeGoals + " - " + result.awayGoals + " " + result.away; var userInvolved = result.home === userTeamName || result.away === userTeamName; var userWon = false, userDraw = false; if (userInvolved) { if (result.home === userTeamName && result.homeGoals > result.awayGoals || result.away === userTeamName && result.awayGoals > result.homeGoals) { userWon = true; } else if (result.homeGoals === result.awayGoals) { userDraw = true; } } var reward = 0; if (userWon) { reward = 50; userMoney += reward; } else if (userDraw) { reward = 20; userMoney += reward; } var statMsg = ""; if (userInvolved) { statMsg = "\n"; for (var i = 0; i < userSquad.length; i++) { var p = userSquad[i]; var s = userStats[p.name]; if (s.goals > 0 || s.assists > 0) { statMsg += p.name + ": G" + s.goals + " A" + s.assists + "\n"; } } } infoText.setText("Match Result:\n" + msg + (userInvolved ? "\nYou " + (userWon ? "won! +$" + reward : userDraw ? "drew! +$" + reward : "lost.") : "") + statMsg + "\nTap 'Play Next Match' to continue."); } function buyPlayer(player) { if (userMoney < player.price) { infoText.setText("Not enough money to buy " + player.name + "!"); return; } if (userSquad.length >= 11) { infoText.setText("Squad full! Max 11 players."); return; } userMoney -= player.price; var p = Object.assign({}, player); userSquad.push(p); userStats[p.name] = { goals: 0, assists: 0 }; updateMoneyText(); updateTransferMarket(); showTransferMarket(); showSquad(); infoText.setText("Bought " + p.name + "!"); } function restartGame() { leagueFinished = false; userMoney = 200; userStats = {}; initLeagueTable(); initFixtures(); initUserSquad(); updateTransferMarket(); showMainPanel(); } // --- Game Start --- function startGame() { leagueFinished = false; userMoney = 200; userStats = {}; initLeagueTable(); initFixtures(); initUserSquad(); updateTransferMarket(); showMainPanel(); } // --- Start --- startGame();
===================================================================
--- original.js
+++ change.js
@@ -521,10 +521,10 @@
}
function showTransferMarket() {
if (!marketPanel) {
marketPanel = new Container();
- marketPanel.x = 900; // Move panel a bit left for more width
- marketPanel.y = 1200;
+ marketPanel.x = 600; // Move panel further left for more width
+ marketPanel.y = 1400; // Move panel further down
mainPanel.addChild(marketPanel);
}
clearPanel(marketPanel);
buyButtons = [];
@@ -538,31 +538,29 @@
marketPanel.addChild(marketTitle);
// Increase width and spacing for better visibility
for (var i = 0; i < transferMarket.length; i++) {
var p = transferMarket[i];
- var y = 80 + i * 130; // More vertical space
+ var y = 100 + i * 160; // More vertical space
var icon = LK.getAsset(p.isStar ? 'starPlayer' : 'playerIcon', {
anchorX: 0.5,
anchorY: 0.5,
- x: 60,
- //{3n} // More space for icon
- y: y + 50 //{3o} // Center icon with new spacing
+ x: 80,
+ y: y + 60
});
marketPanel.addChild(icon);
var txt = p.name + " (" + p.position + ")" + (p.isStar ? " ★" : "") + " $" + p.price;
var t = new Text2(txt, {
- size: 54,
- //{3r} // Larger font for clarity
+ size: 64,
fill: 0xFFFFFF
});
t.anchor.set(0, 0.5);
- t.x = 130; //{3v} // Move text further right
- t.y = y + 50;
+ t.x = 180;
+ t.y = y + 60;
marketPanel.addChild(t);
// Buy button
var btn = new UIButton();
- btn.x = 500; // Move button further right
- btn.y = y + 50;
+ btn.x = 600;
+ btn.y = y + 60;
btn.setText("Buy");
btn.up = function (player) {
return function () {
buyPlayer(player);