User prompt
hala you yazıyor onu düzet sadece seçtiğim takım olsun
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'name')' in or related to this line: 'opponentTeam.name = leagueTeams[oppIdx].name;' Line Number: 2216
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'name')' in or related to this line: 'var oppName = leagueTeams[oppIdx].name;' Line Number: 915
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'played')' in or related to this line: 'homeTeam.played += 1;' Line Number: 855
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'realSquad')' in or related to this line: 'if (homeTeam.realSquad) {' Line Number: 773
User prompt
takım seçince ligde 2 tane oluyor seçtiğim takımı ligden sil ve sadece benim takımım olsun
User prompt
takımı seçtikten sonra seçtiğim takımı league 1 yerinde maviyle gösterki belli olsun
User prompt
oyuna girince takım seçmek olsun ligdeki tüm takımlardan birini seçelim ve onunla oynayalım bu seçim yerini gösterirken ekrana hiçbişey koyma herhangi bir lig takımı seçtikten sonra herşey ekrana gelsin ve o takımla oynamaya devam edelim
User prompt
şampiyonlar ligi yazısını gelince boş bir ekrana koy çünkü görünmüyor boş bi ekrana gelince tam ortada olsun
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attack')' in or related to this line: 'var atkChance = atkP.attack + randomInt(0, atkP.stamina);' Line Number: 831
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'seasonsRemaining')' in or related to this line: 'var seasonsTxt = typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null ? " (" + p.seasonsRemaining + "s)" : "";' Line Number: 242
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'inSquad')' in or related to this line: 'allPlayers[i].inSquad = false;' Line Number: 183
User prompt
Please fix the bug: 'PLAYER_MAX_VALUE is not defined' in or related to this line: 'var val = Math.floor((atk + def + sta) / 3) + randomInt(PLAYER_MIN_VALUE + 2, PLAYER_MAX_VALUE - 5);' Line Number: 168
User prompt
Please add a Champions League-style tournament to the game. At the end of each season, the top 4 teams in the league should qualify for the next season's Champions League. This tournament should run alongside the regular league season and include knockout rounds or group stages with other qualified teams. Winning it should reward extra prize money and prestige.
User prompt
Recreate the FIFA Ultimate Team draft screen, but make the layout clean, spaced out, and visually organized by player positions. Do not overlap any cards. Every card should be clearly separated, aligned properly based on its role in the 4-3-3 (Attacking) formation. Forwards at the top, midfielders in the middle, defenders and goalkeeper at the bottom. Use clean lines and generous spacing. Each player card must be fully visible and readable — no cards should cover others. Add the START DRAFT button clearly at the bottom center, with enough breathing room around it. Keep the card designs FIFA-style (ICON, TOTY, etc.), but focus on clean composition and visual clarity. Do not sacrifice layout for fancy styling. The final result should feel like a polished in-game draft interface: clean, pro-level, and easy to understand at a glance.
User prompt
Please fix the bug: 'Uncaught TypeError: card.swapChildren is not a function' in or related to this line: 'card.swapChildren(border, bg);' Line Number: 1054
User prompt
Ultimate FIFA Draft Prompt – Clean UI, Player-by-Player Reveal, No Mess Build a FIFA-style Ultimate Team Draft system with a clean, minimal user interface. Use the 4-3-3 (Attacking) formation. The UI should be smooth and easy to navigate — no clutter, no dropdown hell, no hidden menus. Each position in the squad must be shown one by one, not all at once. Start with the goalkeeper, then move through the defenders, midfielders, and forwards — just like in a real draft experience. For each position, show 3 player cards side-by-side (visually styled like FUT cards), clearly labeled with their name, rating, card type (ICON, TOTY, etc.), and stats (pace, shooting, passing, etc.). After showing the 3 options, automatically pick the best-fitting player based on chemistry, traits, preferred foot, and fit with the chosen playstyle (fast-paced passing and wing-focused attacks). Add a single big “START DRAFT” button at the bottom of the screen that launches the process — no multiple clicks or hidden interactions. Each draft step should feel smooth and satisfying, with clean transitions between positions. At the end, display the full squad visually, and provide a short but sharp analysis of the team’s strengths, chemistry, weaknesses, and how it would play in-game. Don’t overcomplicate. Don’t overdecorate. Just make it look elite, smart, and easy to use — like something a real player would want to interact with.
User prompt
Build a FIFA-style Ultimate Team draft system using the 4-3-3 (Attacking) formation. Make the interface clean, straightforward, and focused. I don’t want clutter or unnecessary complexity. Every position must show 3 high-tier player options (preferably ICON and TOTY cards), with one being selected automatically based on chemistry, stats, and fit for a fast-paced, quick-passing, wing-based playstyle. Make sure the draft logic considers: chemistry links, preferred foot, work rates, skill moves, and player traits (like finesse shot, outside foot, etc.). I want a fully built squad by the end, with proper roles filled and good in-game synergy. Do not bury the functionality under dropdowns or multiple clicks. Put a big, visible “Start Draft” button at the bottom of the screen that kicks off the draft. The button should be impossible to miss. I’m not here to click around for half an hour — this should feel like a clean, smooth draft flow from beginning to end. After the draft finishes, give a brief analysis of the final team: chemistry, strengths, weak spots, and how it would ideally play in-game. Keep your tone clear and focused — don’t fluff things up. This is about efficiency, clarity, and delivering a killer squad-building experience.
User prompt
do that in game
User prompt
put youth academy and transfer market in mainb
User prompt
make league 2 table more right
Code edit (1 edits merged)
Please save this source code
User prompt
After playing a match, the Youth Academy and Transfer Market sections disappear from the interface. Please fix this bug so that both features remain visible and accessible after a match is played.
User prompt
matches are so many scores make it lower
User prompt
Everything in the game is very messy and disorganized. Please clean up and fix the entire layout so it's clear, structured, and easy to use.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a3d2f }); /**** * Game Code ****/ // Player class: represents a footballer // --- CONSTANTS --- var Player = function Player(name, attack, defense, stamina, value, seasonsRemaining) { var self = {}; self.name = name; self.attack = attack; self.defense = defense; self.stamina = stamina; self.value = value; self.maxStamina = stamina; self.inSquad = false; // true if in starting 5 self.seasonsRemaining = typeof seasonsRemaining === "number" ? seasonsRemaining : null; // null for non-transfer players, or integer for transfer market return self; }; // Team class: holds a list of players var Team = function Team(name, players) { var self = {}; self.name = name; self.players = players; // array of Player return self; }; var SQUAD_SIZE = 5; var BENCH_SIZE = 3; var INITIAL_BUDGET = 100; var PLAYER_MIN_VALUE = 10; var PLAYER_MAX_VALUE = 40; // Added to fix not defined error. Adjust as needed for your game balance. // --- GLOBALS --- // --- GLOBALS --- var allPlayers = []; // All players owned by user var squad = []; // Starting 5 var bench = []; // Bench 3 var transferList = []; // Players available to buy var budget = INITIAL_BUDGET; var opponentTeam = null; var matchInProgress = false; var matchLog = []; var matchResult = null; var selectedPlayerIdx = null; // For swapping var selectedBenchIdx = null; // For swapping var infoText = null; var budgetText = null; var matchText = null; var transferText = null; var transferBtns = []; var swapBtns = []; var playBtn = null; var nextBtn = null; var sellBtns = []; var buyBtns = []; var squadLabels = []; var benchLabels = []; var opponentLabels = []; var guiY = 0; // --- CHAMPIONS LEAGUE SYSTEM --- var championsLeagueTeams = []; // Array of {name, realSquad, ...} var championsLeagueFixtures = []; // Array of {homeIdx, awayIdx} var championsLeagueCurrentRound = 0; var championsLeagueActive = false; var championsLeagueUserQualified = false; var championsLeagueUserEliminated = false; var championsLeaguePrize = 0; var championsLeagueLog = []; var championsLeagueOpponent = null; var championsLeagueStage = ""; // "Group", "Quarterfinal", "Semifinal", "Final" var championsLeagueGroup = []; // User's group, if group stage var championsLeagueGroupResults = []; // Standings for group var championsLeagueKnockoutBracket = []; // For knockout rounds var championsLeagueUserGroupPos = null; var championsLeagueUserLastStage = ""; // --- YOUTH ACADEMY --- var youthAcademy = []; // Array of young players waiting for promotion/sale var youthLabels = []; var promoteBtns = []; var sellYouthBtns = []; var youthTimer = null; var YOUTH_TIMER_INTERVAL = 10000; // 10 seconds for demo (tweak as needed) var YOUTH_MAX = 3; // Max youth in academy at once // --- TRANSFER OFFERS SYSTEM --- // Each offer: {player: Player, offerValue: number, club: string} var transferOffers = []; var offerLabels = []; var acceptOfferBtns = []; var rejectOfferBtns = []; var OFFER_TIMER = null; var OFFER_INTERVAL = 15000; // 15 seconds for demo var OFFER_CLUBS = ["Galatasaray", "Fenerbahce", "Besiktas", "Trabzonspor", "Basaksehir", "Sivasspor", "Konyaspor", "Antalyaspor", "Alanyaspor", "Denizlispor"]; // --- UTILS --- function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function randomName() { var first = ["Ahmet", "Mehmet", "Mustafa", "Ali", "Hüseyin", "Hasan", "Cesur", "Osman", "Yusuf", "Murat", "Emre", "Burak", "Fatih", "Serkan", "Onur", "Barış", "Cem", "Eren", "Kaan", "Deniz", "Çınar", "Aziz", "Ege", "Miraç"]; var last = ["Yılmaz", "Kaya", "Demir", "Şahin", "Çelik", "Yıldız", "Yıldırım", "Aydın", "Öztürk", "Arslan", "Doğan", "Kılıç", "Aslan", "Polat", "Koç", "Kurt", "Özdemir", "Aksoy", "Güneş", "Bozkurt", "Bozbalak", "Sakız", "Fizikli"]; return first[randomInt(0, first.length - 1)] + " " + last[randomInt(0, last.length - 1)]; } function makeRandomPlayer() { var atk = randomInt(5, 15); var def = randomInt(5, 15); var sta = randomInt(10, 20); var val = Math.floor((atk + def + sta) / 3) + randomInt(PLAYER_MIN_VALUE, PLAYER_MAX_VALUE); return new Player(randomName(), atk, def, sta, val); } // Real-life Turkish Super Lig squads (2023/24, main players, 5 per team for demo) var realSquads = { "Galatasaray": [new Player("Mauro Icardi", 18, 8, 16, 40), new Player("Dries Mertens", 16, 7, 15, 36), new Player("Lucas Torreira", 10, 16, 17, 34), new Player("Kerem Aktürkoğlu", 15, 8, 15, 32), new Player("Fernando Muslera", 7, 18, 16, 35)], "Fenerbahce": [new Player("Edin Dzeko", 17, 7, 15, 38), new Player("Dusan Tadic", 16, 8, 15, 36), new Player("Fred", 12, 14, 16, 33), new Player("Sebastian Szymanski", 15, 9, 15, 32), new Player("Dominik Livakovic", 6, 17, 16, 34)], "Besiktas": [new Player("Cenk Tosun", 16, 7, 15, 34), new Player("Rachid Ghezzal", 15, 8, 14, 32), new Player("Salih Uçan", 12, 13, 15, 30), new Player("Omar Colley", 8, 16, 15, 31), new Player("Mert Günok", 6, 17, 15, 30)], "Trabzonspor": [new Player("Edin Visca", 15, 8, 15, 32), new Player("Anastasios Bakasetas", 15, 9, 15, 32), new Player("Uğurcan Çakır", 6, 17, 16, 33), new Player("Enis Bardhi", 14, 8, 14, 29), new Player("Joaquin Fernandez", 8, 15, 14, 28)], "Basaksehir": [new Player("Danijel Aleksic", 14, 8, 14, 28), new Player("Leo Duarte", 8, 15, 14, 27), new Player("Serdar Gürler", 13, 8, 14, 27), new Player("Mahmut Tekdemir", 9, 14, 14, 26), new Player("Volkan Babacan", 6, 16, 14, 25)], "Sivasspor": [new Player("Mustapha Yatabare", 14, 8, 14, 27), new Player("Max Gradel", 13, 8, 14, 27), new Player("Hakan Arslan", 10, 13, 14, 25), new Player("Uğur Çiftçi", 8, 14, 14, 24), new Player("Ali Şaşal Vural", 6, 16, 14, 24)], "Konyaspor": [new Player("Sokol Cikalleshi", 14, 8, 14, 27), new Player("Amir Hadziahmetovic", 11, 13, 14, 25), new Player("Guilherme", 10, 13, 14, 25), new Player("Francisco Calvo", 8, 15, 14, 25), new Player("Ibrahim Sehic", 6, 16, 14, 24)], "Antalyaspor": [new Player("Haji Wright", 14, 8, 14, 27), new Player("Fernando", 11, 13, 14, 25), new Player("Bünyamin Balcı", 10, 13, 14, 24), new Player("Veysel Sarı", 8, 15, 14, 24), new Player("Helton Leite", 6, 16, 14, 24)], "Alanyaspor": [new Player("Efecan Karaca", 14, 8, 14, 27), new Player("Famara Diedhiou", 13, 8, 14, 26), new Player("Yusuf Özdemir", 10, 13, 14, 24), new Player("Fidan Aliti", 8, 15, 14, 24), new Player("Runar Runarsson", 6, 16, 14, 24)], "Denizlispor": [new Player("Ömer Şişmanoğlu", 13, 8, 14, 25), new Player("Mustafa Yumlu", 8, 15, 14, 24), new Player("Gökhan Süzen", 10, 13, 14, 23), new Player("Oğuz Yılmaz", 8, 14, 14, 23), new Player("Adam Stachowiak", 6, 16, 14, 23)] }; function makeOpponentTeam() { // List of realistic Turkish club names var clubNames = ["Denizlispor", "Sivasspor", "Galatasaray", "Fenerbahce", "Trabzonspor", "Besiktas", "Basaksehir", "Konyaspor", "Antalyaspor", "Alanyaspor"]; // Pick a random club name for the opponent var clubName = clubNames[randomInt(0, clubNames.length - 1)]; var oppPlayers; if (realSquads[clubName]) { // Use real squad, clone to avoid reference issues oppPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) { var p = realSquads[clubName][i]; oppPlayers.push(clonePlayer(p)); } } else { // Fallback to random oppPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) { oppPlayers.push(makeRandomPlayer()); } } return new Team(clubName, oppPlayers); } function clonePlayer(p) { return new Player(p.name, p.attack, p.defense, p.stamina, p.value, p.seasonsRemaining); } // --- INIT DATA --- function initPlayers() { allPlayers = []; for (var i = 0; i < SQUAD_SIZE + BENCH_SIZE; i++) { // For initial squad, generate decent stats (attack, defense, stamina) var atk = randomInt(8, 13); var def = randomInt(8, 13); var sta = randomInt(13, 18); var val = Math.floor((atk + def + sta) / 3) + randomInt(PLAYER_MIN_VALUE + 2, PLAYER_MAX_VALUE - 5); allPlayers.push(new Player(randomName(), atk, def, sta, val)); } updateSquadAndBench(); } function updateSquadAndBench() { squad = []; bench = []; for (var i = 0; i < allPlayers.length; i++) { if (!allPlayers[i]) continue; if (i < SQUAD_SIZE) { allPlayers[i].inSquad = true; squad.push(allPlayers[i]); } else { allPlayers[i].inSquad = false; bench.push(allPlayers[i]); } } } function initTransferList() { transferList = []; // List of latest, highest-valued real-world football players (2024, top market values, demo) var topPlayers = [new Player("Kylian Mbappé", 20, 12, 19, 180), new Player("Erling Haaland", 21, 10, 18, 170), new Player("Jude Bellingham", 18, 14, 18, 150), new Player("Vinícius Júnior", 19, 12, 18, 150), new Player("Phil Foden", 17, 13, 17, 130), new Player("Bukayo Saka", 17, 12, 17, 120), new Player("Rodri", 14, 18, 17, 120), new Player("Jamal Musiala", 17, 12, 17, 120), new Player("Victor Osimhen", 19, 10, 17, 110), new Player("Florian Wirtz", 16, 12, 17, 110), new Player("Pedri", 15, 13, 17, 100), new Player("Declan Rice", 13, 17, 17, 100), new Player("Harry Kane", 20, 10, 16, 100), new Player("Martin Ødegaard", 16, 13, 16, 100), new Player("Rafael Leão", 18, 10, 16, 90), new Player("Khvicha Kvaratskhelia", 17, 11, 16, 90), new Player("Josko Gvardiol", 10, 18, 16, 90), new Player("Gavi", 14, 14, 16, 90), new Player("Alejandro Balde", 12, 15, 16, 80), new Player("William Saliba", 9, 18, 16, 80), new Player("Son Heung Min", 19, 11, 17, 110)]; // Always show 6 random top players in the transfer market, no duplicates var usedIdx = []; for (var i = 0; i < 6; i++) { var idx; do { idx = randomInt(0, topPlayers.length - 1); } while (usedIdx.indexOf(idx) !== -1); usedIdx.push(idx); // When adding to transferList, set seasonsRemaining=3 for transfer market players var p = topPlayers[idx]; transferList.push(new Player(p.name, p.attack, p.defense, p.stamina, p.value, 3)); } } // --- UI HELPERS --- function clearArray(arr) { while (arr.length > 0) { var el = arr.pop(); if (el && el.destroy) { el.destroy(); } } } function makeLabel(txt, x, y, size, color) { var t = new Text2(txt, { size: size || 60, fill: color || "#fff" }); t.x = x; t.y = y; return t; } function updateBudgetText() { budgetText.setText("Budget: $" + budget + "M"); } function showInfo(msg) { infoText.setText(msg); } function updateSquadLabels() { clearArray(squadLabels); // Add extra margin at the top for squad section var startY = guiY + 240; // Keep top margin for squad section var squadX = 80; // left margin var swapBtnX = squadX + 700; // move swap arrow much closer to name var sellBtnX = squadX + 800; // move sell button just after swap arrow var rowSpacing = 50; // reduced for almost zero vertical space between squad texts for (var i = 0; i < SQUAD_SIZE; i++) { var p = squad[i]; if (!p) { continue; } var seasonsTxt = typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null ? " (" + p.seasonsRemaining + "s)" : ""; var t = makeLabel(i + 1 + ". " + p.name + " [A:" + p.attack + " D:" + p.defense + " S:" + p.stamina + "]" + seasonsTxt, squadX, startY + i * rowSpacing, 48, "#ffe066"); game.addChild(t); squadLabels.push(t); // Add swap button var btn = makeLabel("↔", swapBtnX, t.y, 48, "#fff"); btn.idx = i; btn.interactive = true; btn.down = function (x, y, obj) { selectedPlayerIdx = obj.idx; if (selectedPlayerIdx !== null && squad[selectedPlayerIdx]) { showInfo("Tap a bench player to swap with " + squad[selectedPlayerIdx].name); } else { showInfo("Tap a bench player to swap."); } }; game.addChild(btn); swapBtns.push(btn); // Add sell button var sellBtn = makeLabel("Sell", sellBtnX, t.y, 40, "#ff7675"); sellBtn.idx = i; sellBtn.interactive = true; sellBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = squad[idx]; if (!p) { showInfo("Player not available."); return; } // Find the player in allPlayers by reference, not by index var allIdx = allPlayers.indexOf(p); if (allIdx !== -1) { budget += p.value; allPlayers.splice(allIdx, 1); updateSquadAndBench(); updateBudgetText(); showInfo("Sold " + p.name + " for $" + p.value + "M"); refreshUI(); } else { showInfo("Player not found in squad."); } }; }(i); game.addChild(sellBtn); sellBtns.push(sellBtn); } } function updateBenchLabels() { clearArray(benchLabels); // Add extra margin at the top for bench section var startY = guiY + 240; // Increased for more top margin var benchX = 1100; // moved closer to squad var rowSpacing = 48; // reduced for almost zero vertical space between bench texts for (var i = 0; i < BENCH_SIZE; i++) { var p = bench[i]; if (!p) { continue; } var seasonsTxt = typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null ? " (" + p.seasonsRemaining + "s)" : ""; var t = makeLabel("B" + (i + 1) + ". " + p.name + " [A:" + p.attack + " D:" + p.defense + " S:" + p.stamina + "]" + seasonsTxt, benchX, startY + i * rowSpacing, 48, "#b2bec3"); game.addChild(t); benchLabels.push(t); // Add swap handler t.idx = i; t.interactive = true; t.down = function (x, y, obj) { if (selectedPlayerIdx !== null) { // Swap squad[selectedPlayerIdx] with bench[obj.idx] var sIdx = selectedPlayerIdx; var bIdx = obj.idx; var temp = squad[sIdx]; squad[sIdx] = bench[bIdx]; bench[bIdx] = temp; // Update allPlayers order for (var j = 0; j < SQUAD_SIZE; j++) { allPlayers[j] = squad[j]; } for (var j = 0; j < BENCH_SIZE; j++) { allPlayers[SQUAD_SIZE + j] = bench[j]; } selectedPlayerIdx = null; showInfo("Swapped players."); refreshUI(); } }; } } function updateTransferLabels() { clearArray(transferBtns); clearArray(buyBtns); // Position transfer section directly above the opponent team display (bottom-left) var sectionWidth = 900; var sectionX = 80; // Align with opponent section (left margin) var sectionHeight = (transferList.length + 1) * 140 + 120; // Height of transfer section, increased row height and extra margin // Calculate opponent section Y var oppStartY = 2048 - (SQUAD_SIZE + 2) * 120 - 200; // increased row height and more margin for opponent section if (oppStartY < guiY + 1800) { oppStartY = guiY + 1800; } // push down if needed for more space // Place transfer section just above opponent section var startY = oppStartY - sectionHeight - 120; // 120px gap above opponent section if (startY < guiY + 600) { startY = guiY + 600; } // avoid top overlap, more margin if (transferText) { transferText.destroy(); } transferText = makeLabel("Transfer Market", sectionX, startY - 90, 56, "#00b894"); game.addChild(transferText); for (var i = 0; i < transferList.length; i++) { var p = transferList[i]; // Remove seasonsTxt for transfer market display var t = makeLabel(p.name + " [A:" + p.attack + " D:" + p.defense + " S:" + p.stamina + "] $" + p.value + "M", sectionX, startY + i * 48, 44, "#fff"); game.addChild(t); transferBtns.push(t); // Buy button var buyBtn = makeLabel("Buy", sectionX + 750, t.y, 40, "#00b894"); // moved right for more space buyBtn.idx = i; buyBtn.interactive = true; buyBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = transferList[idx]; if (!p) { showInfo("Player not available."); return; } if (budget < p.value) { showInfo("Not enough budget!"); return; } if (allPlayers.length >= SQUAD_SIZE + BENCH_SIZE) { showInfo("Squad full! Sell a player first."); return; } budget -= p.value; // When buying, always set seasonsRemaining=3 allPlayers.push(new Player(p.name, p.attack, p.defense, p.stamina, p.value, 3)); updateSquadAndBench(); updateBudgetText(); showInfo("Bought " + p.name + " for $" + p.value + "M"); // Remove from transfer list, add new transferList.splice(idx, 1, makeRandomPlayer()); refreshUI(); }; }(i); game.addChild(buyBtn); buyBtns.push(buyBtn); } } function updateOpponentLabels() { clearArray(opponentLabels); // Position opponent section at bottom-left (for reference, but now only for opponent info) var oppStartY = 2048 - (SQUAD_SIZE + 2) * 120 - 200; // increased row height and more margin for opponent section if (oppStartY < guiY + 1800) { oppStartY = guiY + 1800; } // push down if needed for more space // --- League Table: show all teams, slightly larger, and moved to the left --- // Place league tables side by side above the opponent section, below the transfer market var leagueWidth = 600; // slightly larger var leagueX = 80; // left side of the screen for League 1 var league2X = 80 + leagueWidth + 240; // move League 2 table further right for more separation var leagueY = oppStartY - 650; // place above opponent section, below transfer market if (leagueY < guiY + 600) { leagueY = guiY + 600; } // League 1 Table var leagueHeader = makeLabel("League 1 Table", leagueX, leagueY, 54, "#fdcb6e"); // slightly larger font game.addChild(leagueHeader); opponentLabels.push(leagueHeader); // Sort league by points, then goal difference, then goals for var sortedLeague = leagueTeams.slice().sort(function (a, b) { if (b.points !== a.points) { return b.points - a.points; } var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) { return gdB - gdA; } return b.goalsFor - a.goalsFor; }); for (var i = 0; i < sortedLeague.length; i++) { var team = sortedLeague[i]; // Highlight user's selected team in blue, fallback to "You" for legacy var isUserTeam = userSelectedTeam && team.name === userSelectedTeam || !userSelectedTeam && team.name === "You"; var color = isUserTeam ? "#00cec9" : "#fff"; var displayName = userSelectedTeam && team.name === userSelectedTeam ? userSelectedTeam : team.name === "You" && userSelectedTeam ? userSelectedTeam : team.name; var gd = team.goalsFor - team.goalsAgainst; var labelTxt = i + 1 + ". " + displayName + " Pts:" + team.points + " GP:" + team.played + " W:" + team.wins + " D:" + team.draws + " L:" + team.losses + " GD:" + gd; var teamLabel = makeLabel(labelTxt, leagueX, leagueY + 70 + i * 48, 38, color); // slightly larger font and spacing game.addChild(teamLabel); opponentLabels.push(teamLabel); } // League 2 Table (side by side) var league2Header = makeLabel("League 2 Table", league2X, leagueY, 54, "#b2bec3"); game.addChild(league2Header); opponentLabels.push(league2Header); var sortedLeague2 = league2Teams.slice().sort(function (a, b) { if (b.points !== a.points) { return b.points - a.points; } var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) { return gdB - gdA; } return b.goalsFor - a.goalsFor; }); for (var i = 0; i < sortedLeague2.length; i++) { var team = sortedLeague2[i]; var color = "#fff"; var gd = team.goalsFor - team.goalsAgainst; var labelTxt = i + 1 + ". " + team.name + " Pts:" + team.points + " GP:" + team.played + " W:" + team.wins + " D:" + team.draws + " L:" + team.losses + " GD:" + gd; var teamLabel = makeLabel(labelTxt, league2X, leagueY + 70 + i * 48, 38, color); game.addChild(teamLabel); opponentLabels.push(teamLabel); } // Now show opponent section below league table var t = makeLabel("Next Opponent: " + opponentTeam.name, 80, oppStartY, 56, "#fab1a0"); game.addChild(t); opponentLabels.push(t); // Reduce vertical spacing between opponent team player names to minimum without overlap var oppPlayerFontSize = 40; var oppPlayerSpacing = oppPlayerFontSize + 2; // 2px gap to avoid touching for (var i = 0; i < SQUAD_SIZE; i++) { var p = opponentTeam.players[i]; var pt = makeLabel(i + 1 + ". " + p.name + " [A:" + p.attack + " D:" + p.defense + " S:" + p.stamina + "]", 80, oppStartY + 120 + i * oppPlayerSpacing, oppPlayerFontSize, "#fff"); game.addChild(pt); opponentLabels.push(pt); } } function clearMatchText() { if (matchText) { matchText.destroy(); matchText = null; } } function showMatchLog() { clearMatchText(); var log = matchLog.join("\n"); matchText = new Text2(log, { size: 48, fill: "#fff", wordWrap: true, wordWrapWidth: 1800 }); // Position match summary directly underneath the Play Match button var playBtnX = 2048 / 2 - 200; // Same as playBtn X var playBtnY = 2048 - 200; // Same as playBtn Y matchText.x = playBtnX; matchText.y = playBtnY + 180; // 180px below Play Match button for extra separation game.addChild(matchText); } function clearAllUI() { clearArray(squadLabels); clearArray(benchLabels); clearArray(transferBtns); clearArray(buyBtns); clearArray(swapBtns); clearArray(sellBtns); clearArray(opponentLabels); // --- YOUTH ACADEMY UI --- clearArray(youthLabels); clearArray(promoteBtns); clearArray(sellYouthBtns); if (transferText) { transferText.destroy(); } transferText = null; // --- CLEAR TRANSFER OFFER UI --- clearArray(offerLabels); clearArray(acceptOfferBtns); clearArray(rejectOfferBtns); clearMatchText(); if (playBtn) { playBtn.destroy(); } playBtn = null; if (nextBtn) { nextBtn.destroy(); } nextBtn = null; } // --- LEAGUE SYSTEM --- // League teams: user + 10 Turkish clubs, now with two leagues var leagueClubNames = ["Denizlispor", "Sivasspor", "Galatasaray", "Fenerbahce", "Trabzonspor", "Besiktas", "Basaksehir", "Konyaspor", "Antalyaspor", "Alanyaspor"]; var league2ClubNames = ["Giresunspor", "Genclerbirligi", "Samsunspor", "Erzurumspor", "Manisaspor", "Bursaspor", "Altay", "Boluspor", "Adanaspor", "Bandirmaspor"]; var leagueTeams = []; // First league var league2Teams = []; // Second league var leagueFixtures = []; // [{homeIdx, awayIdx}] var league2Fixtures = []; var currentFixtureIdx = 0; var userTeamIdx = 0; // always 0 function initLeague() { // First league leagueTeams = []; leagueTeams.push({ name: "You", points: 0, played: 0, wins: 0, draws: 0, losses: 0, goalsFor: 0, goalsAgainst: 0 }); for (var i = 0; i < leagueClubNames.length; i++) { var clubName = leagueClubNames[i]; leagueTeams.push({ name: clubName, points: 0, played: 0, wins: 0, draws: 0, losses: 0, goalsFor: 0, goalsAgainst: 0, realSquad: realSquads[clubName] ? realSquads[clubName].map(function (p) { return clonePlayer(p); }) : null }); } // Second league league2Teams = []; for (var i = 0; i < league2ClubNames.length; i++) { var clubName = league2ClubNames[i]; league2Teams.push({ name: clubName, points: 0, played: 0, wins: 0, draws: 0, losses: 0, goalsFor: 0, goalsAgainst: 0, realSquad: null // No real squads for league 2 }); } // Fixtures for both leagues leagueFixtures = []; var n = leagueTeams.length; for (var i = 0; i < n; i++) { for (var j = 0; j < n; j++) { if (i !== j) { if (i < j) { leagueFixtures.push({ homeIdx: i, awayIdx: j }); leagueFixtures.push({ homeIdx: j, awayIdx: i }); } } } } // Shuffle fixtures for variety for (var k = leagueFixtures.length - 1; k > 0; k--) { var r = randomInt(0, k); var temp = leagueFixtures[k]; leagueFixtures[k] = leagueFixtures[r]; leagueFixtures[r] = temp; } currentFixtureIdx = 0; // League 2 fixtures league2Fixtures = []; var n2 = league2Teams.length; for (var i = 0; i < n2; i++) { for (var j = 0; j < n2; j++) { if (i !== j) { if (i < j) { league2Fixtures.push({ homeIdx: i, awayIdx: j }); league2Fixtures.push({ homeIdx: j, awayIdx: i }); } } } } for (var k = league2Fixtures.length - 1; k > 0; k--) { var r = randomInt(0, k); var temp = league2Fixtures[k]; league2Fixtures[k] = league2Fixtures[r]; league2Fixtures[r] = temp; } } function getCurrentOpponentIdx() { // Find the next fixture where user is home or away for (var i = currentFixtureIdx; i < leagueFixtures.length; i++) { var f = leagueFixtures[i]; if (f.homeIdx === userTeamIdx || f.awayIdx === userTeamIdx) { return f.homeIdx === userTeamIdx ? f.awayIdx : f.homeIdx; } } return null; } function getCurrentFixture() { for (var i = currentFixtureIdx; i < leagueFixtures.length; i++) { var f = leagueFixtures[i]; if (f.homeIdx === userTeamIdx || f.awayIdx === userTeamIdx) { return { idx: i, fixture: f }; } } return null; } function advanceFixture() { // Move to next user fixture for (var i = currentFixtureIdx + 1; i < leagueFixtures.length; i++) { var f = leagueFixtures[i]; if (f.homeIdx === userTeamIdx || f.awayIdx === userTeamIdx) { currentFixtureIdx = i; return; } } // No more fixtures: season over currentFixtureIdx = leagueFixtures.length; } function isSeasonOver() { // If all user fixtures played for (var i = currentFixtureIdx; i < leagueFixtures.length; i++) { var f = leagueFixtures[i]; if (f.homeIdx === userTeamIdx || f.awayIdx === userTeamIdx) { return false; } } return true; } // --- GAME LOGIC --- function simulateMatch() { matchLog = []; matchResult = null; matchInProgress = true; // --- Always spawn youth players at match start if needed --- if (youthAcademy.length < YOUTH_MAX) { var toAdd = YOUTH_MAX - youthAcademy.length; for (var i = 0; i < toAdd; i++) { // Generate a young player (attributes 1-10) var atk = randomInt(1, 10); var def = randomInt(1, 10); var sta = randomInt(1, 10); // Calculate base stat sum and average var statSum = atk + def + sta; var statAvg = Math.floor(statSum / 3); // Most players: value 1-5M, some: 6-10M, all <= 10M var val; if (Math.random() < 0.8) { val = Math.max(1, Math.min(5, statAvg + randomInt(0, 1))); } else { val = Math.max(6, Math.min(10, statAvg + randomInt(2, 4))); if (val < 6) { val = 5; } } if (val > 10) { val = 10; } var p = new Player(randomName(), atk, def, sta, val, null); youthAcademy.push(p); showInfo("A new youth player has joined your academy!"); } refreshUI(); } // Find all fixtures for this matchday (all teams play one match) if (currentFixtureIdx >= leagueFixtures.length) { matchLog.push("Season is over!"); showMatchLog(); matchInProgress = false; return; } // --- LEAGUE 1: Gather all fixtures for this matchday (each team plays once) --- var nTeams = leagueTeams.length; var matchdayFixtures = []; var teamsPlayed = {}; for (var i = currentFixtureIdx; i < leagueFixtures.length; i++) { var f = leagueFixtures[i]; if (!teamsPlayed[f.homeIdx] && !teamsPlayed[f.awayIdx]) { matchdayFixtures.push({ idx: i, fixture: f }); teamsPlayed[f.homeIdx] = true; teamsPlayed[f.awayIdx] = true; if (Object.keys(teamsPlayed).length >= nTeams) { break; } } } // --- LEAGUE 2: Gather all fixtures for this matchday (each team plays once) --- var n2Teams = league2Teams.length; var matchdayFixtures2 = []; var teamsPlayed2 = {}; for (var i = 0; i < league2Fixtures.length; i++) { var f2 = league2Fixtures[i]; if (!teamsPlayed2[f2.homeIdx] && !teamsPlayed2[f2.awayIdx]) { matchdayFixtures2.push({ idx: i, fixture: f2 }); teamsPlayed2[f2.homeIdx] = true; teamsPlayed2[f2.awayIdx] = true; if (Object.keys(teamsPlayed2).length >= n2Teams) { break; } } } // --- Simulate all matches in this matchday for LEAGUE 1 --- var userMatchIdx = -1; for (var m = 0; m < matchdayFixtures.length; m++) { var fixtureObj = matchdayFixtures[m]; var fixture = fixtureObj.fixture; var homeIdx = fixture.homeIdx; var awayIdx = fixture.awayIdx; var homeTeam = leagueTeams[homeIdx]; var awayTeam = leagueTeams[awayIdx]; // Prepare teams var homePlayers, awayPlayers; if (homeIdx === userTeamIdx) { homePlayers = squad; } else { // Use real squad if available, else generate random team if (homeTeam && Array.isArray(homeTeam.realSquad) && homeTeam.realSquad.length >= SQUAD_SIZE) { homePlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) { homePlayers.push(clonePlayer(homeTeam.realSquad[i])); } } else { homePlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) { homePlayers.push(makeRandomPlayer()); } } } if (awayIdx === userTeamIdx) { awayPlayers = squad; } else { if (awayTeam && Array.isArray(awayTeam.realSquad) && awayTeam.realSquad.length >= SQUAD_SIZE) { awayPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) { awayPlayers.push(clonePlayer(awayTeam.realSquad[i])); } } else { awayPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) { awayPlayers.push(makeRandomPlayer()); } } } // Calculate stats // Determine team strengths var homeStrength = 0; for (var i = 0; i < homePlayers.length; i++) { homeStrength += homePlayers[i].attack + homePlayers[i].defense + homePlayers[i].stamina; } var awayStrength = 0; for (var i = 0; i < awayPlayers.length; i++) { awayStrength += awayPlayers[i].attack + awayPlayers[i].defense + awayPlayers[i].stamina; } var homeGoals = 0, awayGoals = 0; // Simulate match based on strength and randomness // A simple model: higher strength means more chances to score var homeChances = Math.max(1, Math.floor(homeStrength / 30) + randomInt(-2, 2)); // Add randomness var awayChances = Math.max(1, Math.floor(awayStrength / 30) + randomInt(-2, 2)); // Add randomness for (var i = 0; i < homeChances; i++) { if (Math.random() < 0.6) { // Higher chance to score per chance homeGoals++; } } for (var i = 0; i < awayChances; i++) { if (Math.random() < 0.6) { // Higher chance to score per chance awayGoals++; } } for (var turn = 0; turn < 5; turn++) { // Home attack (for match log details) var atkP = homePlayers[turn]; var defP = awayPlayers[turn]; if (atkP && defP) { var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = defP.defense + randomInt(0, defP.stamina); if (atkChance > defChance + 3) { //homeGoals++; // Already accounted for in overall simulation } else if (defChance > atkChance + 5) { // Defensive action (for match log details) } } // Away attack (for match log details) var oAtkP = awayPlayers[turn]; var oDefP = homePlayers[turn]; if (oAtkP && oDefP) { var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3) { //awayGoals++; // Already accounted for in overall simulation } else if (oDefChance > oAtkChance + 5) { // Defensive action (for match log details) } } } // Update league table defensively if (homeTeam && awayTeam) { if (typeof homeTeam.played === "number") homeTeam.played += 1; if (typeof awayTeam.played === "number") awayTeam.played += 1; if (typeof homeTeam.goalsFor === "number") homeTeam.goalsFor += homeGoals; if (typeof homeTeam.goalsAgainst === "number") homeTeam.goalsAgainst += awayGoals; if (typeof awayTeam.goalsFor === "number") awayTeam.goalsFor += awayGoals; if (typeof awayTeam.goalsAgainst === "number") awayTeam.goalsAgainst += homeGoals; if (homeGoals > awayGoals) { if (typeof homeTeam.points === "number") homeTeam.points += 3; if (typeof homeTeam.wins === "number") homeTeam.wins += 1; if (typeof awayTeam.losses === "number") awayTeam.losses += 1; } else if (homeGoals < awayGoals) { if (typeof awayTeam.points === "number") awayTeam.points += 3; if (typeof awayTeam.wins === "number") awayTeam.wins += 1; if (typeof homeTeam.losses === "number") homeTeam.losses += 1; } else { if (typeof homeTeam.points === "number") homeTeam.points += 1; if (typeof awayTeam.points === "number") awayTeam.points += 1; if (typeof homeTeam.draws === "number") homeTeam.draws += 1; if (typeof awayTeam.draws === "number") awayTeam.draws += 1; } } // If this is the user's match, log details and handle rewards if (homeIdx === userTeamIdx || awayIdx === userTeamIdx) { userMatchIdx = m; var userGoals = homeIdx === userTeamIdx ? homeGoals : awayGoals; var oppGoals = homeIdx === userTeamIdx ? awayGoals : homeGoals; var oppIdx = homeIdx === userTeamIdx ? awayIdx : homeIdx; var oppName = leagueTeams[oppIdx] && leagueTeams[oppIdx].name ? leagueTeams[oppIdx].name : "Opponent"; for (var turn = 0; turn < 5; turn++) { // User attack var atkP = squad[turn]; var defP = homeIdx === userTeamIdx ? awayPlayers[turn] : homePlayers[turn]; if (atkP && defP) { var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = defP.defense + randomInt(0, defP.stamina); if (atkChance > defChance + 3) { matchLog.push("Minute " + (turn * 18 + 5) + ": " + atkP.name + " scores!"); } else if (defChance > atkChance + 5) { matchLog.push("Minute " + (turn * 18 + 8) + ": " + defP.name + " makes a key tackle."); } } // Opponent attack var oAtkP = homeIdx === userTeamIdx ? awayPlayers[turn] : homePlayers[turn]; var oDefP = squad[turn]; if (oAtkP && oDefP) { var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3) { matchLog.push("Minute " + (turn * 18 + 12) + ": " + oAtkP.name + " scores!"); } else if (oDefChance > oAtkChance + 5) { matchLog.push("Minute " + (turn * 18 + 15) + ": " + oDefP.name + " blocks a shot."); } } } matchLog.push("Full Time: You " + userGoals + " - " + oppGoals + " " + oppName); // Rewards if (userGoals > oppGoals) { matchResult = "win"; matchLog.push("You win! +$20M"); budget += 20; } else if (userGoals < oppGoals) { matchResult = "lose"; matchLog.push("You lose."); } else { matchResult = "draw"; matchLog.push("Draw. +$5M"); budget += 5; } } } // --- Simulate all matches in this matchday for LEAGUE 2 --- for (var m2 = 0; m2 < matchdayFixtures2.length; m2++) { var fixtureObj2 = matchdayFixtures2[m2]; var fixture2 = fixtureObj2.fixture; var homeIdx2 = fixture2.homeIdx; var awayIdx2 = fixture2.awayIdx; var homeTeam2 = league2Teams[homeIdx2]; var awayTeam2 = league2Teams[awayIdx2]; // Generate random teams for league 2 var homePlayers2 = []; var awayPlayers2 = []; for (var i2 = 0; i2 < SQUAD_SIZE; i2++) { homePlayers2.push(makeRandomPlayer()); awayPlayers2.push(makeRandomPlayer()); } // Calculate stats var homeStrength2 = 0; for (var i2 = 0; i2 < homePlayers2.length; i2++) { homeStrength2 += homePlayers2[i2].attack + homePlayers2[i2].defense + homePlayers2[i2].stamina; } var awayStrength2 = 0; for (var i2 = 0; i2 < awayPlayers2.length; i2++) { awayStrength2 += awayPlayers2[i2].attack + awayPlayers2[i2].defense + awayPlayers2[i2].stamina; } var homeGoals2 = 0, awayGoals2 = 0; var homeChances2 = Math.max(1, Math.floor(homeStrength2 / 30) + randomInt(-2, 2)); var awayChances2 = Math.max(1, Math.floor(awayStrength2 / 30) + randomInt(-2, 2)); for (var i2 = 0; i2 < homeChances2; i2++) { if (Math.random() < 0.6) { homeGoals2++; } } for (var i2 = 0; i2 < awayChances2; i2++) { if (Math.random() < 0.6) { awayGoals2++; } } // Update league 2 table homeTeam2.played += 1; awayTeam2.played += 1; homeTeam2.goalsFor += homeGoals2; homeTeam2.goalsAgainst += awayGoals2; awayTeam2.goalsFor += awayGoals2; awayTeam2.goalsAgainst += homeGoals2; if (homeGoals2 > awayGoals2) { homeTeam2.points += 3; homeTeam2.wins += 1; awayTeam2.losses += 1; } else if (homeGoals2 < awayGoals2) { awayTeam2.points += 3; awayTeam2.wins += 1; homeTeam2.losses += 1; } else { homeTeam2.points += 1; awayTeam2.points += 1; homeTeam2.draws += 1; awayTeam2.draws += 1; } } // Advance fixture pointer by number of fixtures played this matchday currentFixtureIdx += matchdayFixtures.length; // Restore stamina a bit after match for (var i = 0; i < homePlayers.length; i++) { if (homeIdx === userTeamIdx) { homePlayers[i].stamina = Math.max(0, homePlayers[i].stamina - randomInt(3, 6)); // Decrease stamina after playing homePlayers[i].stamina = Math.min(homePlayers[i].maxStamina, homePlayers[i].stamina + randomInt(1, 3)); // Partial recovery } } for (var i = 0; i < awayPlayers.length; i++) { if (awayIdx === userTeamIdx) { awayPlayers[i].stamina = Math.max(0, awayPlayers[i].stamina - randomInt(3, 6)); // Decrease stamina after playing awayPlayers[i].stamina = Math.min(awayPlayers[i].maxStamina, awayPlayers[i].stamina + randomInt(1, 3)); // Partial recovery } } updateBudgetText(); showMatchLog(); // --- CHAMPIONS LEAGUE: Simulate group/knockout matches if active and not eliminated --- if (championsLeagueActive && !championsLeagueUserEliminated) { // Only simulate if in group or knockout and not finished if (championsLeagueStage === "Group") { // Each group: 3 matchdays (user plays each team once) if (championsLeagueCurrentRound < 3) { // Find user group position var userIdx = -1; for (var i = 0; i < 4; i++) { if (championsLeagueGroup[i].name === "You") userIdx = i; } // Play user match for this round var oppIdx = (userIdx + championsLeagueCurrentRound + 1) % 4; var userTeam = championsLeagueGroup[userIdx]; var oppTeam = championsLeagueGroup[oppIdx]; // Prepare squads var userPlayers = squad; var oppPlayers = []; if (oppTeam.realSquad) { for (var i = 0; i < SQUAD_SIZE; i++) oppPlayers.push(clonePlayer(oppTeam.realSquad[i])); } else { for (var i = 0; i < SQUAD_SIZE; i++) oppPlayers.push(makeRandomPlayer()); } // Simulate match var userStrength = 0, oppStrength = 0; for (var i = 0; i < SQUAD_SIZE; i++) { userStrength += userPlayers[i].attack + userPlayers[i].defense + userPlayers[i].stamina; oppStrength += oppPlayers[i].attack + oppPlayers[i].defense + oppPlayers[i].stamina; } var userGoals = 0, oppGoals = 0; var userChances = Math.max(1, Math.floor(userStrength / 30) + randomInt(-1, 1)); var oppChances = Math.max(1, Math.floor(oppStrength / 30) + randomInt(-1, 1)); for (var i = 0; i < userChances; i++) if (Math.random() < 0.6) userGoals++; for (var i = 0; i < oppChances; i++) if (Math.random() < 0.6) oppGoals++; // Update group table for (var i = 0; i < 4; i++) { if (championsLeagueGroupResults[i].name === "You") { championsLeagueGroupResults[i].played++; championsLeagueGroupResults[i].goalsFor += userGoals; championsLeagueGroupResults[i].goalsAgainst += oppGoals; if (userGoals > oppGoals) { championsLeagueGroupResults[i].points += 3; championsLeagueGroupResults[i].wins++; } else if (userGoals < oppGoals) { championsLeagueGroupResults[i].losses++; } else { championsLeagueGroupResults[i].points += 1; championsLeagueGroupResults[i].draws++; } } if (championsLeagueGroupResults[i].name === oppTeam.name) { championsLeagueGroupResults[i].played++; championsLeagueGroupResults[i].goalsFor += oppGoals; championsLeagueGroupResults[i].goalsAgainst += userGoals; if (oppGoals > userGoals) { championsLeagueGroupResults[i].points += 3; championsLeagueGroupResults[i].wins++; } else if (oppGoals < userGoals) { championsLeagueGroupResults[i].losses++; } else { championsLeagueGroupResults[i].points += 1; championsLeagueGroupResults[i].draws++; } } } championsLeagueLog.push("Champions League Group: You " + userGoals + " - " + oppGoals + " " + oppTeam.name); if (userGoals > oppGoals) { championsLeaguePrize += 5; championsLeagueLog.push("You win! +$5M CL prize."); budget += 5; } else if (userGoals === oppGoals) { championsLeaguePrize += 2; championsLeagueLog.push("Draw. +$2M CL prize."); budget += 2; } else { championsLeagueLog.push("You lose."); } championsLeagueCurrentRound++; // After 3 rounds, check group standings if (championsLeagueCurrentRound >= 3) { // Sort group var sortedGroup = championsLeagueGroupResults.slice().sort(function (a, b) { if (b.points !== a.points) return b.points - a.points; var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) return gdB - gdA; return b.goalsFor - a.goalsFor; }); for (var i = 0; i < 4; i++) { if (sortedGroup[i].name === "You") championsLeagueUserGroupPos = i + 1; } if (championsLeagueUserGroupPos <= 2) { championsLeagueStage = "Quarterfinal"; championsLeagueCurrentRound = 0; championsLeagueLog.push("You advance to the Champions League Quarterfinals!"); } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You are eliminated from the Champions League group stage."); } } } } else if (championsLeagueStage === "Quarterfinal" && !championsLeagueUserEliminated) { // Simulate a single knockout match // Pick a random strong team as opponent var possibleOpponents = []; for (var i = 0; i < championsLeagueTeams.length; i++) { if (championsLeagueTeams[i].name !== "You") possibleOpponents.push(championsLeagueTeams[i]); } var oppTeam = possibleOpponents[randomInt(0, possibleOpponents.length - 1)]; var userPlayers = squad; var oppPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) oppPlayers.push(makeRandomPlayer()); var userStrength = 0, oppStrength = 0; for (var i = 0; i < SQUAD_SIZE; i++) { userStrength += userPlayers[i].attack + userPlayers[i].defense + userPlayers[i].stamina; oppStrength += oppPlayers[i].attack + oppPlayers[i].defense + oppPlayers[i].stamina; } var userGoals = 0, oppGoals = 0; var userChances = Math.max(1, Math.floor(userStrength / 30) + randomInt(-1, 1)); var oppChances = Math.max(1, Math.floor(oppStrength / 30) + randomInt(-1, 1)); for (var i = 0; i < userChances; i++) if (Math.random() < 0.6) userGoals++; for (var i = 0; i < oppChances; i++) if (Math.random() < 0.6) oppGoals++; championsLeagueLog.push("Champions League Quarterfinal: You " + userGoals + " - " + oppGoals + " " + oppTeam.name); if (userGoals > oppGoals) { championsLeaguePrize += 10; championsLeagueLog.push("You advance to the Semifinals! +$10M CL prize."); budget += 10; championsLeagueStage = "Semifinal"; } else if (userGoals === oppGoals) { // Penalties if (Math.random() < 0.5) { championsLeaguePrize += 10; championsLeagueLog.push("You win on penalties! +$10M CL prize."); budget += 10; championsLeagueStage = "Semifinal"; } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You lose on penalties. Eliminated from Champions League."); } } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You are eliminated from the Champions League Quarterfinals."); } } else if (championsLeagueStage === "Semifinal" && !championsLeagueUserEliminated) { // Simulate a single knockout match var possibleOpponents = []; for (var i = 0; i < championsLeagueTeams.length; i++) { if (championsLeagueTeams[i].name !== "You") possibleOpponents.push(championsLeagueTeams[i]); } var oppTeam = possibleOpponents[randomInt(0, possibleOpponents.length - 1)]; var userPlayers = squad; var oppPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) oppPlayers.push(makeRandomPlayer()); var userStrength = 0, oppStrength = 0; for (var i = 0; i < SQUAD_SIZE; i++) { userStrength += userPlayers[i].attack + userPlayers[i].defense + userPlayers[i].stamina; oppStrength += oppPlayers[i].attack + oppPlayers[i].defense + oppPlayers[i].stamina; } var userGoals = 0, oppGoals = 0; var userChances = Math.max(1, Math.floor(userStrength / 30) + randomInt(-1, 1)); var oppChances = Math.max(1, Math.floor(oppStrength / 30) + randomInt(-1, 1)); for (var i = 0; i < userChances; i++) if (Math.random() < 0.6) userGoals++; for (var i = 0; i < oppChances; i++) if (Math.random() < 0.6) oppGoals++; championsLeagueLog.push("Champions League Semifinal: You " + userGoals + " - " + oppGoals + " " + oppTeam.name); if (userGoals > oppGoals) { championsLeaguePrize += 20; championsLeagueLog.push("You advance to the Champions League Final! +$20M CL prize."); budget += 20; championsLeagueStage = "Final"; } else if (userGoals === oppGoals) { // Penalties if (Math.random() < 0.5) { championsLeaguePrize += 20; championsLeagueLog.push("You win on penalties! +$20M CL prize."); budget += 20; championsLeagueStage = "Final"; } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You lose on penalties. Eliminated from Champions League."); } } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You are eliminated from the Champions League Semifinals."); } } else if (championsLeagueStage === "Final" && !championsLeagueUserEliminated) { // Simulate final var possibleOpponents = []; for (var i = 0; i < championsLeagueTeams.length; i++) { if (championsLeagueTeams[i].name !== "You") possibleOpponents.push(championsLeagueTeams[i]); } var oppTeam = possibleOpponents[randomInt(0, possibleOpponents.length - 1)]; var userPlayers = squad; var oppPlayers = []; for (var i = 0; i < SQUAD_SIZE; i++) oppPlayers.push(makeRandomPlayer()); var userStrength = 0, oppStrength = 0; for (var i = 0; i < SQUAD_SIZE; i++) { userStrength += userPlayers[i].attack + userPlayers[i].defense + userPlayers[i].stamina; oppStrength += oppPlayers[i].attack + oppPlayers[i].defense + oppPlayers[i].stamina; } var userGoals = 0, oppGoals = 0; var userChances = Math.max(1, Math.floor(userStrength / 30) + randomInt(-1, 1)); var oppChances = Math.max(1, Math.floor(oppStrength / 30) + randomInt(-1, 1)); for (var i = 0; i < userChances; i++) if (Math.random() < 0.6) userGoals++; for (var i = 0; i < oppChances; i++) if (Math.random() < 0.6) oppGoals++; championsLeagueLog.push("Champions League Final: You " + userGoals + " - " + oppGoals + " " + oppTeam.name); if (userGoals > oppGoals) { championsLeaguePrize += 40; championsLeagueLog.push("You are Champions League Winners! +$40M CL prize and huge prestige!"); budget += 40; championsLeagueActive = false; championsLeagueUserEliminated = true; } else if (userGoals === oppGoals) { // Penalties if (Math.random() < 0.5) { championsLeaguePrize += 40; championsLeagueLog.push("You win the Champions League Final on penalties! +$40M CL prize and huge prestige!"); budget += 40; championsLeagueActive = false; championsLeagueUserEliminated = true; } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You lose the Champions League Final on penalties. Runner-up!"); } } else { championsLeagueUserEliminated = true; championsLeagueLog.push("You are runners-up in the Champions League Final."); } } } matchInProgress = false; } function refreshUI() { clearAllUI(); // Add extra vertical space between all sections by adjusting guiY and section Y positions // Squad section updateSquadLabels(); // Bench section (move further down) guiY = 0; // reset updateBenchLabels(); // Transfer section (move further down) updateTransferLabels(); // Opponent and league table section (move further down) updateOpponentLabels(); updateBudgetText(); // --- Champions League UI --- if (championsLeagueActive || championsLeagueLog.length > 0) { var clX = 80 + 2 * 600 + 240 + 200; // right of league tables var clY = guiY + 600; var clHeader = makeLabel("Champions League", clX, clY, 54, "#ffe066"); game.addChild(clHeader); var yOffset = 70; for (var i = 0; i < championsLeagueLog.length && i < 8; i++) { var clMsg = makeLabel(championsLeagueLog[championsLeagueLog.length - 1 - i], clX, clY + yOffset + i * 48, 38, "#fff"); game.addChild(clMsg); } // Show group table if in group stage if (championsLeagueActive && championsLeagueStage === "Group" && championsLeagueGroupResults.length > 0) { var groupHeader = makeLabel("CL Group Standings", clX, clY + 500, 40, "#00b894"); game.addChild(groupHeader); var sortedGroup = championsLeagueGroupResults.slice().sort(function (a, b) { if (b.points !== a.points) return b.points - a.points; var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) return gdB - gdA; return b.goalsFor - a.goalsFor; }); for (var i = 0; i < sortedGroup.length; i++) { var g = sortedGroup[i]; var isUserTeam = userSelectedTeam && g.name === userSelectedTeam || !userSelectedTeam && g.name === "You"; var color = isUserTeam ? "#00cec9" : "#fff"; var displayName = userSelectedTeam && g.name === userSelectedTeam ? userSelectedTeam : g.name === "You" && userSelectedTeam ? userSelectedTeam : g.name; var labelTxt = i + 1 + ". " + displayName + " Pts:" + g.points + " GP:" + g.played + " W:" + g.wins + " D:" + g.draws + " L:" + g.losses + " GD:" + (g.goalsFor - g.goalsAgainst); var groupLabel = makeLabel(labelTxt, clX, clY + 550 + i * 38, 32, color); game.addChild(groupLabel); } } } showInfo("Pick lineup, buy/sell, then Play Match!"); // --- YOUTH ACADEMY UI --- clearArray(youthLabels); clearArray(promoteBtns); clearArray(sellYouthBtns); // Place youth academy to the right of the buy buttons in the transfer market var youthX = 80 + 750 + 300; // sectionX + buyBtn offset + extra margin var youthY = guiY + 600; // align vertically with transfer section var youthHeader = makeLabel("Youth Academy", youthX, youthY, 54, "#81ecec"); game.addChild(youthHeader); youthLabels.push(youthHeader); for (var i = 0; i < youthAcademy.length; i++) { var yp = youthAcademy[i]; var t = makeLabel(yp.name + " [A:" + yp.attack + " D:" + yp.defense + " S:" + yp.stamina + "] $" + yp.value + "M", youthX, youthY + 70 + i * 60, 40, "#fff"); game.addChild(t); youthLabels.push(t); // Promote button var promoteBtn = makeLabel("Promote", youthX + 420, t.y, 36, "#00b894"); promoteBtn.idx = i; promoteBtn.interactive = true; promoteBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to promote."); return; } if (allPlayers.length >= SQUAD_SIZE + BENCH_SIZE) { showInfo("Squad full! Sell a player first."); return; } allPlayers.push(new Player(p.name, p.attack, p.defense, p.stamina, p.value, null)); updateSquadAndBench(); showInfo("Promoted " + p.name + " to your team!"); youthAcademy.splice(idx, 1); refreshUI(); }; }(i); game.addChild(promoteBtn); promoteBtns.push(promoteBtn); // Sell button var sellBtn = makeLabel("Sell", youthX + 600, t.y, 36, "#fdcb6e"); sellBtn.idx = i; sellBtn.interactive = true; sellBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to sell."); return; } budget += p.value; updateBudgetText(); showInfo("Sold " + p.name + " for $" + p.value + "M"); youthAcademy.splice(idx, 1); refreshUI(); }; }(i); game.addChild(sellBtn); sellYouthBtns.push(sellBtn); } // --- TRANSFER OFFERS UI (now under youth academy) --- clearArray(offerLabels); clearArray(acceptOfferBtns); clearArray(rejectOfferBtns); var offerX = youthX; var offerY = youthY + 70 + Math.max(1, youthAcademy.length) * 60 + 40; // place below youth academy if (transferOffers.length > 0) { var offerHeader = makeLabel("Transfer Offers", offerX, offerY, 54, "#fdcb6e"); game.addChild(offerHeader); offerLabels.push(offerHeader); for (var i = 0; i < transferOffers.length; i++) { var offer = transferOffers[i]; var p = offer.player; // Only show player name and offer amount, hide stats var txt = offer.club + " offers $" + offer.offerValue + "M for " + p.name; var t = makeLabel(txt, offerX, offerY + 70 + i * 60, 40, "#fff"); game.addChild(t); offerLabels.push(t); // Accept button var acceptBtn = makeLabel("Accept", offerX + 420, t.y, 36, "#00b894"); acceptBtn.idx = i; acceptBtn.interactive = true; acceptBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var offer = transferOffers[idx]; var p = offer.player; // Remove player from allPlayers, squad/bench var allIdx = allPlayers.indexOf(p); if (allIdx !== -1) { budget += offer.offerValue; allPlayers.splice(allIdx, 1); updateSquadAndBench(); updateBudgetText(); showInfo("Sold " + p.name + " to " + offer.club + " for $" + offer.offerValue + "M"); transferOffers.splice(idx, 1); refreshUI(); } else { showInfo("Player not found."); } }; }(i); game.addChild(acceptBtn); acceptOfferBtns.push(acceptBtn); // Reject button var rejectBtn = makeLabel("Reject", offerX + 600, t.y, 36, "#ff7675"); rejectBtn.idx = i; rejectBtn.interactive = true; rejectBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var offer = transferOffers[idx]; showInfo("Rejected offer for " + offer.player.name + "."); transferOffers.splice(idx, 1); refreshUI(); }; }(i); game.addChild(rejectBtn); rejectOfferBtns.push(rejectBtn); } } // --- YOUTH ACADEMY UI --- clearArray(youthLabels); clearArray(promoteBtns); clearArray(sellYouthBtns); // Place youth academy to the right of the buy buttons in the transfer market var youthX = 80 + 750 + 300; // sectionX + buyBtn offset + extra margin var youthY = guiY + 600; // align vertically with transfer section var youthHeader = makeLabel("Youth Academy", youthX, youthY, 54, "#81ecec"); game.addChild(youthHeader); youthLabels.push(youthHeader); for (var i = 0; i < youthAcademy.length; i++) { var yp = youthAcademy[i]; var t = makeLabel(yp.name + " [A:" + yp.attack + " D:" + yp.defense + " S:" + yp.stamina + "] $" + yp.value + "M", youthX, youthY + 70 + i * 60, 40, "#fff"); game.addChild(t); youthLabels.push(t); // Promote button var promoteBtn = makeLabel("Promote", youthX + 420, t.y, 36, "#00b894"); promoteBtn.idx = i; promoteBtn.interactive = true; promoteBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to promote."); return; } if (allPlayers.length >= SQUAD_SIZE + BENCH_SIZE) { showInfo("Squad full! Sell a player first."); return; } allPlayers.push(new Player(p.name, p.attack, p.defense, p.stamina, p.value, null)); updateSquadAndBench(); showInfo("Promoted " + p.name + " to your team!"); youthAcademy.splice(idx, 1); refreshUI(); }; }(i); game.addChild(promoteBtn); promoteBtns.push(promoteBtn); // Sell button var sellBtn = makeLabel("Sell", youthX + 600, t.y, 36, "#fdcb6e"); sellBtn.idx = i; sellBtn.interactive = true; sellBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to sell."); return; } budget += p.value; updateBudgetText(); showInfo("Sold " + p.name + " for $" + p.value + "M"); youthAcademy.splice(idx, 1); refreshUI(); }; }(i); game.addChild(sellBtn); sellYouthBtns.push(sellBtn); } // --- YOUTH ACADEMY GENERATION TIMER --- if (!youthTimer) { youthTimer = LK.setInterval(function () { if (youthAcademy.length < YOUTH_MAX) { // Generate a young player (attributes 1-10) var atk = randomInt(1, 10); var def = randomInt(1, 10); var sta = randomInt(1, 10); // Calculate base stat sum and average var statSum = atk + def + sta; var statAvg = Math.floor(statSum / 3); // Most players: value 1-5M, some: 6-10M, all <= 10M var val; // 80% chance for 1-5M, 20% for 6-10M (if stats are high enough) if (Math.random() < 0.8) { // Value 1-5M, based on statAvg, but never below 1M val = Math.max(1, Math.min(5, statAvg + randomInt(0, 1))); } else { // Value 6-10M, only if statAvg is high enough val = Math.max(6, Math.min(10, statAvg + randomInt(2, 4))); // If statAvg is too low, fallback to 5M if (val < 6) { val = 5; } } if (val > 10) { val = 10; } // Cap value at 10M for youth academy players var p = new Player(randomName(), atk, def, sta, val, null); youthAcademy.push(p); showInfo("A new youth player has joined your academy!"); refreshUI(); } }, YOUTH_TIMER_INTERVAL); } // --- TRANSFER OFFER GENERATION TIMER REMOVED --- // Transfer offers are now only generated at end of season, see next change_block. // Play match button (bottom middle, with extra margin from all sections) var playBtnX = 2048 / 2 - 200; // Centered horizontally, adjust for button width var playBtnY = 2048 - 200; // 200px from bottom playBtn = makeLabel("Play Match", playBtnX, playBtnY, 70, "#00cec9"); playBtn.interactive = true; playBtn.down = function (x, y, obj) { if (matchInProgress) { return; } simulateMatch(); playBtn.destroy(); playBtn = null; // Next match button (bottom middle, below Play Match) var nextBtnX = 2048 / 2 - 200; var nextBtnY = playBtnY + 120; nextBtn = makeLabel("Next Match", nextBtnX, nextBtnY, 60, "#fdcb6e"); nextBtn.interactive = true; nextBtn.down = function (x, y, obj) { // Restore stamina a bit for (var i = 0; i < allPlayers.length; i++) { allPlayers[i].stamina = Math.min(allPlayers[i].maxStamina, allPlayers[i].stamina + randomInt(1, 3)); } // Check if season is over if (isSeasonOver()) { // Calculate final league position for user var sortedLeague = leagueTeams.slice().sort(function (a, b) { if (b.points !== a.points) { return b.points - a.points; } var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) { return gdB - gdA; } return b.goalsFor - a.goalsFor; }); var userFinalPos = 1; for (var i = 0; i < sortedLeague.length; i++) { if (sortedLeague[i].name === "You") { userFinalPos = i + 1; break; } } // Prize money by position var prize = 5; if (userFinalPos === 1) { prize = 50; } else if (userFinalPos === 2) { prize = 30; } else if (userFinalPos === 3) { prize = 20; } else if (userFinalPos === 4) { prize = 10; } // Award prize budget += prize; showInfo("Season finished! You placed #" + userFinalPos + ". Prize: $" + prize + "M. Table resets for new season."); updateBudgetText(); // Decrement seasonsRemaining for transfer market players, remove those at 0 for (var i = allPlayers.length - 1; i >= 0; i--) { var p = allPlayers[i]; if (typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null) { p.seasonsRemaining--; if (p.seasonsRemaining <= 0) { allPlayers.splice(i, 1); showInfo("Player " + p.name + " has retired/left after 3 seasons."); } } } updateSquadAndBench(); // --- PROMOTION/RELEGATION LOGIC --- // Sort both leagues var sortedLeague1 = leagueTeams.slice().sort(function (a, b) { if (b.points !== a.points) { return b.points - a.points; } var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) { return gdB - gdA; } return b.goalsFor - a.goalsFor; }); var sortedLeague2 = league2Teams.slice().sort(function (a, b) { if (b.points !== a.points) { return b.points - a.points; } var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) { return gdB - gdA; } return b.goalsFor - a.goalsFor; }); // Get bottom 2 from league 1 (excluding "You"), top 2 from league 2 var relegated = []; var promoted = []; for (var i = sortedLeague1.length - 1; i >= 0 && relegated.length < 2; i--) { if (sortedLeague1[i].name !== "You") { relegated.push(sortedLeague1[i]); } } for (var i = 0; i < sortedLeague2.length && promoted.length < 2; i++) { promoted.push(sortedLeague2[i]); } // Remove relegated from league 1, add to league 2; remove promoted from league 2, add to league 1 for (var i = 0; i < relegated.length; i++) { var idx = leagueTeams.findIndex(function (t) { return t.name === relegated[i].name; }); if (idx !== -1) { var team = leagueTeams.splice(idx, 1)[0]; // Reset stats team.points = 0; team.played = 0; team.wins = 0; team.draws = 0; team.losses = 0; team.goalsFor = 0; team.goalsAgainst = 0; league2Teams.push(team); } } for (var i = 0; i < promoted.length; i++) { var idx = league2Teams.findIndex(function (t) { return t.name === promoted[i].name; }); if (idx !== -1) { var team = league2Teams.splice(idx, 1)[0]; // Reset stats team.points = 0; team.played = 0; team.wins = 0; team.draws = 0; team.losses = 0; team.goalsFor = 0; team.goalsAgainst = 0; leagueTeams.push(team); } } // --- Generate up to 3 transfer offers for squad/bench players at end of season --- transferOffers = []; var candidates = squad.concat(bench).slice(); // copy // Shuffle candidates for (var i = candidates.length - 1; i > 0; i--) { var j = randomInt(0, i); var temp = candidates[i]; candidates[i] = candidates[j]; candidates[j] = temp; } var offersToMake = Math.min(3, candidates.length); for (var i = 0; i < offersToMake; i++) { var p = candidates[i]; // Offer value: 90% to 120% of player value var offerVal = Math.floor(p.value * (randomInt(90, 120) / 100)); // Pick a random club var club = OFFER_CLUBS[randomInt(0, OFFER_CLUBS.length - 1)]; transferOffers.push({ player: p, offerValue: offerVal, club: club }); } // Only show info if there are offers if (transferOffers.length > 0) { showInfo("You have received " + transferOffers.length + " transfer offer(s) for your players!"); } // --- CHAMPIONS LEAGUE: Determine qualification and initialize tournament --- championsLeagueUserQualified = false; championsLeagueActive = false; championsLeagueUserEliminated = false; championsLeaguePrize = 0; championsLeagueLog = []; championsLeagueOpponent = null; championsLeagueStage = ""; championsLeagueGroup = []; championsLeagueGroupResults = []; championsLeagueKnockoutBracket = []; championsLeagueUserGroupPos = null; championsLeagueUserLastStage = ""; // Find top 4 in sortedLeague1 (from above) var qualifiedTeams = []; for (var i = 0; i < 4; i++) { qualifiedTeams.push(sortedLeague1[i]); if (sortedLeague1[i].name === "You") { championsLeagueUserQualified = true; } } // Add 12 more strong teams for a 16-team Champions League var extraCLTeams = [{ name: "Real Madrid", realSquad: null }, { name: "Manchester City", realSquad: null }, { name: "Bayern Munich", realSquad: null }, { name: "Barcelona", realSquad: null }, { name: "Liverpool", realSquad: null }, { name: "PSG", realSquad: null }, { name: "Juventus", realSquad: null }, { name: "Inter Milan", realSquad: null }, { name: "Chelsea", realSquad: null }, { name: "Arsenal", realSquad: null }, { name: "Atletico Madrid", realSquad: null }, { name: "Borussia Dortmund", realSquad: null }]; championsLeagueTeams = []; for (var i = 0; i < qualifiedTeams.length; i++) { championsLeagueTeams.push({ name: qualifiedTeams[i].name, realSquad: qualifiedTeams[i].realSquad ? qualifiedTeams[i].realSquad : null }); } for (var i = 0; i < extraCLTeams.length; i++) { championsLeagueTeams.push({ name: extraCLTeams[i].name, realSquad: null }); } // Shuffle for group draw for (var i = championsLeagueTeams.length - 1; i > 0; i--) { var j = randomInt(0, i); var temp = championsLeagueTeams[i]; championsLeagueTeams[i] = championsLeagueTeams[j]; championsLeagueTeams[j] = temp; } if (championsLeagueUserQualified) { championsLeagueActive = true; championsLeagueCurrentRound = 0; championsLeagueStage = "Group"; // Draw 4 groups of 4 championsLeagueGroup = []; for (var g = 0; g < 4; g++) { var group = []; for (var t = 0; t < 4; t++) { group.push(championsLeagueTeams[g * 4 + t]); } // If user is in this group, save it for (var t = 0; t < 4; t++) { if (group[t].name === "You") { championsLeagueGroup = group.slice(); } } } championsLeagueGroupResults = []; for (var i = 0; i < 4; i++) { championsLeagueGroupResults.push({ name: championsLeagueGroup[i].name, points: 0, played: 0, wins: 0, draws: 0, losses: 0, goalsFor: 0, goalsAgainst: 0 }); } championsLeagueLog.push("You have qualified for the Champions League! Group stage draw complete."); } else { championsLeagueActive = false; championsLeagueLog = []; } // Reset league and start new season initLeague(); // Do NOT reset allPlayers, squad, or bench here; keep current team for next season // Only reset transfer market for new season initTransferList(); // Set first opponent var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { // Generate new opponent team for this club opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx] && leagueTeams[oppIdx].name ? leagueTeams[oppIdx].name : "Opponent"; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // Next opponent in league var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx] && leagueTeams[oppIdx].name ? leagueTeams[oppIdx].name : "Opponent"; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); }; game.addChild(nextBtn); }; game.addChild(playBtn); } // --- INIT UI --- var currentScreen = "main"; // "main", "transfer", "league", "youth" var navBtns = []; function showScreen(screen) { currentScreen = screen; clearAllUI(); // Always show nav buttons showNavButtons(); if (screen === "main") { updateSquadLabels(); updateBenchLabels(); // Show transfer market in main updateTransferLabels(); // Show youth academy in main // --- YOUTH ACADEMY UI --- clearArray(youthLabels); clearArray(promoteBtns); clearArray(sellYouthBtns); // Place youth academy to the right of the buy buttons in the transfer market var youthX = 80 + 750 + 300; // sectionX + buyBtn offset + extra margin var youthY = guiY + 600; // align vertically with transfer section var youthHeader = makeLabel("Youth Academy", youthX, youthY, 54, "#81ecec"); game.addChild(youthHeader); youthLabels.push(youthHeader); for (var i = 0; i < youthAcademy.length; i++) { var yp = youthAcademy[i]; var t = makeLabel(yp.name + " [A:" + yp.attack + " D:" + yp.defense + " S:" + yp.stamina + "] $" + yp.value + "M", youthX, youthY + 70 + i * 60, 40, "#fff"); game.addChild(t); youthLabels.push(t); // Promote button var promoteBtn = makeLabel("Promote", youthX + 420, t.y, 36, "#00b894"); promoteBtn.idx = i; promoteBtn.interactive = true; promoteBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to promote."); return; } if (allPlayers.length >= SQUAD_SIZE + BENCH_SIZE) { showInfo("Squad full! Sell a player first."); return; } allPlayers.push(new Player(p.name, p.attack, p.defense, p.stamina, p.value, null)); updateSquadAndBench(); showInfo("Promoted " + p.name + " to your team!"); youthAcademy.splice(idx, 1); refreshUI(); }; }(i); game.addChild(promoteBtn); promoteBtns.push(promoteBtn); // Sell button var sellBtn = makeLabel("Sell", youthX + 600, t.y, 36, "#fdcb6e"); sellBtn.idx = i; sellBtn.interactive = true; sellBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to sell."); return; } budget += p.value; updateBudgetText(); showInfo("Sold " + p.name + " for $" + p.value + "M"); youthAcademy.splice(idx, 1); refreshUI(); }; }(i); game.addChild(sellBtn); sellYouthBtns.push(sellBtn); } // --- TRANSFER OFFERS UI (now under youth academy) --- clearArray(offerLabels); clearArray(acceptOfferBtns); clearArray(rejectOfferBtns); var offerX = youthX; var offerY = youthY + 70 + Math.max(1, youthAcademy.length) * 60 + 40; // place below youth academy if (transferOffers.length > 0) { var offerHeader = makeLabel("Transfer Offers", offerX, offerY, 54, "#fdcb6e"); game.addChild(offerHeader); offerLabels.push(offerHeader); for (var i = 0; i < transferOffers.length; i++) { var offer = transferOffers[i]; var p = offer.player; // Only show player name and offer amount, hide stats var txt = offer.club + " offers $" + offer.offerValue + "M for " + p.name; var t = makeLabel(txt, offerX, offerY + 70 + i * 60, 40, "#fff"); game.addChild(t); offerLabels.push(t); // Accept button var acceptBtn = makeLabel("Accept", offerX + 420, t.y, 36, "#00b894"); acceptBtn.idx = i; acceptBtn.interactive = true; acceptBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var offer = transferOffers[idx]; var p = offer.player; // Remove player from allPlayers, squad/bench var allIdx = allPlayers.indexOf(p); if (allIdx !== -1) { budget += offer.offerValue; allPlayers.splice(allIdx, 1); updateSquadAndBench(); updateBudgetText(); showInfo("Sold " + p.name + " to " + offer.club + " for $" + offer.offerValue + "M"); transferOffers.splice(idx, 1); refreshUI(); } else { showInfo("Player not found."); } }; }(i); game.addChild(acceptBtn); acceptOfferBtns.push(acceptBtn); // Reject button var rejectBtn = makeLabel("Reject", offerX + 600, t.y, 36, "#ff7675"); rejectBtn.idx = i; rejectBtn.interactive = true; rejectBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var offer = transferOffers[idx]; showInfo("Rejected offer for " + offer.player.name + "."); transferOffers.splice(idx, 1); refreshUI(); }; }(i); game.addChild(rejectBtn); rejectOfferBtns.push(rejectBtn); } } updateOpponentLabels(); updateBudgetText(); // --- Champions League UI (main screen) --- if (championsLeagueActive || championsLeagueLog.length > 0) { // If Champions League is active and there are no logs yet, show only a centered text on a blank screen if (championsLeagueActive && championsLeagueLog.length === 0) { // Clear all UI elements for a blank screen clearAllUI(); // Centered "Şampiyonlar Ligi" text var clText = new Text2("Şampiyonlar Ligi", { size: 120, fill: 0xFFE066 }); clText.anchor.set(0.5, 0.5); clText.x = 2048 / 2; clText.y = 2732 / 2; game.addChild(clText); } else { var clX = 80 + 2 * 600 + 240 + 200; // right of league tables var clY = guiY + 600; var clHeader = makeLabel("Champions League", clX, clY, 54, "#ffe066"); game.addChild(clHeader); var yOffset = 70; for (var i = 0; i < championsLeagueLog.length && i < 8; i++) { var clMsg = makeLabel(championsLeagueLog[championsLeagueLog.length - 1 - i], clX, clY + yOffset + i * 48, 38, "#fff"); game.addChild(clMsg); } // Show group table if in group stage if (championsLeagueActive && championsLeagueStage === "Group" && championsLeagueGroupResults.length > 0) { var groupHeader = makeLabel("CL Group Standings", clX, clY + 500, 40, "#00b894"); game.addChild(groupHeader); var sortedGroup = championsLeagueGroupResults.slice().sort(function (a, b) { if (b.points !== a.points) return b.points - a.points; var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) return gdB - gdA; return b.goalsFor - a.goalsFor; }); for (var i = 0; i < sortedGroup.length; i++) { var g = sortedGroup[i]; var isUserTeam = userSelectedTeam && g.name === userSelectedTeam || !userSelectedTeam && g.name === "You"; var color = isUserTeam ? "#00cec9" : "#fff"; var displayName = userSelectedTeam && g.name === userSelectedTeam ? userSelectedTeam : g.name === "You" && userSelectedTeam ? userSelectedTeam : g.name; var labelTxt = i + 1 + ". " + displayName + " Pts:" + g.points + " GP:" + g.played + " W:" + g.wins + " D:" + g.draws + " L:" + g.losses + " GD:" + (g.goalsFor - g.goalsAgainst); var groupLabel = makeLabel(labelTxt, clX, clY + 550 + i * 38, 32, color); game.addChild(groupLabel); } } } } showInfo("Pick lineup, buy/sell, then Play Match!"); // Play Match button var playBtnX = 2048 / 2 - 200; var playBtnY = 2048 - 200; playBtn = makeLabel("Play Match", playBtnX, playBtnY, 70, "#00cec9"); playBtn.interactive = true; playBtn.down = function (x, y, obj) { if (matchInProgress) { return; } simulateMatch(); playBtn.destroy(); playBtn = null; // Next match button var nextBtnX = 2048 / 2 - 200; var nextBtnY = playBtnY + 120; nextBtn = makeLabel("Next Match", nextBtnX, nextBtnY, 60, "#fdcb6e"); nextBtn.interactive = true; nextBtn.down = function (x, y, obj) { // Restore stamina a bit for (var i = 0; i < allPlayers.length; i++) { allPlayers[i].stamina = Math.min(allPlayers[i].maxStamina, allPlayers[i].stamina + randomInt(1, 3)); } // Check if season is over if (isSeasonOver()) { // Calculate final league position for user var sortedLeague = leagueTeams.slice().sort(function (a, b) { if (b.points !== a.points) { return b.points - a.points; } var gdA = a.goalsFor - a.goalsAgainst; var gdB = b.goalsFor - b.goalsAgainst; if (gdB !== gdA) { return gdB - gdA; } return b.goalsFor - a.goalsFor; }); var userFinalPos = 1; for (var i = 0; i < sortedLeague.length; i++) { if (sortedLeague[i].name === "You") { userFinalPos = i + 1; break; } } // Prize money by position var prize = 5; if (userFinalPos === 1) { prize = 50; } else if (userFinalPos === 2) { prize = 30; } else if (userFinalPos === 3) { prize = 20; } else if (userFinalPos === 4) { prize = 10; } // Award prize budget += prize; showInfo("Season finished! You placed #" + userFinalPos + ". Prize: $" + prize + "M. Table resets for new season."); updateBudgetText(); // Decrement seasonsRemaining for transfer market players, remove those at 0 for (var i = allPlayers.length - 1; i >= 0; i--) { var p = allPlayers[i]; if (typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null) { p.seasonsRemaining--; if (p.seasonsRemaining <= 0) { allPlayers.splice(i, 1); showInfo("Player " + p.name + " has retired/left after 3 seasons."); } } } updateSquadAndBench(); // --- Generate up to 3 transfer offers for squad/bench players at end of season --- transferOffers = []; var candidates = squad.concat(bench).slice(); for (var i = candidates.length - 1; i > 0; i--) { var j = randomInt(0, i); var temp = candidates[i]; candidates[i] = candidates[j]; candidates[j] = temp; } var offersToMake = Math.min(3, candidates.length); for (var i = 0; i < offersToMake; i++) { var p = candidates[i]; var offerVal = Math.floor(p.value * (randomInt(90, 120) / 100)); var club = OFFER_CLUBS[randomInt(0, OFFER_CLUBS.length - 1)]; transferOffers.push({ player: p, offerValue: offerVal, club: club }); } if (transferOffers.length > 0) { showInfo("You have received " + transferOffers.length + " transfer offer(s) for your players!"); } initLeague(); initTransferList(); var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx] && leagueTeams[oppIdx].name ? leagueTeams[oppIdx].name : "Opponent"; } clearMatchText(); nextBtn.destroy(); nextBtn = null; showScreen("main"); return; } // Next opponent in league var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx] && leagueTeams[oppIdx].name ? leagueTeams[oppIdx].name : "Opponent"; } clearMatchText(); nextBtn.destroy(); nextBtn = null; showScreen("main"); }; game.addChild(nextBtn); }; game.addChild(playBtn); } else if (screen === "transfer") { updateTransferLabels(); updateBudgetText(); showInfo("Buy top players for your team!"); } else if (screen === "league") { updateOpponentLabels(); showInfo("Check the league table and your next opponent."); } else if (screen === "youth") { // Only show youth academy and transfer offers clearArray(youthLabels); clearArray(promoteBtns); clearArray(sellYouthBtns); var youthX = 80 + 750 + 300; var youthY = guiY + 600; var youthHeader = makeLabel("Youth Academy", youthX, youthY, 54, "#81ecec"); game.addChild(youthHeader); youthLabels.push(youthHeader); for (var i = 0; i < youthAcademy.length; i++) { var yp = youthAcademy[i]; var t = makeLabel(yp.name + " [A:" + yp.attack + " D:" + yp.defense + " S:" + yp.stamina + "] $" + yp.value + "M", youthX, youthY + 70 + i * 60, 40, "#fff"); game.addChild(t); youthLabels.push(t); // Promote button var promoteBtn = makeLabel("Promote", youthX + 420, t.y, 36, "#00b894"); promoteBtn.idx = i; promoteBtn.interactive = true; promoteBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to promote."); return; } if (allPlayers.length >= SQUAD_SIZE + BENCH_SIZE) { showInfo("Squad full! Sell a player first."); return; } allPlayers.push(new Player(p.name, p.attack, p.defense, p.stamina, p.value, null)); updateSquadAndBench(); showInfo("Promoted " + p.name + " to your team!"); youthAcademy.splice(idx, 1); showScreen("youth"); }; }(i); game.addChild(promoteBtn); promoteBtns.push(promoteBtn); // Sell button var sellBtn = makeLabel("Sell", youthX + 600, t.y, 36, "#fdcb6e"); sellBtn.idx = i; sellBtn.interactive = true; sellBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var p = youthAcademy[idx]; if (!p) { showInfo("No youth player to sell."); return; } budget += p.value; updateBudgetText(); showInfo("Sold " + p.name + " for $" + p.value + "M"); youthAcademy.splice(idx, 1); showScreen("youth"); }; }(i); game.addChild(sellBtn); sellYouthBtns.push(sellBtn); } // Transfer offers clearArray(offerLabels); clearArray(acceptOfferBtns); clearArray(rejectOfferBtns); var offerX = youthX; var offerY = youthY + 70 + Math.max(1, youthAcademy.length) * 60 + 40; if (transferOffers.length > 0) { var offerHeader = makeLabel("Transfer Offers", offerX, offerY, 54, "#fdcb6e"); game.addChild(offerHeader); offerLabels.push(offerHeader); for (var i = 0; i < transferOffers.length; i++) { var offer = transferOffers[i]; var p = offer.player; var txt = offer.club + " offers $" + offer.offerValue + "M for " + p.name; var t = makeLabel(txt, offerX, offerY + 70 + i * 60, 40, "#fff"); game.addChild(t); offerLabels.push(t); // Accept button var acceptBtn = makeLabel("Accept", offerX + 420, t.y, 36, "#00b894"); acceptBtn.idx = i; acceptBtn.interactive = true; acceptBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var offer = transferOffers[idx]; var p = offer.player; var allIdx = allPlayers.indexOf(p); if (allIdx !== -1) { budget += offer.offerValue; allPlayers.splice(allIdx, 1); updateSquadAndBench(); updateBudgetText(); showInfo("Sold " + p.name + " to " + offer.club + " for $" + offer.offerValue + "M"); transferOffers.splice(idx, 1); showScreen("youth"); } else { showInfo("Player not found."); } }; }(i); game.addChild(acceptBtn); acceptOfferBtns.push(acceptBtn); // Reject button var rejectBtn = makeLabel("Reject", offerX + 600, t.y, 36, "#ff7675"); rejectBtn.idx = i; rejectBtn.interactive = true; rejectBtn.down = function (idxCopy) { return function (x, y, obj) { var idx = idxCopy; var offer = transferOffers[idx]; showInfo("Rejected offer for " + offer.player.name + "."); transferOffers.splice(idx, 1); showScreen("youth"); }; }(i); game.addChild(rejectBtn); rejectOfferBtns.push(rejectBtn); } } updateBudgetText(); showInfo("Manage your youth academy and transfer offers."); } } function showNavButtons() { clearArray(navBtns); // Button positions - move to very bottom of screen, with spacing and not touching each other or the edge var btnY = 2732 - 100; // 100px from bottom edge for safe area var btnCount = 4; var btnWidth = 320; // estimated width for button label var btnSpacing = 60; // space between buttons var sideMargin = 60; // margin from left/right edge var totalWidth = btnCount * btnWidth + (btnCount - 1) * btnSpacing; var btnXStart = Math.max(sideMargin, (2048 - totalWidth) / 2); // center all buttons horizontally, but never touch edge var btns = [{ label: "Main", screen: "main", color: 0x00CEC9 }, { label: "Transfer Market", screen: "transfer", color: 0x00B894 }, { label: "League Table", screen: "league", color: 0xFDCB6E }, { label: "Youth Academy", screen: "youth", color: 0x81ECEC }]; for (var i = 0; i < btns.length; i++) { var b = btns[i]; var btnX = btnXStart + i * (btnWidth + btnSpacing); var navBtn = makeLabel(b.label, btnX, btnY, 48, b.color); navBtn.interactive = true; navBtn.screen = b.screen; navBtn.down = function (screenName) { return function (x, y, obj) { showScreen(screenName); }; }(b.screen); game.addChild(navBtn); navBtns.push(navBtn); } } function initUI() { guiY = 0; // Title var title = new Text2("Mini Football Manager", { size: 90, fill: 0x00CEC9 }); title.x = 80; title.y = guiY + 40; game.addChild(title); // Budget budgetText = new Text2("Budget: $" + budget + "M", { size: 60, fill: "#fff" }); budgetText.x = 80; budgetText.y = guiY + 120; game.addChild(budgetText); // Info infoText = new Text2("", { size: 54, fill: 0xFDCB6E }); infoText.x = 600; infoText.y = guiY + 120; game.addChild(infoText); showScreen("main"); } // --- GAME START --- // --- TEAM SELECTION SYSTEM --- var userSelectedTeam = null; var teamSelectLabels = []; var teamSelectBtns = []; function showTeamSelectScreen() { // Remove all UI clearAllUI(); // Remove nav buttons if any clearArray(navBtns); // Hide budget/info if present if (budgetText) { budgetText.destroy(); budgetText = null; } if (infoText) { infoText.destroy(); infoText = null; } // Show nothing but team selection var title = new Text2("Takımını Seç", { size: 110, fill: 0x00CEC9 }); title.anchor.set(0.5, 0.5); title.x = 2048 / 2; title.y = 350; game.addChild(title); teamSelectLabels.push(title); // List all Super Lig teams (from realSquads) var teams = Object.keys(realSquads); var btnW = 600, btnH = 100, spacingY = 40; var totalH = teams.length * btnH + (teams.length - 1) * spacingY; var startY = (2732 - totalH) / 2 + 100; for (var i = 0; i < teams.length; i++) { var tName = teams[i]; var btn = new Text2(tName, { size: 70, fill: 0xFFE066 }); btn.anchor.set(0.5, 0.5); btn.x = 2048 / 2; btn.y = startY + i * (btnH + spacingY); btn.interactive = true; btn.teamName = tName; btn.down = function (teamName) { return function (x, y, obj) { pickTeam(teamName); }; }(tName); game.addChild(btn); teamSelectBtns.push(btn); } } function clearTeamSelectScreen() { for (var i = 0; i < teamSelectLabels.length; i++) { if (teamSelectLabels[i] && teamSelectLabels[i].destroy) teamSelectLabels[i].destroy(); } for (var i = 0; i < teamSelectBtns.length; i++) { if (teamSelectBtns[i] && teamSelectBtns[i].destroy) teamSelectBtns[i].destroy(); } teamSelectLabels = []; teamSelectBtns = []; } function pickTeam(teamName) { userSelectedTeam = teamName; clearTeamSelectScreen(); // Set user team in leagueTeams[0] and allPlayers to that squad // Re-init everything with this team newGame(true); } // Overwrite newGame to support team selection function newGame(skipTeamSelect) { if (!skipTeamSelect && !userSelectedTeam) { showTeamSelectScreen(); return; } budget = INITIAL_BUDGET; initLeague(); // If userSelectedTeam is set, use its real squad as allPlayers if (userSelectedTeam && realSquads[userSelectedTeam]) { allPlayers = []; // Copy real squad for squad for (var i = 0; i < SQUAD_SIZE; i++) { allPlayers.push(clonePlayer(realSquads[userSelectedTeam][i])); } // Fill bench with random players for (var i = 0; i < BENCH_SIZE; i++) { allPlayers.push(makeRandomPlayer()); } updateSquadAndBench(); // Remove selected team from leagueTeams (so it only appears as user's team) for (var i = leagueTeams.length - 1; i > 0; i--) { if (leagueTeams[i].name === userSelectedTeam) { leagueTeams.splice(i, 1); break; } } // Set user team name in league if (leagueTeams.length > 0) { leagueTeams[0].name = userSelectedTeam; leagueTeams[0].realSquad = realSquads[userSelectedTeam].map(function (p) { return clonePlayer(p); }); } } else { initPlayers(); // Set user team name in league if (leagueTeams.length > 0) { leagueTeams[0].name = "You"; } } initTransferList(); // --- YOUTH ACADEMY RESET --- youthAcademy = []; if (youthTimer) { LK.clearInterval(youthTimer); youthTimer = null; } // --- TRANSFER OFFERS RESET --- transferOffers = []; if (OFFER_TIMER) { LK.clearInterval(OFFER_TIMER); OFFER_TIMER = null; } clearArray(offerLabels); clearArray(acceptOfferBtns); clearArray(rejectOfferBtns); // Set first opponent in league var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx] && leagueTeams[oppIdx].name ? leagueTeams[oppIdx].name : "Opponent"; } else { opponentTeam = makeOpponentTeam(); } matchInProgress = false; matchLog = []; matchResult = null; selectedPlayerIdx = null; selectedBenchIdx = null; initUI(); } // At very first load, show team select showTeamSelectScreen(); // --- END ---
===================================================================
--- original.js
+++ change.js
@@ -420,11 +420,13 @@
});
for (var i = 0; i < sortedLeague.length; i++) {
var team = sortedLeague[i];
// Highlight user's selected team in blue, fallback to "You" for legacy
- var color = userSelectedTeam && team.name === userSelectedTeam ? "#00cec9" : team.name === "You" ? "#00cec9" : "#fff";
+ var isUserTeam = userSelectedTeam && team.name === userSelectedTeam || !userSelectedTeam && team.name === "You";
+ var color = isUserTeam ? "#00cec9" : "#fff";
+ var displayName = userSelectedTeam && team.name === userSelectedTeam ? userSelectedTeam : team.name === "You" && userSelectedTeam ? userSelectedTeam : team.name;
var gd = team.goalsFor - team.goalsAgainst;
- var labelTxt = i + 1 + ". " + team.name + " Pts:" + team.points + " GP:" + team.played + " W:" + team.wins + " D:" + team.draws + " L:" + team.losses + " GD:" + gd;
+ var labelTxt = i + 1 + ". " + displayName + " Pts:" + team.points + " GP:" + team.played + " W:" + team.wins + " D:" + team.draws + " L:" + team.losses + " GD:" + gd;
var teamLabel = makeLabel(labelTxt, leagueX, leagueY + 70 + i * 48, 38, color); // slightly larger font and spacing
game.addChild(teamLabel);
opponentLabels.push(teamLabel);
}
@@ -1268,10 +1270,12 @@
return b.goalsFor - a.goalsFor;
});
for (var i = 0; i < sortedGroup.length; i++) {
var g = sortedGroup[i];
- var color = g.name === "You" ? "#00cec9" : "#fff";
- var labelTxt = i + 1 + ". " + g.name + " Pts:" + g.points + " GP:" + g.played + " W:" + g.wins + " D:" + g.draws + " L:" + g.losses + " GD:" + (g.goalsFor - g.goalsAgainst);
+ var isUserTeam = userSelectedTeam && g.name === userSelectedTeam || !userSelectedTeam && g.name === "You";
+ var color = isUserTeam ? "#00cec9" : "#fff";
+ var displayName = userSelectedTeam && g.name === userSelectedTeam ? userSelectedTeam : g.name === "You" && userSelectedTeam ? userSelectedTeam : g.name;
+ var labelTxt = i + 1 + ". " + displayName + " Pts:" + g.points + " GP:" + g.played + " W:" + g.wins + " D:" + g.draws + " L:" + g.losses + " GD:" + (g.goalsFor - g.goalsAgainst);
var groupLabel = makeLabel(labelTxt, clX, clY + 550 + i * 38, 32, color);
game.addChild(groupLabel);
}
}
@@ -1990,10 +1994,12 @@
return b.goalsFor - a.goalsFor;
});
for (var i = 0; i < sortedGroup.length; i++) {
var g = sortedGroup[i];
- var color = g.name === "You" ? "#00cec9" : "#fff";
- var labelTxt = i + 1 + ". " + g.name + " Pts:" + g.points + " GP:" + g.played + " W:" + g.wins + " D:" + g.draws + " L:" + g.losses + " GD:" + (g.goalsFor - g.goalsAgainst);
+ var isUserTeam = userSelectedTeam && g.name === userSelectedTeam || !userSelectedTeam && g.name === "You";
+ var color = isUserTeam ? "#00cec9" : "#fff";
+ var displayName = userSelectedTeam && g.name === userSelectedTeam ? userSelectedTeam : g.name === "You" && userSelectedTeam ? userSelectedTeam : g.name;
+ var labelTxt = i + 1 + ". " + displayName + " Pts:" + g.points + " GP:" + g.played + " W:" + g.wins + " D:" + g.draws + " L:" + g.losses + " GD:" + (g.goalsFor - g.goalsAgainst);
var groupLabel = makeLabel(labelTxt, clX, clY + 550 + i * 38, 32, color);
game.addChild(groupLabel);
}
}