User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < clubNames.length; i++) {' Line Number: 165
User prompt
bütün liglerde takımların oyuncuların oyuncularını gerçektekiyle değiştir
User prompt
her ligde takımların oyuncuları gerçekteki oyuncuları olsun yedekler dahil
User prompt
Beraberlik Para ödülünü lig seviyesine göre ayarla, çoktan aza: Premier Lig, La Liga, Serie A, Bundesliga, Ligue 1, Süper Lig, Eredivisie, Liga Portugal, 2.lig, 3.lig, 4.lig
User prompt
maç kazanınca lige göre para gelsin çoktan aza Premier Lig La Liga Serie A Bundesliga Ligue 1 Süper Lig Eredivisie Liga Portugal 2.lig 3.lig 4.lig
User prompt
maç kazanınca lige göre para gelsin
User prompt
kalan maçları lig tablosunun altına koy
User prompt
ligde kalan maçları göster
User prompt
next opponent yazısını kaldır
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < clubNames.length; i++) {' Line Number: 125
User prompt
her takıma kendi kadrosunu koy
User prompt
liglerin hepsi 20 takım olsun
User prompt
bütün takımların kadrolarını 2025 kadrosu yap
User prompt
diğer liglerinde kendi lig tabloları olsun
User prompt
diğer ülkelerin liglerinide takımlarıyla ekle
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'customBtn.y = startY + clubs.length * btnSpacing + 120;' Line Number: 2315
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < clubs.length; i++) {' Line Number: 2263
User prompt
süperlig gibi diğer ligleride oynanabilir yap ve takımlarıda olsun
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'customBtn.y = startY + clubs.length * btnSpacing + 120;' Line Number: 2383
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < clubs.length; i++) {' Line Number: 2331
User prompt
süperlig gibi diğer ligleride oynanabilir yap
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < clubNames.length; i++) {' Line Number: 127
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a3d2f }); /**** * Game Code ****/ // --- CONSTANTS --- // Player class: represents a footballer 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; // --- 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, players, ...} var championsLeagueFixtures = []; // Array of {homeIdx, awayIdx} var championsLeagueCurrentRound = 0; var championsLeagueActive = false; var championsLeagueUserQualified = false; var championsLeagueLog = []; var championsLeagueResult = null; var championsLeaguePrize = 0; var championsLeagueStage = ""; // "Group", "Quarterfinal", etc. var championsLeagueOpponent = null; var championsLeagueUserPoints = 0; var championsLeagueUserGroup = []; var championsLeagueGroupResults = []; var championsLeagueKnockoutTeams = []; var championsLeagueKnockoutRound = 0; var championsLeagueKnockoutOpponent = null; var championsLeagueKnockoutLog = []; var championsLeagueKnockoutResult = null; var championsLeagueKnockoutStage = ""; var championsLeagueUserEliminated = false; // --- 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"]; // --- 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, 2. Lig, 3. Lig, 4. Lig squads (2024/25, 5 oyuncu örnek, demo) // Plus real squads for all teams in every league (not just champions) var realSquads = {}; // Helper: assign real squads for a league function assignRealSquadsForLeague(clubNames, squadArrs) { // Defensive: If clubNames is not an array or is undefined/null, do nothing if (!clubNames || typeof clubNames.length !== "number" || clubNames.length === 0) { return; } if (!clubNames || typeof clubNames.length !== "number" || clubNames.length === 0) { return; } for (var i = 0; i < clubNames.length; i++) { realSquads[clubNames[i]] = squadArrs[i]; } } // Süper Lig assignRealSquadsForLeague(leagueClubNames1, [ // Sivasspor [new Player("Rey Manaj", 15, 8, 14, 28), new Player("Clinton N'Jie", 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)], // Galatasaray [new Player("Mauro Icardi", 19, 8, 16, 42), new Player("Wilfried Zaha", 17, 7, 15, 36), new Player("Lucas Torreira", 10, 17, 17, 35), new Player("Kerem Aktürkoğlu", 16, 8, 15, 33), 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, 15, 16, 34), new Player("Sebastian Szymanski", 15, 9, 15, 32), new Player("Dominik Livakovic", 6, 17, 16, 34)], // Trabzonspor [new Player("Paul Onuachu", 16, 7, 15, 32), new Player("Edin Visca", 15, 8, 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)], // 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)], // Basaksehir [new Player("Joao Figueiredo", 14, 8, 14, 28), new Player("Leo Duarte", 8, 15, 14, 27), new Player("Serdar Gürler", 13, 8, 14, 27), new Player("Ousseynou Ba", 9, 14, 14, 26), new Player("Volkan Babacan", 6, 16, 14, 25)], // Konyaspor [new Player("Sokol Cikalleshi", 14, 8, 14, 27), new Player("Oğulcan Ülgün", 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("Adam Buksa", 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("Oğuz Aydın", 14, 8, 14, 27), new Player("Efecan Karaca", 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)]]); // 2. Lig assignRealSquadsForLeague(leagueClubNames2, [[new Player("Yasin Öztekin", 14, 8, 14, 27), new Player("Atınç Nukan", 10, 13, 14, 25), new Player("Murat Paluli", 8, 14, 14, 24), new Player("Romulo Cardoso", 15, 8, 14, 28), new Player("Arda Özçimen", 6, 16, 14, 24)], [new Player("Kabongo Kasongo", 15, 8, 14, 27), new Player("Oğuz Yıldırım", 10, 13, 14, 25), new Player("Burak Süleyman", 13, 8, 14, 27), new Player("Isaac Donkor", 8, 15, 14, 25), new Player("Cihan Topaloğlu", 6, 16, 14, 24)], [new Player("Douglas Tanque", 15, 8, 14, 27), new Player("Mehmet Taş", 10, 13, 14, 25), new Player("Berat Altındiş", 13, 8, 14, 27), new Player("Ali Keten", 8, 15, 14, 25), new Player("Korcan Çelikay", 6, 16, 14, 24)], [new Player("Umut Nayir", 15, 8, 14, 27), new Player("Caner Erkin", 10, 13, 14, 25), new Player("Halil Akbunar", 13, 8, 14, 27), new Player("Alpaslan Öztürk", 8, 15, 14, 25), new Player("Harun Tekin", 6, 16, 14, 24)], [new Player("Gökdeniz Bayrakdar", 14, 8, 14, 27), new Player("Erkan Değişmez", 10, 13, 14, 25), new Player("Celal Dumanlı", 13, 8, 14, 27), new Player("Samet Yalçın", 8, 15, 14, 25), new Player("Diogo Sousa", 6, 16, 14, 24)], [new Player("Barış Alıcı", 14, 8, 14, 27), new Player("Rahmetullah Berişbek", 10, 13, 14, 25), new Player("Gökhan Gül", 13, 8, 14, 27), new Player("Arda Kızıldağ", 8, 15, 14, 25), new Player("Ramazan Köse", 6, 16, 14, 24)], [new Player("Eren Tozlu", 14, 8, 14, 27), new Player("Orhan Ovacıklı", 10, 13, 14, 25), new Player("Murat Uçar", 13, 8, 14, 27), new Player("Aykut Demir", 8, 15, 14, 25), new Player("Göktuğ Bakırbaş", 6, 16, 14, 24)], [new Player("Berk Yıldız", 14, 8, 14, 27), new Player("Ali Keten", 10, 13, 14, 25), new Player("Gökhan Sazdağı", 13, 8, 14, 27), new Player("Uğur Akdemir", 8, 15, 14, 25), new Player("Çağlar Şahin Akbaba", 6, 16, 14, 24)], [new Player("Doğan Can Davas", 14, 8, 14, 27), new Player("Sergen Piçinciol", 10, 13, 14, 25), new Player("Okan Alkan", 13, 8, 14, 27), new Player("Emre Batuhan Adıgüzel", 8, 15, 14, 25), new Player("Gökhan Değirmenci", 6, 16, 14, 24)]]); // 3. Lig assignRealSquadsForLeague(leagueClubNames3, [[new Player("Özgür Göktaş", 13, 8, 13, 22), new Player("Mehmet Sıddık İstemi", 12, 9, 13, 21), new Player("Sinan Akaydın", 11, 10, 13, 21), new Player("Mert Somay", 10, 11, 13, 20), new Player("Cemal Doğan", 9, 12, 13, 20)], [new Player("Okan Deniz", 13, 8, 13, 22), new Player("Mehmet Yiğit", 12, 9, 13, 21), new Player("Fatih Üge", 11, 10, 13, 21), new Player("Emre Okur", 10, 11, 13, 20), new Player("Murat Yılmaz", 9, 12, 13, 20)], [new Player("İsmail Haktan Odabaşı", 13, 8, 13, 22), new Player("Onur Demir", 12, 9, 13, 21), new Player("Mert Efe Çölbeyi", 11, 10, 13, 21), new Player("Ali Kılıç", 10, 11, 13, 20), new Player("Yusuf Emre Kasal", 9, 12, 13, 20)], [new Player("Mehmet Sıddık İstemi", 13, 8, 13, 22), new Player("Sinan Akaydın", 12, 9, 13, 21), new Player("Mert Somay", 11, 10, 13, 21), new Player("Cemal Doğan", 10, 11, 13, 20), new Player("Özgür Göktaş", 9, 12, 13, 20)], [new Player("Fatih Üge", 13, 8, 13, 22), new Player("Emre Okur", 12, 9, 13, 21), new Player("Murat Yılmaz", 11, 10, 13, 21), new Player("Okan Deniz", 10, 11, 13, 20), new Player("Mehmet Yiğit", 9, 12, 13, 20)], [new Player("Onur Demir", 13, 8, 13, 22), new Player("Mert Efe Çölbeyi", 12, 9, 13, 21), new Player("Ali Kılıç", 11, 10, 13, 21), new Player("Yusuf Emre Kasal", 10, 11, 13, 20), new Player("İsmail Haktan Odabaşı", 9, 12, 13, 20)], [new Player("Sinan Akaydın", 13, 8, 13, 22), new Player("Mert Somay", 12, 9, 13, 21), new Player("Cemal Doğan", 11, 10, 13, 21), new Player("Özgür Göktaş", 10, 11, 13, 20), new Player("Mehmet Sıddık İstemi", 9, 12, 13, 20)], [new Player("Emre Okur", 13, 8, 13, 22), new Player("Murat Yılmaz", 12, 9, 13, 21), new Player("Okan Deniz", 11, 10, 13, 21), new Player("Mehmet Yiğit", 10, 11, 13, 20), new Player("Fatih Üge", 9, 12, 13, 20)], [new Player("Mert Efe Çölbeyi", 13, 8, 13, 22), new Player("Ali Kılıç", 12, 9, 13, 21), new Player("Yusuf Emre Kasal", 11, 10, 13, 21), new Player("İsmail Haktan Odabaşı", 10, 11, 13, 20), new Player("Onur Demir", 9, 12, 13, 20)]]); // 4. Lig assignRealSquadsForLeague(leagueClubNames4, [[new Player("Fatih Taşdelen", 12, 8, 12, 18), new Player("Mustafa Aşan", 11, 9, 12, 17), new Player("Hüseyin Yılmaz", 10, 10, 12, 17), new Player("Ali Say", 9, 11, 12, 16), new Player("Mehmet Yılmaz", 8, 12, 12, 16)], [new Player("Okan Duran", 12, 8, 12, 18), new Player("Emre Özkan", 11, 9, 12, 17), new Player("Burak Aydın", 10, 10, 12, 17), new Player("Serkan Balcı", 9, 11, 12, 16), new Player("Murat Akın", 8, 12, 12, 16)], [new Player("Mehmet Yılmaz", 12, 8, 12, 18), new Player("Ali Say", 11, 9, 12, 17), new Player("Fatih Taşdelen", 10, 10, 12, 17), new Player("Mustafa Aşan", 9, 11, 12, 16), new Player("Hüseyin Yılmaz", 8, 12, 12, 16)], [new Player("Burak Aydın", 12, 8, 12, 18), new Player("Serkan Balcı", 11, 9, 12, 17), new Player("Murat Akın", 10, 10, 12, 17), new Player("Okan Duran", 9, 11, 12, 16), new Player("Emre Özkan", 8, 12, 12, 16)], [new Player("Ali Say", 12, 8, 12, 18), new Player("Fatih Taşdelen", 11, 9, 12, 17), new Player("Mustafa Aşan", 10, 10, 12, 17), new Player("Hüseyin Yılmaz", 9, 11, 12, 16), new Player("Mehmet Yılmaz", 8, 12, 12, 16)], [new Player("Serkan Balcı", 12, 8, 12, 18), new Player("Murat Akın", 11, 9, 12, 17), new Player("Okan Duran", 10, 10, 12, 17), new Player("Emre Özkan", 9, 11, 12, 16), new Player("Burak Aydın", 8, 12, 12, 16)], [new Player("Fatih Taşdelen", 12, 8, 12, 18), new Player("Mustafa Aşan", 11, 9, 12, 17), new Player("Hüseyin Yılmaz", 10, 10, 12, 17), new Player("Ali Say", 9, 11, 12, 16), new Player("Mehmet Yılmaz", 8, 12, 12, 16)], [new Player("Emre Özkan", 12, 8, 12, 18), new Player("Burak Aydın", 11, 9, 12, 17), new Player("Serkan Balcı", 10, 10, 12, 17), new Player("Murat Akın", 9, 11, 12, 16), new Player("Okan Duran", 8, 12, 12, 16)], [new Player("Mustafa Aşan", 12, 8, 12, 18), new Player("Hüseyin Yılmaz", 11, 9, 12, 17), new Player("Mehmet Yılmaz", 10, 10, 12, 17), new Player("Fatih Taşdelen", 9, 11, 12, 16), new Player("Ali Say", 8, 12, 12, 16)]]); // Premier League (England) assignRealSquadsForLeague(leagueClubNamesEngland, [[new Player("Erling Haaland", 21, 10, 18, 170), new Player("Phil Foden", 17, 13, 17, 130), new Player("Kevin De Bruyne", 17, 14, 16, 120), new Player("Rodri", 14, 18, 17, 120), new Player("Ederson", 6, 18, 16, 90)], [new Player("Bukayo Saka", 17, 12, 17, 120), new Player("Martin Ødegaard", 16, 13, 16, 100), new Player("Declan Rice", 13, 17, 17, 100), new Player("William Saliba", 9, 18, 16, 80), new Player("Gabriel Jesus", 16, 10, 15, 85)], [new Player("Mohamed Salah", 19, 10, 16, 110), new Player("Virgil van Dijk", 8, 19, 16, 90), new Player("Alisson Becker", 6, 18, 16, 80), new Player("Trent Alexander-Arnold", 13, 15, 15, 85), new Player("Luis Díaz", 16, 10, 15, 80)], [new Player("Enzo Fernández", 14, 14, 16, 80), new Player("Raheem Sterling", 16, 10, 15, 75), new Player("Reece James", 12, 15, 15, 75), new Player("Christopher Nkunku", 17, 11, 15, 85), new Player("Robert Sánchez", 6, 16, 15, 60)], [new Player("Bruno Fernandes", 16, 12, 16, 90), new Player("Marcus Rashford", 17, 10, 16, 90), new Player("Casemiro", 12, 16, 16, 80), new Player("Lisandro Martínez", 9, 17, 15, 75), new Player("André Onana", 6, 16, 15, 60)], [new Player("Heung-Min Son", 19, 11, 17, 110), new Player("James Maddison", 15, 12, 15, 80), new Player("Cristian Romero", 9, 17, 15, 75), new Player("Dejan Kulusevski", 15, 10, 15, 70), new Player("Guglielmo Vicario", 6, 16, 15, 60)], [new Player("Alexander Isak", 16, 10, 15, 80), new Player("Bruno Guimarães", 14, 14, 16, 80), new Player("Sven Botman", 9, 17, 15, 70), new Player("Kieran Trippier", 12, 15, 15, 70), new Player("Nick Pope", 6, 16, 15, 60)], [new Player("Ollie Watkins", 16, 10, 15, 75), new Player("Douglas Luiz", 13, 14, 15, 70), new Player("Emiliano Martínez", 6, 17, 15, 65), new Player("John McGinn", 13, 12, 15, 65), new Player("Leon Bailey", 15, 10, 15, 65)], [new Player("Kaoru Mitoma", 15, 10, 15, 70), new Player("Pascal Groß", 13, 13, 15, 65), new Player("Lewis Dunk", 9, 16, 15, 65), new Player("Pervis Estupiñán", 12, 14, 15, 65), new Player("Bart Verbruggen", 6, 15, 15, 60)], // The rest: fill with randoms for demo [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()]]); // Bundesliga (Germany) assignRealSquadsForLeague(leagueClubNamesGermany, [[new Player("Jamal Musiala", 17, 12, 17, 120), new Player("Harry Kane", 20, 10, 16, 100), new Player("Joshua Kimmich", 14, 15, 16, 100), new Player("Leroy Sané", 17, 10, 16, 95), new Player("Manuel Neuer", 6, 19, 16, 90)], [new Player("Julian Brandt", 15, 12, 15, 80), new Player("Niclas Füllkrug", 16, 10, 15, 75), new Player("Mats Hummels", 8, 17, 15, 70), new Player("Emre Can", 13, 14, 15, 70), new Player("Gregor Kobel", 6, 16, 15, 65)], [new Player("Dani Olmo", 15, 12, 15, 75), new Player("Loïs Openda", 16, 10, 15, 75), new Player("Willi Orbán", 9, 17, 15, 70), new Player("Xaver Schlager", 13, 14, 15, 70), new Player("Janis Blaswich", 6, 16, 15, 65)], [new Player("Florian Wirtz", 16, 12, 17, 110), new Player("Victor Boniface", 16, 10, 15, 75), new Player("Jonathan Tah", 9, 17, 15, 70), new Player("Granit Xhaka", 13, 14, 15, 70), new Player("Lukáš Hrádecký", 6, 16, 15, 65)], [new Player("Mario Götze", 14, 13, 15, 70), new Player("Omar Marmoush", 15, 10, 15, 70), new Player("Robin Koch", 9, 16, 15, 65), new Player("Sebastian Rode", 13, 14, 15, 65), new Player("Kevin Trapp", 6, 16, 15, 60)], [new Player("Kevin Behrens", 15, 10, 15, 70), new Player("Robin Gosens", 13, 14, 15, 70), new Player("Danilho Doekhi", 9, 16, 15, 65), new Player("Rani Khedira", 13, 14, 15, 65), new Player("Frederik Rønnow", 6, 16, 15, 60)], [new Player("Vincenzo Grifo", 15, 12, 15, 70), new Player("Michael Gregoritsch", 16, 10, 15, 70), new Player("Matthias Ginter", 9, 17, 15, 65), new Player("Nicolas Höfler", 13, 14, 15, 65), new Player("Noah Atubolu", 6, 16, 15, 60)], [new Player("Jonas Wind", 16, 10, 15, 70), new Player("Maxence Lacroix", 9, 17, 15, 65), new Player("Mattias Svanberg", 13, 14, 15, 65), new Player("Patrick Wimmer", 15, 12, 15, 65), new Player("Koen Casteels", 6, 16, 15, 60)], [new Player("Serhou Guirassy", 17, 10, 15, 75), new Player("Waldemar Anton", 9, 17, 15, 65), new Player("Chris Führich", 15, 12, 15, 65), new Player("Enzo Millot", 13, 14, 15, 65), new Player("Alexander Nübel", 6, 16, 15, 60)]]); // La Liga (Spain) assignRealSquadsForLeague(leagueClubNamesSpain, [[new Player("Vinícius Júnior", 19, 12, 18, 150), new Player("Jude Bellingham", 18, 14, 18, 150), new Player("Rodrygo", 16, 10, 16, 100), new Player("Toni Kroos", 14, 15, 15, 90), new Player("Thibaut Courtois", 7, 19, 16, 90)], [new Player("Robert Lewandowski", 20, 9, 15, 100), new Player("Pedri", 15, 13, 17, 100), new Player("Gavi", 14, 14, 16, 90), new Player("Jules Koundé", 10, 17, 15, 80), new Player("Marc-André ter Stegen", 6, 18, 16, 80)], [new Player("Antoine Griezmann", 17, 12, 16, 90), new Player("Álvaro Morata", 16, 10, 15, 80), new Player("Koke", 13, 14, 15, 75), new Player("José Giménez", 9, 17, 15, 75), new Player("Jan Oblak", 6, 18, 16, 80)], [new Player("Youssef En-Nesyri", 16, 10, 15, 75), new Player("Ivan Rakitić", 14, 13, 15, 70), new Player("Marcos Acuña", 13, 14, 15, 70), new Player("Nemanja Gudelj", 9, 17, 15, 65), new Player("Marko Dmitrović", 6, 16, 15, 60)], [new Player("Mikel Oyarzabal", 15, 12, 15, 70), new Player("Takefusa Kubo", 15, 10, 15, 70), new Player("Robin Le Normand", 9, 17, 15, 65), new Player("Mikel Merino", 13, 14, 15, 65), new Player("Álex Remiro", 6, 16, 15, 60)], [new Player("Gerard Moreno", 16, 10, 15, 70), new Player("Dani Parejo", 14, 13, 15, 70), new Player("Pau Torres", 9, 17, 15, 65), new Player("Álex Baena", 13, 14, 15, 65), new Player("Pepe Reina", 6, 16, 15, 60)], [new Player("Nabil Fekir", 15, 12, 15, 70), new Player("Borja Iglesias", 16, 10, 15, 70), new Player("Guido Rodríguez", 13, 14, 15, 65), new Player("William Carvalho", 13, 14, 15, 65), new Player("Claudio Bravo", 6, 16, 15, 60)], [new Player("Iñaki Williams", 16, 10, 15, 70), new Player("Oihan Sancet", 15, 12, 15, 70), new Player("Yeray Álvarez", 9, 17, 15, 65), new Player("Dani Vivian", 13, 14, 15, 65), new Player("Unai Simón", 6, 16, 15, 60)], [new Player("Hugo Duro", 15, 10, 15, 65), new Player("José Gayà", 13, 14, 15, 65), new Player("Gabriel Paulista", 9, 17, 15, 65), new Player("André Almeida", 13, 14, 15, 65), new Player("Giorgi Mamardashvili", 6, 16, 15, 60)]]); // Ligue 1 (France) assignRealSquadsForLeague(leagueClubNamesFrance, [[new Player("Kylian Mbappé", 20, 12, 19, 180), new Player("Ousmane Dembélé", 17, 10, 16, 90), new Player("Achraf Hakimi", 13, 15, 16, 90), new Player("Marquinhos", 10, 17, 16, 90), new Player("Gianluigi Donnarumma", 6, 18, 16, 90)], [new Player("Pierre-Emerick Aubameyang", 17, 10, 15, 80), new Player("Mattéo Guendouzi", 13, 14, 15, 70), new Player("Jonathan Clauss", 13, 14, 15, 70), new Player("Samuel Gigot", 9, 17, 15, 65), new Player("Pau López", 6, 16, 15, 60)], [new Player("Alexandre Lacazette", 17, 10, 15, 80), new Player("Corentin Tolisso", 13, 14, 15, 70), new Player("Nicolás Tagliafico", 13, 14, 15, 70), new Player("Dejan Lovren", 9, 17, 15, 65), new Player("Anthony Lopes", 6, 16, 15, 60)], [new Player("Wissam Ben Yedder", 17, 10, 15, 80), new Player("Youssouf Fofana", 13, 14, 15, 70), new Player("Axel Disasi", 13, 14, 15, 70), new Player("Guillermo Maripán", 9, 17, 15, 65), new Player("Philipp Köhn", 6, 16, 15, 60)], [new Player("Jonathan David", 17, 10, 15, 80), new Player("Benjamin André", 13, 14, 15, 70), new Player("José Fonte", 13, 14, 15, 70), new Player("Tiago Djaló", 9, 17, 15, 65), new Player("Lucas Chevalier", 6, 16, 15, 60)], [new Player("Martin Terrier", 16, 10, 15, 75), new Player("Benjamin Bourigeaud", 13, 14, 15, 70), new Player("Arthur Theate", 13, 14, 15, 70), new Player("Warmed Omari", 9, 17, 15, 65), new Player("Steve Mandanda", 6, 16, 15, 60)], [new Player("Gaëtan Laborde", 16, 10, 15, 75), new Player("Khephren Thuram", 13, 14, 15, 70), new Player("Jean-Clair Todibo", 13, 14, 15, 70), new Player("Dante", 9, 17, 15, 65), new Player("Kasper Schmeichel", 6, 16, 15, 60)], [new Player("Florian Sotoca", 16, 10, 15, 75), new Player("Seko Fofana", 13, 14, 15, 70), new Player("Kevin Danso", 13, 14, 15, 70), new Player("Facundo Medina", 9, 17, 15, 65), new Player("Brice Samba", 6, 16, 15, 60)], [new Player("Ludovic Blas", 15, 10, 15, 70), new Player("Andrei Girotto", 13, 14, 15, 65), new Player("Nicolas Pallois", 9, 17, 15, 65), new Player("Pedro Chirivella", 13, 14, 15, 65), new Player("Alban Lafont", 6, 16, 15, 60)]]); // Serie A (Italy) assignRealSquadsForLeague(leagueClubNamesItaly, [[new Player("Lautaro Martínez", 18, 11, 16, 95), new Player("Hakan Çalhanoğlu", 15, 13, 16, 80), new Player("Nicolò Barella", 14, 14, 16, 80), new Player("Federico Dimarco", 13, 13, 15, 75), new Player("Yann Sommer", 7, 18, 15, 70)], [new Player("Dusan Vlahovic", 17, 10, 15, 90), new Player("Federico Chiesa", 16, 10, 15, 85), new Player("Adrien Rabiot", 13, 14, 15, 80), new Player("Gleison Bremer", 9, 17, 15, 75), new Player("Wojciech Szczęsny", 6, 16, 15, 70)], [new Player("Rafael Leão", 18, 10, 16, 90), new Player("Olivier Giroud", 17, 10, 15, 85), new Player("Theo Hernández", 13, 14, 15, 80), new Player("Fikayo Tomori", 9, 17, 15, 75), new Player("Mike Maignan", 7, 19, 15, 75)], [new Player("Victor Osimhen", 19, 10, 17, 110), new Player("Khvicha Kvaratskhelia", 17, 11, 16, 90), new Player("Piotr Zieliński", 14, 13, 15, 80), new Player("Giovanni Di Lorenzo", 13, 14, 15, 80), new Player("Alex Meret", 6, 16, 15, 70)], [new Player("Paulo Dybala", 17, 10, 15, 85), new Player("Lorenzo Pellegrini", 14, 13, 15, 80), new Player("Chris Smalling", 9, 17, 15, 75), new Player("Bryan Cristante", 13, 14, 15, 75), new Player("Rui Patrício", 6, 16, 15, 70)], [new Player("Ciro Immobile", 17, 10, 15, 85), new Player("Sergej Milinković-Savić", 15, 13, 16, 80), new Player("Luis Alberto", 14, 13, 15, 80), new Player("Alessio Romagnoli", 9, 17, 15, 75), new Player("Ivan Provedel", 6, 16, 15, 70)], [new Player("Duván Zapata", 17, 10, 15, 80), new Player("Teun Koopmeiners", 14, 13, 15, 75), new Player("Marten de Roon", 13, 14, 15, 75), new Player("Giorgio Scalvini", 9, 17, 15, 70), new Player("Juan Musso", 6, 16, 15, 65)], [new Player("Nicolás González", 16, 10, 15, 75), new Player("Giacomo Bonaventura", 14, 13, 15, 70), new Player("Cristiano Biraghi", 13, 14, 15, 70), new Player("Nikola Milenković", 9, 17, 15, 65), new Player("Pietro Terracciano", 6, 16, 15, 60)], [new Player("Antonio Sanabria", 16, 10, 15, 70), new Player("Nikola Vlašić", 14, 13, 15, 65), new Player("Alessandro Buongiorno", 9, 17, 15, 65), new Player("Samuele Ricci", 13, 14, 15, 65), new Player("Vanja Milinković-Savić", 6, 16, 15, 60)]]); // Eredivisie (Netherlands) assignRealSquadsForLeague(leagueClubNamesNetherlands, [[new Player("Luuk de Jong", 16, 8, 15, 60), new Player("Joey Veerman", 14, 12, 15, 55), new Player("Johan Bakayoko", 15, 10, 15, 55), new Player("Olivier Boscagli", 10, 15, 15, 50), new Player("Walter Benítez", 7, 17, 15, 50)], [new Player("Steven Bergwijn", 16, 10, 15, 75), new Player("Brian Brobbey", 15, 10, 15, 70), new Player("Steven Berghuis", 14, 13, 15, 70), new Player("Jurrien Timber", 9, 17, 15, 65), new Player("Gerónimo Rulli", 6, 16, 15, 60)], [new Player("Santiago Giménez", 16, 10, 15, 75), new Player("Orkun Kökçü", 14, 13, 15, 70), new Player("David Hancko", 9, 17, 15, 65), new Player("Mats Wieffer", 13, 14, 15, 65), new Player("Justin Bijlow", 6, 16, 15, 60)], [new Player("Vangelis Pavlidis", 16, 10, 15, 70), new Player("Jordy Clasie", 14, 13, 15, 65), new Player("Bruno Martins Indi", 9, 17, 15, 65), new Player("Dani de Wit", 13, 14, 15, 65), new Player("Mathew Ryan", 6, 16, 15, 60)], [new Player("Ricky van Wolfswinkel", 16, 10, 15, 70), new Player("Ramiz Zerrouki", 14, 13, 15, 65), new Player("Robin Pröpper", 9, 17, 15, 65), new Player("Michal Sadílek", 13, 14, 15, 65), new Player("Lars Unnerstall", 6, 16, 15, 60)], [new Player("Anastasios Douvikas", 16, 10, 15, 70), new Player("Jens Toornstra", 14, 13, 15, 65), new Player("Nick Viergever", 9, 17, 15, 65), new Player("Sander van de Streek", 13, 14, 15, 65), new Player("Vasilis Barkas", 6, 16, 15, 60)], [new Player("Sydney van Hooijdonk", 16, 10, 15, 70), new Player("Pelle van Amersfoort", 14, 13, 15, 65), new Player("Sven van Beek", 9, 17, 15, 65), new Player("Thom Haye", 13, 14, 15, 65), new Player("Andries Noppert", 6, 16, 15, 60)], [new Player("Jørgen Strand Larsen", 16, 10, 15, 70), new Player("Michael de Leeuw", 14, 13, 15, 65), new Player("Bart van Hintum", 9, 17, 15, 65), new Player("Daleho Irandust", 13, 14, 15, 65), new Player("Peter Leeuwenburgh", 6, 16, 15, 60)], [new Player("Nikolai Baden Frederiksen", 16, 10, 15, 70), new Player("Riechedly Bazoer", 14, 13, 15, 65), new Player("Danilho Doekhi", 9, 17, 15, 65), new Player("Matus Bero", 13, 14, 15, 65), new Player("Markus Schubert", 6, 16, 15, 60)]]); // Primeira Liga (Portugal) assignRealSquadsForLeague(leagueClubNamesPortugal, [[new Player("Rafa Silva", 16, 12, 16, 60), new Player("João Mário", 14, 13, 15, 55), new Player("Ángel Di María", 15, 10, 15, 55), new Player("Nicolás Otamendi", 10, 15, 15, 50), new Player("Anatoliy Trubin", 7, 17, 15, 50)], [new Player("Mehdi Taremi", 17, 10, 15, 80), new Player("Otávio", 14, 13, 15, 75), new Player("Pepe", 9, 17, 15, 70), new Player("Mateus Uribe", 13, 14, 15, 70), new Player("Diogo Costa", 6, 16, 15, 65)], [new Player("Pedro Gonçalves", 16, 10, 15, 75), new Player("Gonçalo Inácio", 14, 13, 15, 70), new Player("Sebastián Coates", 9, 17, 15, 70), new Player("Manuel Ugarte", 13, 14, 15, 70), new Player("Antonio Adán", 6, 16, 15, 65)], [new Player("Ricardo Horta", 16, 10, 15, 75), new Player("Abel Ruiz", 14, 13, 15, 70), new Player("Vítor Tormena", 9, 17, 15, 70), new Player("Al Musrati", 13, 14, 15, 70), new Player("Matheus", 6, 16, 15, 65)], [new Player("André Silva", 16, 10, 15, 70), new Player("Tiago Silva", 14, 13, 15, 65), new Player("Toni Borevkovic", 9, 17, 15, 65), new Player("Mikel Villanueva", 13, 14, 15, 65), new Player("Bruno Varela", 6, 16, 15, 60)], [new Player("Yusupha Njie", 16, 10, 15, 70), new Player("Gustavo Sauer", 14, 13, 15, 65), new Player("Rodrigo Abascal", 9, 17, 15, 65), new Player("Sebastián Pérez", 13, 14, 15, 65), new Player("Rafael Bracali", 6, 16, 15, 60)], [new Player("André Franco", 16, 10, 15, 70), new Player("João Gamboa", 14, 13, 15, 65), new Player("Lucas Áfrico", 9, 17, 15, 65), new Player("Francisco Geraldes", 13, 14, 15, 65), new Player("Daniel Figueira", 6, 16, 15, 60)], [new Player("Simon Banza", 16, 10, 15, 70), new Player("Iván Jaime", 14, 13, 15, 65), new Player("Riccieli", 9, 17, 15, 65), new Player("Gustavo Assunção", 13, 14, 15, 65), new Player("Luiz Júnior", 6, 16, 15, 60)], [new Player("Clayton", 16, 10, 15, 70), new Player("Lucas Soares", 14, 13, 15, 65), new Player("Fernando Varela", 9, 17, 15, 65), new Player("Afonso Taira", 13, 14, 15, 65), new Player("Ricardo Batista", 6, 16, 15, 60)]]); function makeOpponentTeam() { // List of realistic Turkish club names for all leagues var clubNames = leagueClubNames1 && leagueClubNames2 && leagueClubNames3 && leagueClubNames4 ? leagueClubNames1.concat(leagueClubNames2, leagueClubNames3, leagueClubNames4) : []; // Defensive: If clubNames is not an array or is empty, fallback to a default if (!clubNames || typeof clubNames.length !== "number" || clubNames.length === 0) { clubNames = ["Default FC"]; } // 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(12, 17); var val = Math.floor((atk + def + sta) / 3) + randomInt(PLAYER_MIN_VALUE + 2, PLAYER_MIN_VALUE + 10); allPlayers.push(new Player(randomName(), atk, def, sta, val)); } updateSquadAndBench(); } function updateSquadAndBench() { squad = []; bench = []; for (var i = 0; i < allPlayers.length; i++) { 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), // Added players: new Player("Rafa Silva", 16, 12, 16, 60), new Player("Ferdi Kadıoğlu", 13, 15, 16, 55), // More top players: new Player("Kevin De Bruyne", 17, 14, 16, 120), new Player("Mohamed Salah", 19, 10, 16, 110), new Player("Robert Lewandowski", 20, 9, 15, 100), new Player("Bernardo Silva", 15, 14, 16, 95), new Player("Lautaro Martínez", 18, 11, 16, 95), new Player("Jadon Sancho", 16, 11, 15, 85), new Player("Trent Alexander-Arnold", 13, 15, 15, 85), new Player("Jules Koundé", 10, 17, 15, 80), new Player("Mike Maignan", 7, 19, 15, 75), new Player("João Cancelo", 13, 15, 15, 80), new Player("Frenkie de Jong", 14, 14, 16, 90), new Player("Christopher Nkunku", 17, 11, 15, 85), new Player("Kai Havertz", 16, 12, 15, 80), new Player("Rúben Dias", 9, 18, 15, 85), new Player("Alphonso Davies", 13, 15, 16, 90), new Player("Eduardo Camavinga", 13, 14, 16, 80), new Player("Mason Mount", 15, 12, 15, 75), new Player("Milinković-Savić", 15, 13, 16, 80), new Player("Nicolo Barella", 14, 14, 16, 80), // Superstar additions: new Player("Cristiano Ronaldo", 20, 8, 15, 90), new Player("Lionel Messi", 19, 9, 16, 90)]; // 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]; var seasonsTxt = p && typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null ? " (" + p.seasonsRemaining + "s)" : ""; var t = makeLabel(i + 1 + ". " + (p ? p.name : "N/A") + " [A:" + (p ? p.attack : "-") + " D:" + (p ? p.defense : "-") + " S:" + (p ? 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 table just above the opponent section, but below the transfer market var leagueWidth = 600; // slightly larger var leagueX = 80; // move to the left side of the screen var leagueY = oppStartY - 650; // place above opponent section, below transfer market if (leagueY < guiY + 600) { leagueY = guiY + 600; } var leagueHeader = makeLabel("League 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]; var color = selectedTeamName && team.name === selectedTeamName ? "#00cec9" : "#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, leagueX, leagueY + 70 + i * 48, 38, color); // slightly larger font and spacing 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); // --- Champions League group/knockout matches: show to the right of the league table --- var clX = leagueX + leagueWidth + 80; // right of league table var clY = leagueY; if (championsLeagueActive || championsLeagueUserEliminated || championsLeagueLog && championsLeagueLog.length > 0 || championsLeagueGroupResults && championsLeagueGroupResults.length > 0) { var clHeader = makeLabel("Şampiyonlar Ligi", clX, clY, 54, "#00b894"); game.addChild(clHeader); opponentLabels.push(clHeader); // Show group stage table if in group or just finished group if (championsLeagueStage === "Group" && championsLeagueUserGroup && championsLeagueUserGroup.length === 4 && championsLeagueGroupResults && championsLeagueGroupResults.length === 4) { var groupTableY = clY + 70; var groupHeader = makeLabel("Grup Tablosu", clX, groupTableY, 40, "#fff"); game.addChild(groupHeader); opponentLabels.push(groupHeader); // Sort by points, then goal diff, then goals for var sortedGroup = championsLeagueGroupResults.slice().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; }); for (var i = 0; i < sortedGroup.length; i++) { var team = sortedGroup[i]; var color = selectedTeamName && team.name === selectedTeamName ? "#00cec9" : "#fff"; var gd = team.gf - team.ga; var labelTxt = i + 1 + ". " + team.name + " Pts:" + team.points + " GF:" + team.gf + " GA:" + team.ga + " GD:" + gd; var teamLabel = makeLabel(labelTxt, clX, groupTableY + 50 + i * 40, 32, color); game.addChild(teamLabel); opponentLabels.push(teamLabel); } groupTableY += 50 + 4 * 40 + 20; // Show next group match info if not finished if (championsLeagueCurrentRound <= 3 && championsLeagueOpponent) { var nextOpp = makeLabel("Sonraki Grup Rakibi: " + championsLeagueOpponent.name, clX, groupTableY, 36, "#fdcb6e"); game.addChild(nextOpp); opponentLabels.push(nextOpp); } } // Show knockout stage info if in semifinals or final if ((championsLeagueStage === "Semifinal" || championsLeagueStage === "Final") && championsLeagueKnockoutOpponent) { var koY = clY + 320; var stageTxt = championsLeagueStage === "Semifinal" ? "Yarı Final" : "Final"; var koHeader = makeLabel("ŞL " + stageTxt, clX, koY, 40, "#fff"); game.addChild(koHeader); opponentLabels.push(koHeader); var oppName = championsLeagueKnockoutOpponent.name; var oppLabel = makeLabel("Rakip: " + oppName, clX, koY + 50, 36, "#fdcb6e"); game.addChild(oppLabel); opponentLabels.push(oppLabel); } // Show last Champions League match results (from log) if (showMatchLog._shownCLLogs && showMatchLog._shownCLLogs.length > 0) { var logY = clY + 500; var logHeader = makeLabel("ŞL Sonuçları", clX, logY, 36, "#00b894"); game.addChild(logHeader); opponentLabels.push(logHeader); var shownLogs = showMatchLog._shownCLLogs.slice(-5); // show last 5 for (var i = 0; i < shownLogs.length; i++) { var logLine = makeLabel(shownLogs[i], clX, logY + 40 + i * 32, 28, "#fff"); game.addChild(logLine); opponentLabels.push(logLine); } } } // Opponent team player display removed as per requirements } function clearMatchText() { if (matchText) { matchText.destroy(); matchText = null; } } function showMatchLog() { clearMatchText(); // League log only 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); // --- Champions League summary: show in a separate area, never repeat --- // Remove any previous CL summary if (showMatchLog._clText && showMatchLog._clText.destroy) { showMatchLog._clText.destroy(); showMatchLog._clText = null; } // Only show if there are new CL results to show (and not already shown) if (championsLeagueLog && championsLeagueLog.length > 0) { // Show CL summary at top right, away from league log var clText = new Text2("=== Şampiyonlar Ligi ===\n" + championsLeagueLog.join("\n"), { size: 48, fill: 0x00B894, wordWrap: true, wordWrapWidth: 900 }); clText.x = 1200; clText.y = 120; game.addChild(clText); showMatchLog._clText = clText; // Mark CL log as shown so it won't be shown again // Instead of clearing the log immediately, keep a record of shown matches if (!showMatchLog._shownCLLogs) showMatchLog._shownCLLogs = []; for (var i = 0; i < championsLeagueLog.length; i++) { showMatchLog._shownCLLogs.push(championsLeagueLog[i]); } championsLeagueLog = []; } } 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 --- // 1. Lig (Süper Lig), 2. Lig, 3. Lig, 4. Lig takımları var leagueClubNames1 = ["Sivasspor", "Galatasaray", "Fenerbahce", "Trabzonspor", "Besiktas", "Basaksehir", "Konyaspor", "Antalyaspor", "Alanyaspor"]; var leagueClubNames2 = ["Göztepe", "Sakaryaspor", "Kocaelispor", "Eyüpspor", "Bodrumspor", "Gençlerbirliği", "Erzurumspor", "Boluspor", "Bandırmaspor"]; var leagueClubNames3 = ["Amedspor", "Inegölspor", "Afjet Afyonspor", "Diyarbekirspor", "Kırklarelispor", "Serik Belediyespor", "Kırşehir FK", "Nazilli Belediyespor", "Zonguldak Kömürspor"]; var leagueClubNames4 = ["Karşıyaka", "Bucaspor", "Erokspor", "Şanlıurfaspor", "Kastamonuspor", "Adıyaman FK", "Batman Petrolspor", "Somaspor", "Düzcespor"]; // --- OTHER COUNTRIES' LEAGUES (EXAMPLES) --- var leagueClubNamesEngland = ["Manchester City", "Arsenal", "Liverpool", "Chelsea", "Manchester United", "Tottenham", "Newcastle", "Aston Villa", "Brighton", "West Ham United", "Crystal Palace", "Fulham", "Wolverhampton", "Everton", "Brentford", "Bournemouth", "Nottingham Forest", "Burnley", "Sheffield United", "Luton Town"]; var leagueClubNamesGermany = ["Bayern Munich", "Borussia Dortmund", "RB Leipzig", "Bayer Leverkusen", "Eintracht Frankfurt", "Union Berlin", "Freiburg", "Wolfsburg", "Stuttgart"]; var leagueClubNamesSpain = ["Real Madrid", "Barcelona", "Atletico Madrid", "Sevilla", "Real Sociedad", "Villarreal", "Real Betis", "Athletic Bilbao", "Valencia"]; var leagueClubNamesFrance = ["Paris SG", "Marseille", "Lyon", "Monaco", "Lille", "Rennes", "Nice", "Lens", "Nantes"]; var leagueClubNamesItaly = ["Inter", "Juventus", "Milan", "Napoli", "Roma", "Lazio", "Atalanta", "Fiorentina", "Torino"]; var leagueClubNamesNetherlands = ["PSV", "Ajax", "Feyenoord", "AZ Alkmaar", "Twente", "Utrecht", "Heerenveen", "Groningen", "Vitesse"]; var leagueClubNamesPortugal = ["Benfica", "Porto", "Sporting CP", "Braga", "Guimaraes", "Boavista", "Estoril", "Famalicao", "Casa Pia"]; // By default, start in 1. Lig. Set this to 2 to start in 2. Lig, 3 for 3. Lig, 4 for 4. Lig, 101+ for other countries var currentLeagueLevel = 1; // 1 = Süper Lig, 2 = 2. Lig, 3 = 3. Lig, 4 = 4. Lig, 101 = England, 102 = Germany, etc. // This will be set to leagueClubNames1, leagueClubNames2, leagueClubNames3, leagueClubNames4, or a foreign league var leagueClubNames = leagueClubNames1; var leagueTeams = []; // [{name, points, played, wins, draws, losses, goalsFor, goalsAgainst}] var leagueFixtures = []; // [{homeIdx, awayIdx}] var currentFixtureIdx = 0; var userTeamIdx = 0; // always 0 function initLeague() { leagueTeams = []; // Use correct league club names for current division var clubs; if (currentLeagueLevel === 1) { clubs = leagueClubNames1; } else if (currentLeagueLevel === 2) { clubs = leagueClubNames2; } else if (currentLeagueLevel === 3) { clubs = leagueClubNames3; } else if (currentLeagueLevel === 4) { clubs = leagueClubNames4; } else { clubs = leagueClubNames1; } for (var i = 0; i < clubs.length; i++) { var clubName = clubs[i]; leagueTeams.push({ name: clubName, points: 0, played: 0, wins: 0, draws: 0, losses: 0, goalsFor: 0, goalsAgainst: 0, // Attach real squad if available for league simulation realSquad: realSquads[clubName] ? realSquads[clubName].map(function (p) { return clonePlayer(p); }) : null }); } // Generate fixtures: each team plays every other team twice (home/away), skip empty matches leagueFixtures = []; var n = leagueTeams.length; for (var i = 0; i < n; i++) { for (var j = 0; j < n; j++) { if (i !== j) { // Only add each pair twice (home/away) if (i < j) { // Only add if both teams have a name (not empty/undefined) if (leagueTeams[i].name && leagueTeams[j].name) { 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; } 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; // --- CHAMPIONS LEAGUE: Simulate group/knockout matches if active and not eliminated --- if (championsLeagueActive && !championsLeagueUserEliminated) { // Champions League structure: 8 teams, 2 groups of 4, top 2 advance to semifinals, then final if (championsLeagueCurrentRound === 0) { // Group draw championsLeagueUserGroup = []; championsLeagueGroupResults = []; // Split into 2 groups of 4 var groupA = championsLeagueTeams.slice(0, 4); var groupB = championsLeagueTeams.slice(4, 8); // Find which group user is in var userGroup = null; for (var i = 0; i < 4; i++) { if (selectedTeamName && groupA[i].name === selectedTeamName) userGroup = groupA; if (selectedTeamName && groupB[i].name === selectedTeamName) userGroup = groupB; } championsLeagueUserGroup = userGroup; championsLeagueGroupResults = []; for (var i = 0; i < 4; i++) { championsLeagueGroupResults.push({ name: userGroup[i].name, points: 0, gf: 0, ga: 0 }); } championsLeagueCurrentRound = 1; championsLeagueStage = "Group"; championsLeagueUserPoints = 0; championsLeagueLog = []; } // Group stage: 3 rounds, each user group team plays each other once if (championsLeagueStage === "Group" && championsLeagueCurrentRound <= 3) { // Find user group var group = championsLeagueUserGroup; var userIdx = -1; for (var i = 0; i < 4; i++) if (selectedTeamName && group[i].name === selectedTeamName) userIdx = i; // Play next group match for user var oppIdx = (championsLeagueCurrentRound - 1 + userIdx) % 4; if (oppIdx === userIdx) oppIdx = (oppIdx + 1) % 4; var opp = group[oppIdx]; championsLeagueOpponent = opp; // Simulate match var userGoals = 0, oppGoals = 0; for (var turn = 0; turn < 5; turn++) { var atkP = squad[turn]; var defP = opp.players[turn]; var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = 0; if (defP && typeof defP.defense === "number" && typeof defP.stamina === "number") { defChance = defP.defense + randomInt(0, defP.stamina); } else { // fallback: use average defense/stamina or 0 defChance = 10 + randomInt(0, 10); } if (atkChance > defChance + 3) userGoals++; var oAtkP = opp.players[turn]; var oDefP = squad[turn]; var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3) oppGoals++; } // Update group table for (var i = 0; i < 4; i++) { if (selectedTeamName && championsLeagueGroupResults[i].name === selectedTeamName) { championsLeagueGroupResults[i].gf += userGoals; championsLeagueGroupResults[i].ga += oppGoals; if (userGoals > oppGoals) championsLeagueGroupResults[i].points += 3;else if (userGoals === oppGoals) championsLeagueGroupResults[i].points += 1; } if (championsLeagueGroupResults[i].name === opp.name) { championsLeagueGroupResults[i].gf += oppGoals; championsLeagueGroupResults[i].ga += userGoals; if (oppGoals > userGoals) championsLeagueGroupResults[i].points += 3;else if (userGoals === oppGoals) championsLeagueGroupResults[i].points += 1; } } championsLeagueLog.push("Champions League Group Match: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + opp.name); if (userGoals > oppGoals) championsLeagueLog.push((selectedTeamName || "You") + " win! +$10M prestige bonus");else if (userGoals === oppGoals) championsLeagueLog.push("Draw. +$3M prestige bonus");else championsLeagueLog.push((selectedTeamName || "You") + " lose."); budget += userGoals > oppGoals ? 10 : userGoals === oppGoals ? 3 : 0; championsLeagueCurrentRound++; if (championsLeagueCurrentRound > 3) { // Group stage over, check if user advances championsLeagueGroupResults.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; }); var userPos = 1; for (var i = 0; i < 4; i++) if (selectedTeamName && championsLeagueGroupResults[i].name === selectedTeamName) userPos = i + 1; if (userPos <= 2) { championsLeagueStage = "Semifinal"; championsLeagueKnockoutTeams = [championsLeagueGroupResults[0].name, championsLeagueGroupResults[1].name]; championsLeagueKnockoutRound = 1; championsLeagueLog.push((selectedTeamName || "You") + " advance to the Champions League Semifinals!"); } else { championsLeagueActive = false; championsLeagueUserEliminated = true; championsLeagueLog.push((selectedTeamName || "You") + " are eliminated from the Champions League group stage."); } } } else if (championsLeagueStage === "Semifinal" && championsLeagueKnockoutRound === 1) { // Find opponent from other group var otherGroup = []; for (var i = 0; i < championsLeagueTeams.length; i++) { var t = championsLeagueTeams[i]; var inUserGroup = false; for (var j = 0; j < 4; j++) if (championsLeagueUserGroup[j].name === t.name) inUserGroup = true; if (!inUserGroup) otherGroup.push(t); } // Find top 2 from other group var otherGroupResults = []; for (var i = 0; i < 4; i++) { otherGroupResults.push({ name: otherGroup[i].name, points: 0, gf: 0, ga: 0 }); } // Simulate other group (random for now) for (var r = 0; r < 3; r++) { for (var i = 0; i < 4; i++) { var a = otherGroup[i]; var b = otherGroup[(i + r + 1) % 4]; var aGoals = randomInt(0, 4), bGoals = randomInt(0, 4); for (var k = 0; k < 4; k++) { if (otherGroupResults[k].name === a.name) { otherGroupResults[k].gf += aGoals; otherGroupResults[k].ga += bGoals; if (aGoals > bGoals) otherGroupResults[k].points += 3;else if (aGoals === bGoals) otherGroupResults[k].points += 1; } if (otherGroupResults[k].name === b.name) { otherGroupResults[k].gf += bGoals; otherGroupResults[k].ga += aGoals; if (bGoals > aGoals) otherGroupResults[k].points += 3;else if (aGoals === bGoals) otherGroupResults[k].points += 1; } } } } otherGroupResults.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; }); // User plays 1st of other group if user was 2nd, else 2nd var userPos = 1; for (var i = 0; i < 2; i++) if (selectedTeamName && championsLeagueKnockoutTeams[i] === selectedTeamName) userPos = i + 1; var oppName = userPos === 1 ? otherGroupResults[1].name : otherGroupResults[0].name; var opp = null; for (var i = 0; i < championsLeagueTeams.length; i++) if (championsLeagueTeams[i].name === oppName) opp = championsLeagueTeams[i]; championsLeagueKnockoutOpponent = opp; // Simulate match var userGoals = 0, oppGoals = 0; for (var turn = 0; turn < 5; turn++) { var atkP = squad[turn]; var defP = opp.players[turn]; var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = 0; if (defP && typeof defP.defense === "number" && typeof defP.stamina === "number") { defChance = defP.defense + randomInt(0, defP.stamina); } else { defChance = 10 + randomInt(0, 10); } if (atkChance > defChance + 3) userGoals++; var oAtkP = opp.players[turn]; var oDefP = squad[turn]; var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3) oppGoals++; } championsLeagueLog.push("Champions League Semifinal: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + opp.name); if (userGoals > oppGoals) { championsLeagueLog.push((selectedTeamName || "You") + " win! " + (selectedTeamName || "You") + " advance to the Champions League Final! +$20M bonus"); budget += 20; championsLeagueStage = "Final"; championsLeagueKnockoutRound = 2; } else if (userGoals === oppGoals) { championsLeagueLog.push("Draw. Decided by coin toss..."); if (randomInt(0, 1) === 0) { championsLeagueLog.push((selectedTeamName || "You") + " win the toss! " + (selectedTeamName || "You") + " advance to the Final! +$20M bonus"); budget += 20; championsLeagueStage = "Final"; championsLeagueKnockoutRound = 2; } else { championsLeagueLog.push((selectedTeamName || "You") + " lose the toss. Eliminated in Semifinal."); championsLeagueActive = false; championsLeagueUserEliminated = true; } } else { championsLeagueLog.push((selectedTeamName || "You") + " lose. Eliminated in Semifinal."); championsLeagueActive = false; championsLeagueUserEliminated = true; } } else if (championsLeagueStage === "Final" && championsLeagueKnockoutRound === 2) { // Find other finalist var otherFinalist = null; for (var i = 0; i < championsLeagueTeams.length; i++) { var t = championsLeagueTeams[i]; if (selectedTeamName && t.name !== selectedTeamName && t.name !== championsLeagueKnockoutOpponent.name) { otherFinalist = t; break; } } if (!otherFinalist) { // Pick random otherFinalist = championsLeagueTeams[randomInt(0, championsLeagueTeams.length - 1)]; } championsLeagueKnockoutOpponent = otherFinalist; // Simulate match var userGoals = 0, oppGoals = 0; for (var turn = 0; turn < 5; turn++) { var atkP = squad[turn]; var defP = otherFinalist.players[turn]; var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = 0; if (defP && typeof defP.defense === "number" && typeof defP.stamina === "number") { defChance = defP.defense + randomInt(0, defP.stamina); } else { defChance = 10 + randomInt(0, 10); } if (atkChance > defChance + 3) userGoals++; var oAtkP = otherFinalist.players[turn]; var oDefP = squad[turn]; var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3) oppGoals++; } championsLeagueLog.push("Champions League Final: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + otherFinalist.name); if (userGoals > oppGoals) { championsLeagueLog.push((selectedTeamName || "You") + " are Champions League Winners! +$50M and huge prestige!"); budget += 50; championsLeagueActive = false; championsLeagueUserEliminated = true; } else if (userGoals === oppGoals) { championsLeagueLog.push("Draw. Decided by coin toss..."); if (randomInt(0, 1) === 0) { championsLeagueLog.push((selectedTeamName || "You") + " win the toss! " + (selectedTeamName || "You") + " are Champions League Winners! +$50M and huge prestige!"); budget += 50; championsLeagueActive = false; championsLeagueUserEliminated = true; } else { championsLeagueLog.push((selectedTeamName || "You") + " lose the toss. Runners-up in the Champions League."); championsLeagueActive = false; championsLeagueUserEliminated = true; } } else { championsLeagueLog.push((selectedTeamName || "You") + " lose. Runners-up in the Champions League."); championsLeagueActive = false; championsLeagueUserEliminated = true; } } } // Find all fixtures for this matchday (all teams play one match) if (currentFixtureIdx >= leagueFixtures.length) { matchLog.push("Season is over!"); showMatchLog(); matchInProgress = false; return; } // 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; } } } // Simulate all matches in this matchday 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.realSquad) { 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.realSquad) { 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 var homeGoals = 0, awayGoals = 0; for (var turn = 0; turn < 5; turn++) { // Home attack var atkP = homePlayers[turn]; var defP = awayPlayers[turn]; var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = defP.defense + randomInt(0, defP.stamina); if (atkChance > defChance + 3) { homeGoals++; } // Away attack var oAtkP = awayPlayers[turn]; var oDefP = homePlayers[turn]; var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3) { awayGoals++; } } // Update league table homeTeam.played += 1; awayTeam.played += 1; homeTeam.goalsFor += homeGoals; homeTeam.goalsAgainst += awayGoals; awayTeam.goalsFor += awayGoals; awayTeam.goalsAgainst += homeGoals; if (homeGoals > awayGoals) { homeTeam.points += 3; homeTeam.wins += 1; awayTeam.losses += 1; } else if (homeGoals < awayGoals) { awayTeam.points += 3; awayTeam.wins += 1; homeTeam.losses += 1; } else { homeTeam.points += 1; awayTeam.points += 1; homeTeam.draws += 1; 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].name; // Track actual goals for user and opponent for correct log var userScored = 0; var oppScored = 0; for (var turn = 0; turn < 5; turn++) { // User attack var atkP = squad[turn]; var defP = homeIdx === userTeamIdx ? awayPlayers[turn] : homePlayers[turn]; var atkChance = atkP.attack + randomInt(0, atkP.stamina); var defChance = defP.defense + randomInt(0, defP.stamina); if (atkChance > defChance + 3 && userScored < (homeIdx === userTeamIdx ? homeGoals : awayGoals)) { matchLog.push("Minute " + (turn * 18 + 5) + ": " + atkP.name + " scores!"); userScored++; } 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]; var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina); var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina); if (oAtkChance > oDefChance + 3 && oppScored < (homeIdx === userTeamIdx ? awayGoals : homeGoals)) { matchLog.push("Minute " + (turn * 18 + 12) + ": " + oAtkP.name + " scores!"); oppScored++; } else if (oDefChance > oAtkChance + 5) { matchLog.push("Minute " + (turn * 18 + 15) + ": " + oDefP.name + " blocks a shot."); } } matchLog.push("Full Time: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + oppName); // Rewards if (userGoals > oppGoals) { matchResult = "win"; matchLog.push((selectedTeamName || "You") + " win! +$20M"); budget += 20; } else if (userGoals < oppGoals) { matchResult = "lose"; matchLog.push((selectedTeamName || "You") + " lose."); } else { matchResult = "draw"; matchLog.push("Draw. +$5M"); budget += 5; } } } // Advance fixture pointer by number of fixtures played this matchday currentFixtureIdx += matchdayFixtures.length; updateBudgetText(); showMatchLog(); matchInProgress = false; // If Champions League is active and not eliminated, and there are more CL matches to play, only show one CL match result at a time if (championsLeagueActive && !championsLeagueUserEliminated) { // Only auto-play next CL match if a flag is set (to prevent showing the same match again) if (!simulateMatch._justPlayedCL) { // Group stage: play next group match if not finished if (championsLeagueStage === "Group" && championsLeagueCurrentRound <= 3) { // Set flag so next simulateMatch call doesn't immediately repeat simulateMatch._justPlayedCL = true; LK.setTimeout(function () { simulateMatch._justPlayedCL = false; simulateMatch(); }, 1200); } // Semifinal: if just finished, and now in Final, auto-play Final else if (championsLeagueStage === "Final" && championsLeagueKnockoutRound === 2) { simulateMatch._justPlayedCL = true; LK.setTimeout(function () { simulateMatch._justPlayedCL = false; simulateMatch(); }, 1200); } } } } function refreshUI() { clearAllUI(); // Remove any previous CL summary if present (in case of UI refresh) if (showMatchLog._clText && showMatchLog._clText.destroy) { showMatchLog._clText.destroy(); showMatchLog._clText = null; } // 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) // Always update opponentTeam to match the next fixture before updating UI var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { if (!opponentTeam || opponentTeam.name !== leagueTeams[oppIdx].name) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } } updateOpponentLabels(); updateBudgetText(); 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!"); // Do NOT call refreshUI here to avoid screen reset } }, 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; } // --- Limit to at most 1 Champions League match per Play Match button press --- if (championsLeagueActive && !championsLeagueUserEliminated) { simulateMatch._justPlayedCL = true; } 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 (selectedTeamName && sortedLeague[i].name === selectedTeamName) { 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(); // 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 QUALIFICATION --- // Sadece 1. olan takım ve diğer liglerin şampiyonları gitsin championsLeagueUserQualified = false; var leagueChampionName = sortedLeague[0].name; // --- PROMOTION/DEMOTION SYSTEM --- // Küme düşme ve üst lige çıkma sistemi // 4. Lig'de 1. bitiren kullanıcı üst lige çıkar if (currentLeagueLevel === 4 && selectedTeamName && leagueChampionName === selectedTeamName) { showInfo("Tebrikler! 4. Lig'i kazandınız ve 3. Lig'e yükseldiniz!"); currentLeagueLevel = 3; leagueClubNames = leagueClubNames3; // Reset league for 3. Lig initLeague(); // Place user team in 3. Lig if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // 4. Lig'den 3. Lig'e çıkan kullanıcı, 3. Lig'den sonuncu olan takımla yer değiştirir var lig3LastIdx = leagueTeams.length - 1; var relegatedTeamName = leagueTeams[lig3LastIdx].name; // 4. Lig listesine düşen takımı ekle if (leagueClubNames4.indexOf(relegatedTeamName) === -1) { leagueClubNames4.push(relegatedTeamName); } // Kullanıcı takımını 4. Lig listesinden çıkar var userIdxIn4 = leagueClubNames4.indexOf(selectedTeamName); if (userIdxIn4 !== -1) { leagueClubNames4.splice(userIdxIn4, 1); } // 3. Lig listesinden düşen takımı çıkar var relegatedIdxIn3 = leagueClubNames3.indexOf(relegatedTeamName); if (relegatedIdxIn3 !== -1) { leagueClubNames3.splice(relegatedIdxIn3, 1); } // Kullanıcı takımını 3. Lig listesine ekle if (leagueClubNames3.indexOf(selectedTeamName) === -1) { leagueClubNames3.push(selectedTeamName); } initTransferList(); var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // 3. Lig'de 1. bitiren kullanıcı üst lige çıkar if (currentLeagueLevel === 3 && selectedTeamName && leagueChampionName === selectedTeamName) { showInfo("Tebrikler! 3. Lig'i kazandınız ve 2. Lig'e yükseldiniz!"); currentLeagueLevel = 2; leagueClubNames = leagueClubNames2; // Reset league for 2. Lig initLeague(); // Place user team in 2. Lig if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // 3. Lig'den 2. Lig'e çıkan kullanıcı, 2. Lig'den sonuncu olan takımla yer değiştirir var lig2LastIdx = leagueTeams.length - 1; var relegatedTeamName = leagueTeams[lig2LastIdx].name; // 3. Lig listesine düşen takımı ekle if (leagueClubNames3.indexOf(relegatedTeamName) === -1) { leagueClubNames3.push(relegatedTeamName); } // Kullanıcı takımını 3. Lig listesinden çıkar var userIdxIn3 = leagueClubNames3.indexOf(selectedTeamName); if (userIdxIn3 !== -1) { leagueClubNames3.splice(userIdxIn3, 1); } // 2. Lig listesinden düşen takımı çıkar var relegatedIdxIn2 = leagueClubNames2.indexOf(relegatedTeamName); if (relegatedIdxIn2 !== -1) { leagueClubNames2.splice(relegatedIdxIn2, 1); } // Kullanıcı takımını 2. Lig listesine ekle if (leagueClubNames2.indexOf(selectedTeamName) === -1) { leagueClubNames2.push(selectedTeamName); } initTransferList(); var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // 2. Lig'de 1. bitiren kullanıcı üst lige çıkar if (currentLeagueLevel === 2 && selectedTeamName && leagueChampionName === selectedTeamName) { showInfo("Tebrikler! 2. Lig'i kazandınız ve Süper Lig'e yükseldiniz!"); currentLeagueLevel = 1; leagueClubNames = leagueClubNames1; // Reset league for Süper Lig initLeague(); // Place user team in Süper Lig if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // 2. Lig'den Süper Lig'e çıkan kullanıcı, Süper Lig'den sonuncu olan takımla yer değiştirir // Süper Lig'den sonuncu olan takım 2. Lig'e düşer // Sadece gerçek takımlar arasında değişim yapılır, kullanıcı takımı hariç var superLigLastIdx = leagueTeams.length - 1; var relegatedTeamName = leagueTeams[superLigLastIdx].name; // 2. Lig'e düşen takım, 2. Lig listesine eklenir if (leagueClubNames2.indexOf(relegatedTeamName) === -1) { leagueClubNames2.push(relegatedTeamName); } // Kullanıcı takımı 2. Lig listesinden çıkarılır (eğer varsa) var userIdxIn2 = leagueClubNames2.indexOf(selectedTeamName); if (userIdxIn2 !== -1) { leagueClubNames2.splice(userIdxIn2, 1); } // Süper Lig listesinden düşen takımı çıkar var relegatedIdxIn1 = leagueClubNames1.indexOf(relegatedTeamName); if (relegatedIdxIn1 !== -1) { leagueClubNames1.splice(relegatedIdxIn1, 1); } // Kullanıcı takımını Süper Lig listesine ekle (eğer yoksa) if (leagueClubNames1.indexOf(selectedTeamName) === -1) { leagueClubNames1.push(selectedTeamName); } // Only reset transfer market for new season initTransferList(); // Set first opponent var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // Süper Lig'de sonuncu bitiren kullanıcı 2. Lig'e düşer if (currentLeagueLevel === 1 && selectedTeamName && sortedLeague[sortedLeague.length - 1].name === selectedTeamName) { showInfo("Üzgünüz! Süper Lig'de sonuncu oldunuz ve 2. Lig'e düştünüz."); currentLeagueLevel = 2; leagueClubNames = leagueClubNames2; // Reset league for 2. Lig initLeague(); // Place user team in 2. Lig if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // Süper Lig'den düşen kullanıcı takımını Süper Lig listesinden çıkar var userIdxIn1 = leagueClubNames1.indexOf(selectedTeamName); if (userIdxIn1 !== -1) { leagueClubNames1.splice(userIdxIn1, 1); } // 2. Lig'e düşen kullanıcı takımını 2. Lig listesine ekle (eğer yoksa) if (leagueClubNames2.indexOf(selectedTeamName) === -1) { leagueClubNames2.push(selectedTeamName); } // 2. Lig'den çıkan takımı Süper Lig'e ekle (otomatik olarak bir üstteki kodda yapılır) // Only reset transfer market for new season initTransferList(); // Set first opponent var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // 2. Lig'de sonuncu bitiren kullanıcı 3. Lig'e düşer if (currentLeagueLevel === 2 && selectedTeamName && sortedLeague[sortedLeague.length - 1].name === selectedTeamName) { showInfo("Üzgünüz! 2. Lig'de sonuncu oldunuz ve 3. Lig'e düştünüz."); currentLeagueLevel = 3; leagueClubNames = leagueClubNames3; // Reset league for 3. Lig initLeague(); // Place user team in 3. Lig if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // 2. Lig'den düşen kullanıcı takımını 2. Lig listesinden çıkar var userIdxIn2 = leagueClubNames2.indexOf(selectedTeamName); if (userIdxIn2 !== -1) { leagueClubNames2.splice(userIdxIn2, 1); } // 3. Lig listesine ekle if (leagueClubNames3.indexOf(selectedTeamName) === -1) { leagueClubNames3.push(selectedTeamName); } initTransferList(); var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // 3. Lig'de sonuncu bitiren kullanıcı 4. Lig'e düşer if (currentLeagueLevel === 3 && selectedTeamName && sortedLeague[sortedLeague.length - 1].name === selectedTeamName) { showInfo("Üzgünüz! 3. Lig'de sonuncu oldunuz ve 4. Lig'e düştünüz."); currentLeagueLevel = 4; leagueClubNames = leagueClubNames4; // Reset league for 4. Lig initLeague(); // Place user team in 4. Lig if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // 3. Lig'den düşen kullanıcı takımını 3. Lig listesinden çıkar var userIdxIn3 = leagueClubNames3.indexOf(selectedTeamName); if (userIdxIn3 !== -1) { leagueClubNames3.splice(userIdxIn3, 1); } // 4. Lig listesine ekle if (leagueClubNames4.indexOf(selectedTeamName) === -1) { leagueClubNames4.push(selectedTeamName); } initTransferList(); var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // --- Süper Lig: Champions League qualification as before --- if (currentLeagueLevel === 1) { if (selectedTeamName && leagueChampionName === selectedTeamName) { championsLeagueUserQualified = true; } // Prepare Champions League teams for next season championsLeagueTeams = []; // 1. olan takımı ekle (kullanıcı ise kendi kadrosu, değilse gerçek kadro veya random) if (selectedTeamName && leagueChampionName === selectedTeamName) { championsLeagueTeams.push({ name: selectedTeamName, players: squad.map(clonePlayer) }); } else { // Find real squad or make random var real = realSquads[leagueChampionName]; var players = real ? real.map(clonePlayer) : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()]; championsLeagueTeams.push({ name: leagueChampionName, players: players }); } // Diğer liglerin şampiyonlarını ekle (örnek: İngiltere, Almanya, İspanya, Fransa, İtalya, Hollanda, Portekiz) // Her biri için örnek kadro ekleniyor var otherChampions = [{ name: "Manchester City", players: [new Player("Erling Haaland", 21, 10, 18, 170), new Player("Phil Foden", 17, 13, 17, 130), new Player("Kevin De Bruyne", 17, 14, 16, 120), new Player("Rodri", 14, 18, 17, 120), new Player("Ederson", 6, 18, 16, 90)] }, { name: "Bayern Munich", players: [new Player("Jamal Musiala", 17, 12, 17, 120), new Player("Harry Kane", 20, 10, 16, 100), new Player("Joshua Kimmich", 14, 15, 16, 100), new Player("Leroy Sané", 17, 10, 16, 95), new Player("Manuel Neuer", 6, 19, 16, 90)] }, { name: "Real Madrid", players: [new Player("Vinícius Júnior", 19, 12, 18, 150), new Player("Jude Bellingham", 18, 14, 18, 150), new Player("Rodrygo", 16, 10, 16, 100), new Player("Toni Kroos", 14, 15, 15, 90), new Player("Thibaut Courtois", 7, 19, 16, 90)] }, { name: "Paris SG", players: [new Player("Kylian Mbappé", 20, 12, 19, 180), new Player("Ousmane Dembélé", 17, 10, 16, 90), new Player("Achraf Hakimi", 13, 15, 16, 90), new Player("Marquinhos", 10, 17, 16, 90), new Player("Gianluigi Donnarumma", 6, 18, 16, 90)] }, { name: "Inter", players: [new Player("Lautaro Martínez", 18, 11, 16, 95), new Player("Hakan Çalhanoğlu", 15, 13, 16, 80), new Player("Nicolò Barella", 14, 14, 16, 80), new Player("Federico Dimarco", 13, 13, 15, 75), new Player("Yann Sommer", 7, 18, 15, 70)] }, { name: "PSV", players: [new Player("Luuk de Jong", 16, 8, 15, 60), new Player("Joey Veerman", 14, 12, 15, 55), new Player("Johan Bakayoko", 15, 10, 15, 55), new Player("Olivier Boscagli", 10, 15, 15, 50), new Player("Walter Benítez", 7, 17, 15, 50)] }, { name: "Benfica", players: [new Player("Rafa Silva", 16, 12, 16, 60), new Player("João Mário", 14, 13, 15, 55), new Player("Ángel Di María", 15, 10, 15, 55), new Player("Nicolás Otamendi", 10, 15, 15, 50), new Player("Anatoliy Trubin", 7, 17, 15, 50)] }]; // Hepsini ekle for (var i = 0; i < otherChampions.length; i++) { championsLeagueTeams.push({ name: otherChampions[i].name, players: otherChampions[i].players.map(clonePlayer) }); } // Toplam 8 takım olduysa devam et, yoksa random güçlü takımlarla tamamla while (championsLeagueTeams.length < 8) { championsLeagueTeams.push({ name: "Strong FC " + (championsLeagueTeams.length + 1), players: [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()] }); } // 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; } championsLeagueActive = championsLeagueUserQualified; championsLeagueCurrentRound = 0; championsLeagueLog = []; championsLeagueResult = null; championsLeaguePrize = 0; championsLeagueStage = ""; championsLeagueOpponent = null; championsLeagueUserPoints = 0; championsLeagueUserGroup = []; championsLeagueGroupResults = []; championsLeagueKnockoutTeams = []; championsLeagueKnockoutRound = 0; championsLeagueKnockoutOpponent = null; championsLeagueKnockoutLog = []; championsLeagueKnockoutResult = null; championsLeagueKnockoutStage = ""; championsLeagueUserEliminated = false; if (championsLeagueUserQualified) { showInfo("Tebrikler! Sadece lig şampiyonu ve diğer liglerin şampiyonları Şampiyonlar Ligi'ne katıldı! Yeni sezonda ekstra ödüller için mücadele et."); } // Reset league and start new season initLeague(); // Always ensure custom team is present in leagueTeams every season if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } // 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].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // If not promoted or Süper Lig, just reset league for same division initLeague(); if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) { var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === selectedTeamName) { foundCustom = true; break; } } if (!foundCustom) { leagueTeams[0].name = selectedTeamName; leagueTeams[0].realSquad = squad.map(clonePlayer); } } initTransferList(); var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); return; } // Next opponent in league var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } clearMatchText(); nextBtn.destroy(); nextBtn = null; refreshUI(); }; game.addChild(nextBtn); }; game.addChild(playBtn); } // --- INIT UI --- 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); refreshUI(); } // --- GAME START --- // --- TEAM SELECTION SYSTEM --- var teamSelectionLabels = []; var teamSelectionBtns = []; var selectedTeamName = null; function showTeamSelection() { // Clear everything clearAllUI(); clearArray(teamSelectionLabels); clearArray(teamSelectionBtns); // --- LIG SEÇİMİ EKRANI --- var leagueSelectTitle = new Text2("Hangi Ligde Oynamak İstersin?", { size: 90, fill: 0x00CEC9 }); leagueSelectTitle.x = 80; leagueSelectTitle.y = 200; game.addChild(leagueSelectTitle); teamSelectionLabels.push(leagueSelectTitle); var leagueNames = [{ name: "Süper Lig", level: 1, color: 0x00B894 }, { name: "2. Lig", level: 2, color: 0x0984E3 }, { name: "3. Lig", level: 3, color: 0x6c5ce7 }, { name: "4. Lig", level: 4, color: 0x00b894 }, // Other countries { name: "Premier League (İngiltere)", level: 101, color: 0x1e90ff }, { name: "Bundesliga (Almanya)", level: 102, color: 0xff0000 }, { name: "La Liga (İspanya)", level: 103, color: 0xf4c542 }, { name: "Ligue 1 (Fransa)", level: 104, color: 0x00b894 }, { name: "Serie A (İtalya)", level: 105, color: 0x2d3436 }, { name: "Eredivisie (Hollanda)", level: 106, color: 0xfdcb6e }, { name: "Primeira Liga (Portekiz)", level: 107, color: 0xe17055 }]; // 3. ve 4. Lig'i Süper Lig ve 2. Lig'in sağına koymak için sıralama değiştirildi leagueNames.splice(2, 0, leagueNames.splice(2, 1)[0]); leagueNames.splice(3, 0, leagueNames.splice(3, 1)[0]); var leagueBtnY = 400; var leagueBtnSpacing = 120; for (var i = 0; i < leagueNames.length; i++) { (function (idx) { var league = leagueNames[idx]; var btn = new Text2(league.name, { size: 80, fill: league.color }); btn.x = 200; btn.y = leagueBtnY + idx * leagueBtnSpacing; btn.interactive = true; btn.down = function (x, y, obj) { // Remove league selection UI for (var j = 0; j < teamSelectionLabels.length; j++) { if (teamSelectionLabels[j] && teamSelectionLabels[j].destroy) teamSelectionLabels[j].destroy(); } for (var j = 0; j < teamSelectionBtns.length; j++) { if (teamSelectionBtns[j] && teamSelectionBtns[j].destroy) teamSelectionBtns[j].destroy(); } teamSelectionLabels = []; teamSelectionBtns = []; // Defensive: If leagueClubLists[league.level] is not an array, show error var leagueClubLists = [null, leagueClubNames1, leagueClubNames2, leagueClubNames3, leagueClubNames4, leagueClubNamesEngland, leagueClubNamesGermany, leagueClubNamesSpain, leagueClubNamesFrance, leagueClubNamesItaly, leagueClubNamesNetherlands, leagueClubNamesPortugal]; if (!leagueClubLists[league.level] || typeof leagueClubLists[league.level].length !== "number" || leagueClubLists[league.level].length === 0) { var errLabel = new Text2("Bu ligde takım bulunamadı.", { size: 70, fill: 0xFF7675 }); errLabel.x = 200; errLabel.y = 400; game.addChild(errLabel); teamSelectionLabels.push(errLabel); return; } // Show team selection for this league showTeamSelectionForLeague(league.level); }; game.addChild(btn); teamSelectionBtns.push(btn); })(i); } // --- LIG SEÇİMİNDEN SONRA TAKIM SEÇİMİ --- function showTeamSelectionForLeague(leagueLevel) { clearAllUI(); clearArray(teamSelectionLabels); clearArray(teamSelectionBtns); var leagueClubLists = [null, leagueClubNames1, leagueClubNames2, leagueClubNames3, leagueClubNames4, leagueClubNamesEngland, // 101 leagueClubNamesGermany, // 102 leagueClubNamesSpain, // 103 leagueClubNamesFrance, // 104 leagueClubNamesItaly, // 105 leagueClubNamesNetherlands, // 106 leagueClubNamesPortugal // 107 ]; var leagueHeaders = [null, "Süper Lig", "2. Lig", "3. Lig", "4. Lig", "Premier League (İngiltere)", "Bundesliga (Almanya)", "La Liga (İspanya)", "Ligue 1 (Fransa)", "Serie A (İtalya)", "Eredivisie (Hollanda)", "Primeira Liga (Portekiz)"]; var leagueColors = [null, 0x00B894, 0x0984E3, 0x6c5ce7, 0x00b894, 0x1e90ff, 0xff0000, 0xf4c542, 0x00b894, 0x2d3436, 0xfdcb6e, 0xe17055]; var title = new Text2("Takımını Seç!", { size: 90, fill: 0x00CEC9 }); title.x = 80; title.y = 200; game.addChild(title); teamSelectionLabels.push(title); var header = new Text2(leagueHeaders[leagueLevel], { size: 60, fill: leagueColors[leagueLevel] }); header.x = 200; header.y = 320; game.addChild(header); teamSelectionLabels.push(header); var clubs = leagueClubLists[leagueLevel]; var btnSpacing = 90; var btnX = 200; var startY = 400; // Defensive: If clubs is not an array or is undefined/null, show error and return if (!clubs || typeof clubs.length !== "number" || clubs.length === 0) { var errLabel = new Text2("Bu ligde takım bulunamadı.", { size: 70, fill: 0xFF7675 }); errLabel.x = btnX; errLabel.y = startY; game.addChild(errLabel); teamSelectionLabels.push(errLabel); } else { if (clubs && typeof clubs.length === "number" && clubs.length > 0) { for (var i = 0; i < clubs.length; i++) { (function (idx) { var clubName = clubs[idx]; var btn = new Text2(clubName, { size: 70, fill: 0xFDCB6E }); btn.x = btnX; btn.y = startY + idx * btnSpacing; btn.interactive = true; btn.down = function (x, y, obj) { selectedTeamName = clubName; currentLeagueLevel = leagueLevel; leagueClubNames = clubs; // Remove selection UI for (var j = 0; j < teamSelectionLabels.length; j++) { if (teamSelectionLabels[j] && teamSelectionLabels[j].destroy) teamSelectionLabels[j].destroy(); } for (var j = 0; j < teamSelectionBtns.length; j++) { if (teamSelectionBtns[j] && teamSelectionBtns[j].destroy) teamSelectionBtns[j].destroy(); } teamSelectionLabels = []; teamSelectionBtns = []; // Start game with this team startGameWithTeam(selectedTeamName); }; game.addChild(btn); teamSelectionBtns.push(btn); })(i); } } } // Add "Kendi Takımını Oluştur" button var customBtn = new Text2("Kendi Takımını Oluştur", { size: 70, fill: 0x00b894 }); customBtn.x = btnX; customBtn.y = startY + (clubs && typeof clubs.length === "number" ? clubs.length : 0) * btnSpacing + 120; customBtn.interactive = true; customBtn.down = function (x, y, obj) { // Remove selection UI for (var j = 0; j < teamSelectionLabels.length; j++) { if (teamSelectionLabels[j] && teamSelectionLabels[j].destroy) teamSelectionLabels[j].destroy(); } for (var j = 0; j < teamSelectionBtns.length; j++) { if (teamSelectionBtns[j] && teamSelectionBtns[j].destroy) teamSelectionBtns[j].destroy(); } teamSelectionLabels = []; teamSelectionBtns = []; // --- Custom Team Name Input UI --- var inputBg = LK.getAsset('character', { width: 900, height: 200, color: 0x222222, anchorX: 0, anchorY: 0 }); inputBg.x = 400; inputBg.y = 700; game.addChild(inputBg); var inputLabel = new Text2("Takım Adını Gir:", { size: 60, fill: 0x00B894 }); inputLabel.x = 420; inputLabel.y = 720; game.addChild(inputLabel); var nameText = new Text2("", { size: 60, fill: "#fff" }); nameText.x = 420; nameText.y = 800; game.addChild(nameText); // Per-letter buttons (including space) var alphabetArr = ["A", "B", "C", "Ç", "D", "E", "F", "G", "Ğ", "H", "I", "İ", "J", "K", "L", "M", "N", "O", "Ö", "P", "R", "S", "Ş", "T", "U", "Ü", "V", "Y", "Z", "a", "b", "c", "ç", "d", "e", "f", "g", "ğ", "h", "ı", "i", "j", "k", "l", "m", "n", "o", "ö", "p", "r", "s", "ş", "t", "u", "ü", "v", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", " "]; var maxLen = 18; var currentName = ""; var letterBtns = []; var lettersPerRow = 10; var startX = 420, startY = 900, btnW = 90, btnH = 90, gap = 16; for (var i = 0; i < alphabetArr.length; i++) { (function (idx) { var ch = alphabetArr[idx]; var btn = new Text2(ch === " " ? "␣" : ch, { size: 54, fill: 0xFDCB6E }); btn.x = startX + idx % lettersPerRow * (btnW + gap); btn.y = startY + Math.floor(idx / lettersPerRow) * (btnH + gap); btn.interactive = true; btn.down = function () { if (currentName.length < maxLen) { currentName += ch; nameText.setText(currentName); } }; game.addChild(btn); letterBtns.push(btn); })(i); } // Backspace button var backBtn = new Text2("Sil", { size: 54, fill: 0xFF7675 }); backBtn.x = startX + (lettersPerRow + 1) * (btnW + gap); backBtn.y = startY; backBtn.interactive = true; backBtn.down = function () { if (currentName.length > 0) { currentName = currentName.slice(0, -1); nameText.setText(currentName); } }; game.addChild(backBtn); // Confirm button var okBtn = new Text2("Tamam", { size: 64, fill: 0x00CEC9 }); okBtn.x = startX + (lettersPerRow + 1) * (btnW + gap); okBtn.y = startY + btnH + gap; okBtn.interactive = true; okBtn.down = function () { var teamName = currentName.trim().length > 0 ? currentName.trim() : "Benim Takımım"; // Clean up input UI inputBg.destroy(); inputLabel.destroy(); nameText.destroy(); for (var i = 0; i < letterBtns.length; i++) letterBtns[i].destroy(); backBtn.destroy(); okBtn.destroy(); selectedTeamName = teamName; // Set up a new team with random players allPlayers = []; for (var i = 0; i < SQUAD_SIZE + BENCH_SIZE; i++) { allPlayers.push(makeRandomPlayer()); } updateSquadAndBench(); initTransferList(); // Start custom team in selected league currentLeagueLevel = leagueLevel; leagueClubNames = leagueClubLists[leagueLevel]; // Set up league with user as custom team initLeague(); leagueTeams[0].name = teamName; userTeamIdx = 0; // Set first opponent in league var oppIdx = getCurrentOpponentIdx(); if (oppIdx !== null) { opponentTeam = makeOpponentTeam(); opponentTeam.name = leagueTeams[oppIdx].name; } else { opponentTeam = makeOpponentTeam(); } // Reset youth academy and offers youthAcademy = []; if (youthTimer) { LK.clearInterval(youthTimer); youthTimer = null; } transferOffers = []; if (OFFER_TIMER) { LK.clearInterval(OFFER_TIMER); OFFER_TIMER = null; } clearArray(offerLabels); clearArray(acceptOfferBtns); clearArray(rejectOfferBtns); matchInProgress = false; matchLog = []; matchResult = null; selectedPlayerIdx = null; selectedBenchIdx = null; budget = INITIAL_BUDGET; initUI(); }; game.addChild(okBtn); }; game.addChild(customBtn); teamSelectionBtns.push(customBtn); } } function startGameWithTeam(teamName) { budget = INITIAL_BUDGET; // Start in the league selected by the user // currentLeagueLevel and leagueClubNames are already set by selection UI if (currentLeagueLevel === 1) { leagueClubNames = leagueClubNames1; } else if (currentLeagueLevel === 2) { leagueClubNames = leagueClubNames2; } else if (currentLeagueLevel === 3) { leagueClubNames = leagueClubNames3; } else if (currentLeagueLevel === 4) { leagueClubNames = leagueClubNames4; } else if (currentLeagueLevel === 101) { leagueClubNames = leagueClubNamesEngland; } else if (currentLeagueLevel === 102) { leagueClubNames = leagueClubNamesGermany; } else if (currentLeagueLevel === 103) { leagueClubNames = leagueClubNamesSpain; } else if (currentLeagueLevel === 104) { leagueClubNames = leagueClubNamesFrance; } else if (currentLeagueLevel === 105) { leagueClubNames = leagueClubNamesItaly; } else if (currentLeagueLevel === 106) { leagueClubNames = leagueClubNamesNetherlands; } else if (currentLeagueLevel === 107) { leagueClubNames = leagueClubNamesPortugal; } else { leagueClubNames = leagueClubNames1; } // Set up league with user as chosen team initLeague(); // Always ensure custom team is present in leagueTeams every season var foundCustom = false; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === teamName) { foundCustom = true; break; } } if (!foundCustom) { // Replace "You" with custom team if not present leagueTeams[0].name = teamName; leagueTeams[0].realSquad = allPlayers.slice(0, SQUAD_SIZE).map(clonePlayer); } // Find index of chosen team in leagueTeams var idx = -1; for (var i = 0; i < leagueTeams.length; i++) { if (leagueTeams[i].name === teamName) { idx = i; break; } } if (idx === -1) idx = 1; // fallback // Swap "You" with chosen team in leagueTeams if (idx !== 0) { var userTeam = leagueTeams[0]; var chosenTeam = leagueTeams[idx]; // Swap all properties except name var tmpName = userTeam.name; userTeam.name = chosenTeam.name; chosenTeam.name = tmpName; // Swap realSquad if present var tmpSquad = userTeam.realSquad; userTeam.realSquad = chosenTeam.realSquad; chosenTeam.realSquad = tmpSquad; // Swap points etc. var props = ["points", "played", "wins", "draws", "losses", "goalsFor", "goalsAgainst"]; for (var p = 0; p < props.length; p++) { var prop = props[p]; var tmp = userTeam[prop]; userTeam[prop] = chosenTeam[prop]; chosenTeam[prop] = tmp; } } userTeamIdx = 0; // Set allPlayers, squad, bench to chosen team's real squad if (realSquads[teamName]) { allPlayers = []; var real = realSquads[teamName]; for (var i = 0; i < real.length; i++) { allPlayers.push(clonePlayer(real[i])); } // Fill bench with randoms for (var i = 0; i < BENCH_SIZE; i++) { allPlayers.push(makeRandomPlayer()); } updateSquadAndBench(); } else { initPlayers(); } 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].name; } else { opponentTeam = makeOpponentTeam(); } matchInProgress = false; matchLog = []; matchResult = null; selectedPlayerIdx = null; selectedBenchIdx = null; initUI(); } // Override newGame to show team selection function newGame() { showTeamSelection(); } newGame(); // --- END ---
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a3d2f
});
/****
* Game Code
****/
// --- CONSTANTS ---
// Player class: represents a footballer
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;
// --- 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, players, ...}
var championsLeagueFixtures = []; // Array of {homeIdx, awayIdx}
var championsLeagueCurrentRound = 0;
var championsLeagueActive = false;
var championsLeagueUserQualified = false;
var championsLeagueLog = [];
var championsLeagueResult = null;
var championsLeaguePrize = 0;
var championsLeagueStage = ""; // "Group", "Quarterfinal", etc.
var championsLeagueOpponent = null;
var championsLeagueUserPoints = 0;
var championsLeagueUserGroup = [];
var championsLeagueGroupResults = [];
var championsLeagueKnockoutTeams = [];
var championsLeagueKnockoutRound = 0;
var championsLeagueKnockoutOpponent = null;
var championsLeagueKnockoutLog = [];
var championsLeagueKnockoutResult = null;
var championsLeagueKnockoutStage = "";
var championsLeagueUserEliminated = false;
// --- 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"];
// --- 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, 2. Lig, 3. Lig, 4. Lig squads (2024/25, 5 oyuncu örnek, demo)
// Plus real squads for all teams in every league (not just champions)
var realSquads = {};
// Helper: assign real squads for a league
function assignRealSquadsForLeague(clubNames, squadArrs) {
// Defensive: If clubNames is not an array or is undefined/null, do nothing
if (!clubNames || typeof clubNames.length !== "number" || clubNames.length === 0) {
return;
}
if (!clubNames || typeof clubNames.length !== "number" || clubNames.length === 0) {
return;
}
for (var i = 0; i < clubNames.length; i++) {
realSquads[clubNames[i]] = squadArrs[i];
}
}
// Süper Lig
assignRealSquadsForLeague(leagueClubNames1, [
// Sivasspor
[new Player("Rey Manaj", 15, 8, 14, 28), new Player("Clinton N'Jie", 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)],
// Galatasaray
[new Player("Mauro Icardi", 19, 8, 16, 42), new Player("Wilfried Zaha", 17, 7, 15, 36), new Player("Lucas Torreira", 10, 17, 17, 35), new Player("Kerem Aktürkoğlu", 16, 8, 15, 33), 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, 15, 16, 34), new Player("Sebastian Szymanski", 15, 9, 15, 32), new Player("Dominik Livakovic", 6, 17, 16, 34)],
// Trabzonspor
[new Player("Paul Onuachu", 16, 7, 15, 32), new Player("Edin Visca", 15, 8, 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)],
// 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)],
// Basaksehir
[new Player("Joao Figueiredo", 14, 8, 14, 28), new Player("Leo Duarte", 8, 15, 14, 27), new Player("Serdar Gürler", 13, 8, 14, 27), new Player("Ousseynou Ba", 9, 14, 14, 26), new Player("Volkan Babacan", 6, 16, 14, 25)],
// Konyaspor
[new Player("Sokol Cikalleshi", 14, 8, 14, 27), new Player("Oğulcan Ülgün", 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("Adam Buksa", 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("Oğuz Aydın", 14, 8, 14, 27), new Player("Efecan Karaca", 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)]]);
// 2. Lig
assignRealSquadsForLeague(leagueClubNames2, [[new Player("Yasin Öztekin", 14, 8, 14, 27), new Player("Atınç Nukan", 10, 13, 14, 25), new Player("Murat Paluli", 8, 14, 14, 24), new Player("Romulo Cardoso", 15, 8, 14, 28), new Player("Arda Özçimen", 6, 16, 14, 24)], [new Player("Kabongo Kasongo", 15, 8, 14, 27), new Player("Oğuz Yıldırım", 10, 13, 14, 25), new Player("Burak Süleyman", 13, 8, 14, 27), new Player("Isaac Donkor", 8, 15, 14, 25), new Player("Cihan Topaloğlu", 6, 16, 14, 24)], [new Player("Douglas Tanque", 15, 8, 14, 27), new Player("Mehmet Taş", 10, 13, 14, 25), new Player("Berat Altındiş", 13, 8, 14, 27), new Player("Ali Keten", 8, 15, 14, 25), new Player("Korcan Çelikay", 6, 16, 14, 24)], [new Player("Umut Nayir", 15, 8, 14, 27), new Player("Caner Erkin", 10, 13, 14, 25), new Player("Halil Akbunar", 13, 8, 14, 27), new Player("Alpaslan Öztürk", 8, 15, 14, 25), new Player("Harun Tekin", 6, 16, 14, 24)], [new Player("Gökdeniz Bayrakdar", 14, 8, 14, 27), new Player("Erkan Değişmez", 10, 13, 14, 25), new Player("Celal Dumanlı", 13, 8, 14, 27), new Player("Samet Yalçın", 8, 15, 14, 25), new Player("Diogo Sousa", 6, 16, 14, 24)], [new Player("Barış Alıcı", 14, 8, 14, 27), new Player("Rahmetullah Berişbek", 10, 13, 14, 25), new Player("Gökhan Gül", 13, 8, 14, 27), new Player("Arda Kızıldağ", 8, 15, 14, 25), new Player("Ramazan Köse", 6, 16, 14, 24)], [new Player("Eren Tozlu", 14, 8, 14, 27), new Player("Orhan Ovacıklı", 10, 13, 14, 25), new Player("Murat Uçar", 13, 8, 14, 27), new Player("Aykut Demir", 8, 15, 14, 25), new Player("Göktuğ Bakırbaş", 6, 16, 14, 24)], [new Player("Berk Yıldız", 14, 8, 14, 27), new Player("Ali Keten", 10, 13, 14, 25), new Player("Gökhan Sazdağı", 13, 8, 14, 27), new Player("Uğur Akdemir", 8, 15, 14, 25), new Player("Çağlar Şahin Akbaba", 6, 16, 14, 24)], [new Player("Doğan Can Davas", 14, 8, 14, 27), new Player("Sergen Piçinciol", 10, 13, 14, 25), new Player("Okan Alkan", 13, 8, 14, 27), new Player("Emre Batuhan Adıgüzel", 8, 15, 14, 25), new Player("Gökhan Değirmenci", 6, 16, 14, 24)]]);
// 3. Lig
assignRealSquadsForLeague(leagueClubNames3, [[new Player("Özgür Göktaş", 13, 8, 13, 22), new Player("Mehmet Sıddık İstemi", 12, 9, 13, 21), new Player("Sinan Akaydın", 11, 10, 13, 21), new Player("Mert Somay", 10, 11, 13, 20), new Player("Cemal Doğan", 9, 12, 13, 20)], [new Player("Okan Deniz", 13, 8, 13, 22), new Player("Mehmet Yiğit", 12, 9, 13, 21), new Player("Fatih Üge", 11, 10, 13, 21), new Player("Emre Okur", 10, 11, 13, 20), new Player("Murat Yılmaz", 9, 12, 13, 20)], [new Player("İsmail Haktan Odabaşı", 13, 8, 13, 22), new Player("Onur Demir", 12, 9, 13, 21), new Player("Mert Efe Çölbeyi", 11, 10, 13, 21), new Player("Ali Kılıç", 10, 11, 13, 20), new Player("Yusuf Emre Kasal", 9, 12, 13, 20)], [new Player("Mehmet Sıddık İstemi", 13, 8, 13, 22), new Player("Sinan Akaydın", 12, 9, 13, 21), new Player("Mert Somay", 11, 10, 13, 21), new Player("Cemal Doğan", 10, 11, 13, 20), new Player("Özgür Göktaş", 9, 12, 13, 20)], [new Player("Fatih Üge", 13, 8, 13, 22), new Player("Emre Okur", 12, 9, 13, 21), new Player("Murat Yılmaz", 11, 10, 13, 21), new Player("Okan Deniz", 10, 11, 13, 20), new Player("Mehmet Yiğit", 9, 12, 13, 20)], [new Player("Onur Demir", 13, 8, 13, 22), new Player("Mert Efe Çölbeyi", 12, 9, 13, 21), new Player("Ali Kılıç", 11, 10, 13, 21), new Player("Yusuf Emre Kasal", 10, 11, 13, 20), new Player("İsmail Haktan Odabaşı", 9, 12, 13, 20)], [new Player("Sinan Akaydın", 13, 8, 13, 22), new Player("Mert Somay", 12, 9, 13, 21), new Player("Cemal Doğan", 11, 10, 13, 21), new Player("Özgür Göktaş", 10, 11, 13, 20), new Player("Mehmet Sıddık İstemi", 9, 12, 13, 20)], [new Player("Emre Okur", 13, 8, 13, 22), new Player("Murat Yılmaz", 12, 9, 13, 21), new Player("Okan Deniz", 11, 10, 13, 21), new Player("Mehmet Yiğit", 10, 11, 13, 20), new Player("Fatih Üge", 9, 12, 13, 20)], [new Player("Mert Efe Çölbeyi", 13, 8, 13, 22), new Player("Ali Kılıç", 12, 9, 13, 21), new Player("Yusuf Emre Kasal", 11, 10, 13, 21), new Player("İsmail Haktan Odabaşı", 10, 11, 13, 20), new Player("Onur Demir", 9, 12, 13, 20)]]);
// 4. Lig
assignRealSquadsForLeague(leagueClubNames4, [[new Player("Fatih Taşdelen", 12, 8, 12, 18), new Player("Mustafa Aşan", 11, 9, 12, 17), new Player("Hüseyin Yılmaz", 10, 10, 12, 17), new Player("Ali Say", 9, 11, 12, 16), new Player("Mehmet Yılmaz", 8, 12, 12, 16)], [new Player("Okan Duran", 12, 8, 12, 18), new Player("Emre Özkan", 11, 9, 12, 17), new Player("Burak Aydın", 10, 10, 12, 17), new Player("Serkan Balcı", 9, 11, 12, 16), new Player("Murat Akın", 8, 12, 12, 16)], [new Player("Mehmet Yılmaz", 12, 8, 12, 18), new Player("Ali Say", 11, 9, 12, 17), new Player("Fatih Taşdelen", 10, 10, 12, 17), new Player("Mustafa Aşan", 9, 11, 12, 16), new Player("Hüseyin Yılmaz", 8, 12, 12, 16)], [new Player("Burak Aydın", 12, 8, 12, 18), new Player("Serkan Balcı", 11, 9, 12, 17), new Player("Murat Akın", 10, 10, 12, 17), new Player("Okan Duran", 9, 11, 12, 16), new Player("Emre Özkan", 8, 12, 12, 16)], [new Player("Ali Say", 12, 8, 12, 18), new Player("Fatih Taşdelen", 11, 9, 12, 17), new Player("Mustafa Aşan", 10, 10, 12, 17), new Player("Hüseyin Yılmaz", 9, 11, 12, 16), new Player("Mehmet Yılmaz", 8, 12, 12, 16)], [new Player("Serkan Balcı", 12, 8, 12, 18), new Player("Murat Akın", 11, 9, 12, 17), new Player("Okan Duran", 10, 10, 12, 17), new Player("Emre Özkan", 9, 11, 12, 16), new Player("Burak Aydın", 8, 12, 12, 16)], [new Player("Fatih Taşdelen", 12, 8, 12, 18), new Player("Mustafa Aşan", 11, 9, 12, 17), new Player("Hüseyin Yılmaz", 10, 10, 12, 17), new Player("Ali Say", 9, 11, 12, 16), new Player("Mehmet Yılmaz", 8, 12, 12, 16)], [new Player("Emre Özkan", 12, 8, 12, 18), new Player("Burak Aydın", 11, 9, 12, 17), new Player("Serkan Balcı", 10, 10, 12, 17), new Player("Murat Akın", 9, 11, 12, 16), new Player("Okan Duran", 8, 12, 12, 16)], [new Player("Mustafa Aşan", 12, 8, 12, 18), new Player("Hüseyin Yılmaz", 11, 9, 12, 17), new Player("Mehmet Yılmaz", 10, 10, 12, 17), new Player("Fatih Taşdelen", 9, 11, 12, 16), new Player("Ali Say", 8, 12, 12, 16)]]);
// Premier League (England)
assignRealSquadsForLeague(leagueClubNamesEngland, [[new Player("Erling Haaland", 21, 10, 18, 170), new Player("Phil Foden", 17, 13, 17, 130), new Player("Kevin De Bruyne", 17, 14, 16, 120), new Player("Rodri", 14, 18, 17, 120), new Player("Ederson", 6, 18, 16, 90)], [new Player("Bukayo Saka", 17, 12, 17, 120), new Player("Martin Ødegaard", 16, 13, 16, 100), new Player("Declan Rice", 13, 17, 17, 100), new Player("William Saliba", 9, 18, 16, 80), new Player("Gabriel Jesus", 16, 10, 15, 85)], [new Player("Mohamed Salah", 19, 10, 16, 110), new Player("Virgil van Dijk", 8, 19, 16, 90), new Player("Alisson Becker", 6, 18, 16, 80), new Player("Trent Alexander-Arnold", 13, 15, 15, 85), new Player("Luis Díaz", 16, 10, 15, 80)], [new Player("Enzo Fernández", 14, 14, 16, 80), new Player("Raheem Sterling", 16, 10, 15, 75), new Player("Reece James", 12, 15, 15, 75), new Player("Christopher Nkunku", 17, 11, 15, 85), new Player("Robert Sánchez", 6, 16, 15, 60)], [new Player("Bruno Fernandes", 16, 12, 16, 90), new Player("Marcus Rashford", 17, 10, 16, 90), new Player("Casemiro", 12, 16, 16, 80), new Player("Lisandro Martínez", 9, 17, 15, 75), new Player("André Onana", 6, 16, 15, 60)], [new Player("Heung-Min Son", 19, 11, 17, 110), new Player("James Maddison", 15, 12, 15, 80), new Player("Cristian Romero", 9, 17, 15, 75), new Player("Dejan Kulusevski", 15, 10, 15, 70), new Player("Guglielmo Vicario", 6, 16, 15, 60)], [new Player("Alexander Isak", 16, 10, 15, 80), new Player("Bruno Guimarães", 14, 14, 16, 80), new Player("Sven Botman", 9, 17, 15, 70), new Player("Kieran Trippier", 12, 15, 15, 70), new Player("Nick Pope", 6, 16, 15, 60)], [new Player("Ollie Watkins", 16, 10, 15, 75), new Player("Douglas Luiz", 13, 14, 15, 70), new Player("Emiliano Martínez", 6, 17, 15, 65), new Player("John McGinn", 13, 12, 15, 65), new Player("Leon Bailey", 15, 10, 15, 65)], [new Player("Kaoru Mitoma", 15, 10, 15, 70), new Player("Pascal Groß", 13, 13, 15, 65), new Player("Lewis Dunk", 9, 16, 15, 65), new Player("Pervis Estupiñán", 12, 14, 15, 65), new Player("Bart Verbruggen", 6, 15, 15, 60)],
// The rest: fill with randoms for demo
[makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()], [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()]]);
// Bundesliga (Germany)
assignRealSquadsForLeague(leagueClubNamesGermany, [[new Player("Jamal Musiala", 17, 12, 17, 120), new Player("Harry Kane", 20, 10, 16, 100), new Player("Joshua Kimmich", 14, 15, 16, 100), new Player("Leroy Sané", 17, 10, 16, 95), new Player("Manuel Neuer", 6, 19, 16, 90)], [new Player("Julian Brandt", 15, 12, 15, 80), new Player("Niclas Füllkrug", 16, 10, 15, 75), new Player("Mats Hummels", 8, 17, 15, 70), new Player("Emre Can", 13, 14, 15, 70), new Player("Gregor Kobel", 6, 16, 15, 65)], [new Player("Dani Olmo", 15, 12, 15, 75), new Player("Loïs Openda", 16, 10, 15, 75), new Player("Willi Orbán", 9, 17, 15, 70), new Player("Xaver Schlager", 13, 14, 15, 70), new Player("Janis Blaswich", 6, 16, 15, 65)], [new Player("Florian Wirtz", 16, 12, 17, 110), new Player("Victor Boniface", 16, 10, 15, 75), new Player("Jonathan Tah", 9, 17, 15, 70), new Player("Granit Xhaka", 13, 14, 15, 70), new Player("Lukáš Hrádecký", 6, 16, 15, 65)], [new Player("Mario Götze", 14, 13, 15, 70), new Player("Omar Marmoush", 15, 10, 15, 70), new Player("Robin Koch", 9, 16, 15, 65), new Player("Sebastian Rode", 13, 14, 15, 65), new Player("Kevin Trapp", 6, 16, 15, 60)], [new Player("Kevin Behrens", 15, 10, 15, 70), new Player("Robin Gosens", 13, 14, 15, 70), new Player("Danilho Doekhi", 9, 16, 15, 65), new Player("Rani Khedira", 13, 14, 15, 65), new Player("Frederik Rønnow", 6, 16, 15, 60)], [new Player("Vincenzo Grifo", 15, 12, 15, 70), new Player("Michael Gregoritsch", 16, 10, 15, 70), new Player("Matthias Ginter", 9, 17, 15, 65), new Player("Nicolas Höfler", 13, 14, 15, 65), new Player("Noah Atubolu", 6, 16, 15, 60)], [new Player("Jonas Wind", 16, 10, 15, 70), new Player("Maxence Lacroix", 9, 17, 15, 65), new Player("Mattias Svanberg", 13, 14, 15, 65), new Player("Patrick Wimmer", 15, 12, 15, 65), new Player("Koen Casteels", 6, 16, 15, 60)], [new Player("Serhou Guirassy", 17, 10, 15, 75), new Player("Waldemar Anton", 9, 17, 15, 65), new Player("Chris Führich", 15, 12, 15, 65), new Player("Enzo Millot", 13, 14, 15, 65), new Player("Alexander Nübel", 6, 16, 15, 60)]]);
// La Liga (Spain)
assignRealSquadsForLeague(leagueClubNamesSpain, [[new Player("Vinícius Júnior", 19, 12, 18, 150), new Player("Jude Bellingham", 18, 14, 18, 150), new Player("Rodrygo", 16, 10, 16, 100), new Player("Toni Kroos", 14, 15, 15, 90), new Player("Thibaut Courtois", 7, 19, 16, 90)], [new Player("Robert Lewandowski", 20, 9, 15, 100), new Player("Pedri", 15, 13, 17, 100), new Player("Gavi", 14, 14, 16, 90), new Player("Jules Koundé", 10, 17, 15, 80), new Player("Marc-André ter Stegen", 6, 18, 16, 80)], [new Player("Antoine Griezmann", 17, 12, 16, 90), new Player("Álvaro Morata", 16, 10, 15, 80), new Player("Koke", 13, 14, 15, 75), new Player("José Giménez", 9, 17, 15, 75), new Player("Jan Oblak", 6, 18, 16, 80)], [new Player("Youssef En-Nesyri", 16, 10, 15, 75), new Player("Ivan Rakitić", 14, 13, 15, 70), new Player("Marcos Acuña", 13, 14, 15, 70), new Player("Nemanja Gudelj", 9, 17, 15, 65), new Player("Marko Dmitrović", 6, 16, 15, 60)], [new Player("Mikel Oyarzabal", 15, 12, 15, 70), new Player("Takefusa Kubo", 15, 10, 15, 70), new Player("Robin Le Normand", 9, 17, 15, 65), new Player("Mikel Merino", 13, 14, 15, 65), new Player("Álex Remiro", 6, 16, 15, 60)], [new Player("Gerard Moreno", 16, 10, 15, 70), new Player("Dani Parejo", 14, 13, 15, 70), new Player("Pau Torres", 9, 17, 15, 65), new Player("Álex Baena", 13, 14, 15, 65), new Player("Pepe Reina", 6, 16, 15, 60)], [new Player("Nabil Fekir", 15, 12, 15, 70), new Player("Borja Iglesias", 16, 10, 15, 70), new Player("Guido Rodríguez", 13, 14, 15, 65), new Player("William Carvalho", 13, 14, 15, 65), new Player("Claudio Bravo", 6, 16, 15, 60)], [new Player("Iñaki Williams", 16, 10, 15, 70), new Player("Oihan Sancet", 15, 12, 15, 70), new Player("Yeray Álvarez", 9, 17, 15, 65), new Player("Dani Vivian", 13, 14, 15, 65), new Player("Unai Simón", 6, 16, 15, 60)], [new Player("Hugo Duro", 15, 10, 15, 65), new Player("José Gayà", 13, 14, 15, 65), new Player("Gabriel Paulista", 9, 17, 15, 65), new Player("André Almeida", 13, 14, 15, 65), new Player("Giorgi Mamardashvili", 6, 16, 15, 60)]]);
// Ligue 1 (France)
assignRealSquadsForLeague(leagueClubNamesFrance, [[new Player("Kylian Mbappé", 20, 12, 19, 180), new Player("Ousmane Dembélé", 17, 10, 16, 90), new Player("Achraf Hakimi", 13, 15, 16, 90), new Player("Marquinhos", 10, 17, 16, 90), new Player("Gianluigi Donnarumma", 6, 18, 16, 90)], [new Player("Pierre-Emerick Aubameyang", 17, 10, 15, 80), new Player("Mattéo Guendouzi", 13, 14, 15, 70), new Player("Jonathan Clauss", 13, 14, 15, 70), new Player("Samuel Gigot", 9, 17, 15, 65), new Player("Pau López", 6, 16, 15, 60)], [new Player("Alexandre Lacazette", 17, 10, 15, 80), new Player("Corentin Tolisso", 13, 14, 15, 70), new Player("Nicolás Tagliafico", 13, 14, 15, 70), new Player("Dejan Lovren", 9, 17, 15, 65), new Player("Anthony Lopes", 6, 16, 15, 60)], [new Player("Wissam Ben Yedder", 17, 10, 15, 80), new Player("Youssouf Fofana", 13, 14, 15, 70), new Player("Axel Disasi", 13, 14, 15, 70), new Player("Guillermo Maripán", 9, 17, 15, 65), new Player("Philipp Köhn", 6, 16, 15, 60)], [new Player("Jonathan David", 17, 10, 15, 80), new Player("Benjamin André", 13, 14, 15, 70), new Player("José Fonte", 13, 14, 15, 70), new Player("Tiago Djaló", 9, 17, 15, 65), new Player("Lucas Chevalier", 6, 16, 15, 60)], [new Player("Martin Terrier", 16, 10, 15, 75), new Player("Benjamin Bourigeaud", 13, 14, 15, 70), new Player("Arthur Theate", 13, 14, 15, 70), new Player("Warmed Omari", 9, 17, 15, 65), new Player("Steve Mandanda", 6, 16, 15, 60)], [new Player("Gaëtan Laborde", 16, 10, 15, 75), new Player("Khephren Thuram", 13, 14, 15, 70), new Player("Jean-Clair Todibo", 13, 14, 15, 70), new Player("Dante", 9, 17, 15, 65), new Player("Kasper Schmeichel", 6, 16, 15, 60)], [new Player("Florian Sotoca", 16, 10, 15, 75), new Player("Seko Fofana", 13, 14, 15, 70), new Player("Kevin Danso", 13, 14, 15, 70), new Player("Facundo Medina", 9, 17, 15, 65), new Player("Brice Samba", 6, 16, 15, 60)], [new Player("Ludovic Blas", 15, 10, 15, 70), new Player("Andrei Girotto", 13, 14, 15, 65), new Player("Nicolas Pallois", 9, 17, 15, 65), new Player("Pedro Chirivella", 13, 14, 15, 65), new Player("Alban Lafont", 6, 16, 15, 60)]]);
// Serie A (Italy)
assignRealSquadsForLeague(leagueClubNamesItaly, [[new Player("Lautaro Martínez", 18, 11, 16, 95), new Player("Hakan Çalhanoğlu", 15, 13, 16, 80), new Player("Nicolò Barella", 14, 14, 16, 80), new Player("Federico Dimarco", 13, 13, 15, 75), new Player("Yann Sommer", 7, 18, 15, 70)], [new Player("Dusan Vlahovic", 17, 10, 15, 90), new Player("Federico Chiesa", 16, 10, 15, 85), new Player("Adrien Rabiot", 13, 14, 15, 80), new Player("Gleison Bremer", 9, 17, 15, 75), new Player("Wojciech Szczęsny", 6, 16, 15, 70)], [new Player("Rafael Leão", 18, 10, 16, 90), new Player("Olivier Giroud", 17, 10, 15, 85), new Player("Theo Hernández", 13, 14, 15, 80), new Player("Fikayo Tomori", 9, 17, 15, 75), new Player("Mike Maignan", 7, 19, 15, 75)], [new Player("Victor Osimhen", 19, 10, 17, 110), new Player("Khvicha Kvaratskhelia", 17, 11, 16, 90), new Player("Piotr Zieliński", 14, 13, 15, 80), new Player("Giovanni Di Lorenzo", 13, 14, 15, 80), new Player("Alex Meret", 6, 16, 15, 70)], [new Player("Paulo Dybala", 17, 10, 15, 85), new Player("Lorenzo Pellegrini", 14, 13, 15, 80), new Player("Chris Smalling", 9, 17, 15, 75), new Player("Bryan Cristante", 13, 14, 15, 75), new Player("Rui Patrício", 6, 16, 15, 70)], [new Player("Ciro Immobile", 17, 10, 15, 85), new Player("Sergej Milinković-Savić", 15, 13, 16, 80), new Player("Luis Alberto", 14, 13, 15, 80), new Player("Alessio Romagnoli", 9, 17, 15, 75), new Player("Ivan Provedel", 6, 16, 15, 70)], [new Player("Duván Zapata", 17, 10, 15, 80), new Player("Teun Koopmeiners", 14, 13, 15, 75), new Player("Marten de Roon", 13, 14, 15, 75), new Player("Giorgio Scalvini", 9, 17, 15, 70), new Player("Juan Musso", 6, 16, 15, 65)], [new Player("Nicolás González", 16, 10, 15, 75), new Player("Giacomo Bonaventura", 14, 13, 15, 70), new Player("Cristiano Biraghi", 13, 14, 15, 70), new Player("Nikola Milenković", 9, 17, 15, 65), new Player("Pietro Terracciano", 6, 16, 15, 60)], [new Player("Antonio Sanabria", 16, 10, 15, 70), new Player("Nikola Vlašić", 14, 13, 15, 65), new Player("Alessandro Buongiorno", 9, 17, 15, 65), new Player("Samuele Ricci", 13, 14, 15, 65), new Player("Vanja Milinković-Savić", 6, 16, 15, 60)]]);
// Eredivisie (Netherlands)
assignRealSquadsForLeague(leagueClubNamesNetherlands, [[new Player("Luuk de Jong", 16, 8, 15, 60), new Player("Joey Veerman", 14, 12, 15, 55), new Player("Johan Bakayoko", 15, 10, 15, 55), new Player("Olivier Boscagli", 10, 15, 15, 50), new Player("Walter Benítez", 7, 17, 15, 50)], [new Player("Steven Bergwijn", 16, 10, 15, 75), new Player("Brian Brobbey", 15, 10, 15, 70), new Player("Steven Berghuis", 14, 13, 15, 70), new Player("Jurrien Timber", 9, 17, 15, 65), new Player("Gerónimo Rulli", 6, 16, 15, 60)], [new Player("Santiago Giménez", 16, 10, 15, 75), new Player("Orkun Kökçü", 14, 13, 15, 70), new Player("David Hancko", 9, 17, 15, 65), new Player("Mats Wieffer", 13, 14, 15, 65), new Player("Justin Bijlow", 6, 16, 15, 60)], [new Player("Vangelis Pavlidis", 16, 10, 15, 70), new Player("Jordy Clasie", 14, 13, 15, 65), new Player("Bruno Martins Indi", 9, 17, 15, 65), new Player("Dani de Wit", 13, 14, 15, 65), new Player("Mathew Ryan", 6, 16, 15, 60)], [new Player("Ricky van Wolfswinkel", 16, 10, 15, 70), new Player("Ramiz Zerrouki", 14, 13, 15, 65), new Player("Robin Pröpper", 9, 17, 15, 65), new Player("Michal Sadílek", 13, 14, 15, 65), new Player("Lars Unnerstall", 6, 16, 15, 60)], [new Player("Anastasios Douvikas", 16, 10, 15, 70), new Player("Jens Toornstra", 14, 13, 15, 65), new Player("Nick Viergever", 9, 17, 15, 65), new Player("Sander van de Streek", 13, 14, 15, 65), new Player("Vasilis Barkas", 6, 16, 15, 60)], [new Player("Sydney van Hooijdonk", 16, 10, 15, 70), new Player("Pelle van Amersfoort", 14, 13, 15, 65), new Player("Sven van Beek", 9, 17, 15, 65), new Player("Thom Haye", 13, 14, 15, 65), new Player("Andries Noppert", 6, 16, 15, 60)], [new Player("Jørgen Strand Larsen", 16, 10, 15, 70), new Player("Michael de Leeuw", 14, 13, 15, 65), new Player("Bart van Hintum", 9, 17, 15, 65), new Player("Daleho Irandust", 13, 14, 15, 65), new Player("Peter Leeuwenburgh", 6, 16, 15, 60)], [new Player("Nikolai Baden Frederiksen", 16, 10, 15, 70), new Player("Riechedly Bazoer", 14, 13, 15, 65), new Player("Danilho Doekhi", 9, 17, 15, 65), new Player("Matus Bero", 13, 14, 15, 65), new Player("Markus Schubert", 6, 16, 15, 60)]]);
// Primeira Liga (Portugal)
assignRealSquadsForLeague(leagueClubNamesPortugal, [[new Player("Rafa Silva", 16, 12, 16, 60), new Player("João Mário", 14, 13, 15, 55), new Player("Ángel Di María", 15, 10, 15, 55), new Player("Nicolás Otamendi", 10, 15, 15, 50), new Player("Anatoliy Trubin", 7, 17, 15, 50)], [new Player("Mehdi Taremi", 17, 10, 15, 80), new Player("Otávio", 14, 13, 15, 75), new Player("Pepe", 9, 17, 15, 70), new Player("Mateus Uribe", 13, 14, 15, 70), new Player("Diogo Costa", 6, 16, 15, 65)], [new Player("Pedro Gonçalves", 16, 10, 15, 75), new Player("Gonçalo Inácio", 14, 13, 15, 70), new Player("Sebastián Coates", 9, 17, 15, 70), new Player("Manuel Ugarte", 13, 14, 15, 70), new Player("Antonio Adán", 6, 16, 15, 65)], [new Player("Ricardo Horta", 16, 10, 15, 75), new Player("Abel Ruiz", 14, 13, 15, 70), new Player("Vítor Tormena", 9, 17, 15, 70), new Player("Al Musrati", 13, 14, 15, 70), new Player("Matheus", 6, 16, 15, 65)], [new Player("André Silva", 16, 10, 15, 70), new Player("Tiago Silva", 14, 13, 15, 65), new Player("Toni Borevkovic", 9, 17, 15, 65), new Player("Mikel Villanueva", 13, 14, 15, 65), new Player("Bruno Varela", 6, 16, 15, 60)], [new Player("Yusupha Njie", 16, 10, 15, 70), new Player("Gustavo Sauer", 14, 13, 15, 65), new Player("Rodrigo Abascal", 9, 17, 15, 65), new Player("Sebastián Pérez", 13, 14, 15, 65), new Player("Rafael Bracali", 6, 16, 15, 60)], [new Player("André Franco", 16, 10, 15, 70), new Player("João Gamboa", 14, 13, 15, 65), new Player("Lucas Áfrico", 9, 17, 15, 65), new Player("Francisco Geraldes", 13, 14, 15, 65), new Player("Daniel Figueira", 6, 16, 15, 60)], [new Player("Simon Banza", 16, 10, 15, 70), new Player("Iván Jaime", 14, 13, 15, 65), new Player("Riccieli", 9, 17, 15, 65), new Player("Gustavo Assunção", 13, 14, 15, 65), new Player("Luiz Júnior", 6, 16, 15, 60)], [new Player("Clayton", 16, 10, 15, 70), new Player("Lucas Soares", 14, 13, 15, 65), new Player("Fernando Varela", 9, 17, 15, 65), new Player("Afonso Taira", 13, 14, 15, 65), new Player("Ricardo Batista", 6, 16, 15, 60)]]);
function makeOpponentTeam() {
// List of realistic Turkish club names for all leagues
var clubNames = leagueClubNames1 && leagueClubNames2 && leagueClubNames3 && leagueClubNames4 ? leagueClubNames1.concat(leagueClubNames2, leagueClubNames3, leagueClubNames4) : [];
// Defensive: If clubNames is not an array or is empty, fallback to a default
if (!clubNames || typeof clubNames.length !== "number" || clubNames.length === 0) {
clubNames = ["Default FC"];
}
// 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(12, 17);
var val = Math.floor((atk + def + sta) / 3) + randomInt(PLAYER_MIN_VALUE + 2, PLAYER_MIN_VALUE + 10);
allPlayers.push(new Player(randomName(), atk, def, sta, val));
}
updateSquadAndBench();
}
function updateSquadAndBench() {
squad = [];
bench = [];
for (var i = 0; i < allPlayers.length; i++) {
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),
// Added players:
new Player("Rafa Silva", 16, 12, 16, 60), new Player("Ferdi Kadıoğlu", 13, 15, 16, 55),
// More top players:
new Player("Kevin De Bruyne", 17, 14, 16, 120), new Player("Mohamed Salah", 19, 10, 16, 110), new Player("Robert Lewandowski", 20, 9, 15, 100), new Player("Bernardo Silva", 15, 14, 16, 95), new Player("Lautaro Martínez", 18, 11, 16, 95), new Player("Jadon Sancho", 16, 11, 15, 85), new Player("Trent Alexander-Arnold", 13, 15, 15, 85), new Player("Jules Koundé", 10, 17, 15, 80), new Player("Mike Maignan", 7, 19, 15, 75), new Player("João Cancelo", 13, 15, 15, 80), new Player("Frenkie de Jong", 14, 14, 16, 90), new Player("Christopher Nkunku", 17, 11, 15, 85), new Player("Kai Havertz", 16, 12, 15, 80), new Player("Rúben Dias", 9, 18, 15, 85), new Player("Alphonso Davies", 13, 15, 16, 90), new Player("Eduardo Camavinga", 13, 14, 16, 80), new Player("Mason Mount", 15, 12, 15, 75), new Player("Milinković-Savić", 15, 13, 16, 80), new Player("Nicolo Barella", 14, 14, 16, 80),
// Superstar additions:
new Player("Cristiano Ronaldo", 20, 8, 15, 90), new Player("Lionel Messi", 19, 9, 16, 90)];
// 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];
var seasonsTxt = p && typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null ? " (" + p.seasonsRemaining + "s)" : "";
var t = makeLabel(i + 1 + ". " + (p ? p.name : "N/A") + " [A:" + (p ? p.attack : "-") + " D:" + (p ? p.defense : "-") + " S:" + (p ? 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 table just above the opponent section, but below the transfer market
var leagueWidth = 600; // slightly larger
var leagueX = 80; // move to the left side of the screen
var leagueY = oppStartY - 650; // place above opponent section, below transfer market
if (leagueY < guiY + 600) {
leagueY = guiY + 600;
}
var leagueHeader = makeLabel("League 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];
var color = selectedTeamName && team.name === selectedTeamName ? "#00cec9" : "#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, leagueX, leagueY + 70 + i * 48, 38, color); // slightly larger font and spacing
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);
// --- Champions League group/knockout matches: show to the right of the league table ---
var clX = leagueX + leagueWidth + 80; // right of league table
var clY = leagueY;
if (championsLeagueActive || championsLeagueUserEliminated || championsLeagueLog && championsLeagueLog.length > 0 || championsLeagueGroupResults && championsLeagueGroupResults.length > 0) {
var clHeader = makeLabel("Şampiyonlar Ligi", clX, clY, 54, "#00b894");
game.addChild(clHeader);
opponentLabels.push(clHeader);
// Show group stage table if in group or just finished group
if (championsLeagueStage === "Group" && championsLeagueUserGroup && championsLeagueUserGroup.length === 4 && championsLeagueGroupResults && championsLeagueGroupResults.length === 4) {
var groupTableY = clY + 70;
var groupHeader = makeLabel("Grup Tablosu", clX, groupTableY, 40, "#fff");
game.addChild(groupHeader);
opponentLabels.push(groupHeader);
// Sort by points, then goal diff, then goals for
var sortedGroup = championsLeagueGroupResults.slice().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;
});
for (var i = 0; i < sortedGroup.length; i++) {
var team = sortedGroup[i];
var color = selectedTeamName && team.name === selectedTeamName ? "#00cec9" : "#fff";
var gd = team.gf - team.ga;
var labelTxt = i + 1 + ". " + team.name + " Pts:" + team.points + " GF:" + team.gf + " GA:" + team.ga + " GD:" + gd;
var teamLabel = makeLabel(labelTxt, clX, groupTableY + 50 + i * 40, 32, color);
game.addChild(teamLabel);
opponentLabels.push(teamLabel);
}
groupTableY += 50 + 4 * 40 + 20;
// Show next group match info if not finished
if (championsLeagueCurrentRound <= 3 && championsLeagueOpponent) {
var nextOpp = makeLabel("Sonraki Grup Rakibi: " + championsLeagueOpponent.name, clX, groupTableY, 36, "#fdcb6e");
game.addChild(nextOpp);
opponentLabels.push(nextOpp);
}
}
// Show knockout stage info if in semifinals or final
if ((championsLeagueStage === "Semifinal" || championsLeagueStage === "Final") && championsLeagueKnockoutOpponent) {
var koY = clY + 320;
var stageTxt = championsLeagueStage === "Semifinal" ? "Yarı Final" : "Final";
var koHeader = makeLabel("ŞL " + stageTxt, clX, koY, 40, "#fff");
game.addChild(koHeader);
opponentLabels.push(koHeader);
var oppName = championsLeagueKnockoutOpponent.name;
var oppLabel = makeLabel("Rakip: " + oppName, clX, koY + 50, 36, "#fdcb6e");
game.addChild(oppLabel);
opponentLabels.push(oppLabel);
}
// Show last Champions League match results (from log)
if (showMatchLog._shownCLLogs && showMatchLog._shownCLLogs.length > 0) {
var logY = clY + 500;
var logHeader = makeLabel("ŞL Sonuçları", clX, logY, 36, "#00b894");
game.addChild(logHeader);
opponentLabels.push(logHeader);
var shownLogs = showMatchLog._shownCLLogs.slice(-5); // show last 5
for (var i = 0; i < shownLogs.length; i++) {
var logLine = makeLabel(shownLogs[i], clX, logY + 40 + i * 32, 28, "#fff");
game.addChild(logLine);
opponentLabels.push(logLine);
}
}
}
// Opponent team player display removed as per requirements
}
function clearMatchText() {
if (matchText) {
matchText.destroy();
matchText = null;
}
}
function showMatchLog() {
clearMatchText();
// League log only
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);
// --- Champions League summary: show in a separate area, never repeat ---
// Remove any previous CL summary
if (showMatchLog._clText && showMatchLog._clText.destroy) {
showMatchLog._clText.destroy();
showMatchLog._clText = null;
}
// Only show if there are new CL results to show (and not already shown)
if (championsLeagueLog && championsLeagueLog.length > 0) {
// Show CL summary at top right, away from league log
var clText = new Text2("=== Şampiyonlar Ligi ===\n" + championsLeagueLog.join("\n"), {
size: 48,
fill: 0x00B894,
wordWrap: true,
wordWrapWidth: 900
});
clText.x = 1200;
clText.y = 120;
game.addChild(clText);
showMatchLog._clText = clText;
// Mark CL log as shown so it won't be shown again
// Instead of clearing the log immediately, keep a record of shown matches
if (!showMatchLog._shownCLLogs) showMatchLog._shownCLLogs = [];
for (var i = 0; i < championsLeagueLog.length; i++) {
showMatchLog._shownCLLogs.push(championsLeagueLog[i]);
}
championsLeagueLog = [];
}
}
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 ---
// 1. Lig (Süper Lig), 2. Lig, 3. Lig, 4. Lig takımları
var leagueClubNames1 = ["Sivasspor", "Galatasaray", "Fenerbahce", "Trabzonspor", "Besiktas", "Basaksehir", "Konyaspor", "Antalyaspor", "Alanyaspor"];
var leagueClubNames2 = ["Göztepe", "Sakaryaspor", "Kocaelispor", "Eyüpspor", "Bodrumspor", "Gençlerbirliği", "Erzurumspor", "Boluspor", "Bandırmaspor"];
var leagueClubNames3 = ["Amedspor", "Inegölspor", "Afjet Afyonspor", "Diyarbekirspor", "Kırklarelispor", "Serik Belediyespor", "Kırşehir FK", "Nazilli Belediyespor", "Zonguldak Kömürspor"];
var leagueClubNames4 = ["Karşıyaka", "Bucaspor", "Erokspor", "Şanlıurfaspor", "Kastamonuspor", "Adıyaman FK", "Batman Petrolspor", "Somaspor", "Düzcespor"];
// --- OTHER COUNTRIES' LEAGUES (EXAMPLES) ---
var leagueClubNamesEngland = ["Manchester City", "Arsenal", "Liverpool", "Chelsea", "Manchester United", "Tottenham", "Newcastle", "Aston Villa", "Brighton", "West Ham United", "Crystal Palace", "Fulham", "Wolverhampton", "Everton", "Brentford", "Bournemouth", "Nottingham Forest", "Burnley", "Sheffield United", "Luton Town"];
var leagueClubNamesGermany = ["Bayern Munich", "Borussia Dortmund", "RB Leipzig", "Bayer Leverkusen", "Eintracht Frankfurt", "Union Berlin", "Freiburg", "Wolfsburg", "Stuttgart"];
var leagueClubNamesSpain = ["Real Madrid", "Barcelona", "Atletico Madrid", "Sevilla", "Real Sociedad", "Villarreal", "Real Betis", "Athletic Bilbao", "Valencia"];
var leagueClubNamesFrance = ["Paris SG", "Marseille", "Lyon", "Monaco", "Lille", "Rennes", "Nice", "Lens", "Nantes"];
var leagueClubNamesItaly = ["Inter", "Juventus", "Milan", "Napoli", "Roma", "Lazio", "Atalanta", "Fiorentina", "Torino"];
var leagueClubNamesNetherlands = ["PSV", "Ajax", "Feyenoord", "AZ Alkmaar", "Twente", "Utrecht", "Heerenveen", "Groningen", "Vitesse"];
var leagueClubNamesPortugal = ["Benfica", "Porto", "Sporting CP", "Braga", "Guimaraes", "Boavista", "Estoril", "Famalicao", "Casa Pia"];
// By default, start in 1. Lig. Set this to 2 to start in 2. Lig, 3 for 3. Lig, 4 for 4. Lig, 101+ for other countries
var currentLeagueLevel = 1; // 1 = Süper Lig, 2 = 2. Lig, 3 = 3. Lig, 4 = 4. Lig, 101 = England, 102 = Germany, etc.
// This will be set to leagueClubNames1, leagueClubNames2, leagueClubNames3, leagueClubNames4, or a foreign league
var leagueClubNames = leagueClubNames1;
var leagueTeams = []; // [{name, points, played, wins, draws, losses, goalsFor, goalsAgainst}]
var leagueFixtures = []; // [{homeIdx, awayIdx}]
var currentFixtureIdx = 0;
var userTeamIdx = 0; // always 0
function initLeague() {
leagueTeams = [];
// Use correct league club names for current division
var clubs;
if (currentLeagueLevel === 1) {
clubs = leagueClubNames1;
} else if (currentLeagueLevel === 2) {
clubs = leagueClubNames2;
} else if (currentLeagueLevel === 3) {
clubs = leagueClubNames3;
} else if (currentLeagueLevel === 4) {
clubs = leagueClubNames4;
} else {
clubs = leagueClubNames1;
}
for (var i = 0; i < clubs.length; i++) {
var clubName = clubs[i];
leagueTeams.push({
name: clubName,
points: 0,
played: 0,
wins: 0,
draws: 0,
losses: 0,
goalsFor: 0,
goalsAgainst: 0,
// Attach real squad if available for league simulation
realSquad: realSquads[clubName] ? realSquads[clubName].map(function (p) {
return clonePlayer(p);
}) : null
});
}
// Generate fixtures: each team plays every other team twice (home/away), skip empty matches
leagueFixtures = [];
var n = leagueTeams.length;
for (var i = 0; i < n; i++) {
for (var j = 0; j < n; j++) {
if (i !== j) {
// Only add each pair twice (home/away)
if (i < j) {
// Only add if both teams have a name (not empty/undefined)
if (leagueTeams[i].name && leagueTeams[j].name) {
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;
}
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;
// --- CHAMPIONS LEAGUE: Simulate group/knockout matches if active and not eliminated ---
if (championsLeagueActive && !championsLeagueUserEliminated) {
// Champions League structure: 8 teams, 2 groups of 4, top 2 advance to semifinals, then final
if (championsLeagueCurrentRound === 0) {
// Group draw
championsLeagueUserGroup = [];
championsLeagueGroupResults = [];
// Split into 2 groups of 4
var groupA = championsLeagueTeams.slice(0, 4);
var groupB = championsLeagueTeams.slice(4, 8);
// Find which group user is in
var userGroup = null;
for (var i = 0; i < 4; i++) {
if (selectedTeamName && groupA[i].name === selectedTeamName) userGroup = groupA;
if (selectedTeamName && groupB[i].name === selectedTeamName) userGroup = groupB;
}
championsLeagueUserGroup = userGroup;
championsLeagueGroupResults = [];
for (var i = 0; i < 4; i++) {
championsLeagueGroupResults.push({
name: userGroup[i].name,
points: 0,
gf: 0,
ga: 0
});
}
championsLeagueCurrentRound = 1;
championsLeagueStage = "Group";
championsLeagueUserPoints = 0;
championsLeagueLog = [];
}
// Group stage: 3 rounds, each user group team plays each other once
if (championsLeagueStage === "Group" && championsLeagueCurrentRound <= 3) {
// Find user group
var group = championsLeagueUserGroup;
var userIdx = -1;
for (var i = 0; i < 4; i++) if (selectedTeamName && group[i].name === selectedTeamName) userIdx = i;
// Play next group match for user
var oppIdx = (championsLeagueCurrentRound - 1 + userIdx) % 4;
if (oppIdx === userIdx) oppIdx = (oppIdx + 1) % 4;
var opp = group[oppIdx];
championsLeagueOpponent = opp;
// Simulate match
var userGoals = 0,
oppGoals = 0;
for (var turn = 0; turn < 5; turn++) {
var atkP = squad[turn];
var defP = opp.players[turn];
var atkChance = atkP.attack + randomInt(0, atkP.stamina);
var defChance = 0;
if (defP && typeof defP.defense === "number" && typeof defP.stamina === "number") {
defChance = defP.defense + randomInt(0, defP.stamina);
} else {
// fallback: use average defense/stamina or 0
defChance = 10 + randomInt(0, 10);
}
if (atkChance > defChance + 3) userGoals++;
var oAtkP = opp.players[turn];
var oDefP = squad[turn];
var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina);
var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina);
if (oAtkChance > oDefChance + 3) oppGoals++;
}
// Update group table
for (var i = 0; i < 4; i++) {
if (selectedTeamName && championsLeagueGroupResults[i].name === selectedTeamName) {
championsLeagueGroupResults[i].gf += userGoals;
championsLeagueGroupResults[i].ga += oppGoals;
if (userGoals > oppGoals) championsLeagueGroupResults[i].points += 3;else if (userGoals === oppGoals) championsLeagueGroupResults[i].points += 1;
}
if (championsLeagueGroupResults[i].name === opp.name) {
championsLeagueGroupResults[i].gf += oppGoals;
championsLeagueGroupResults[i].ga += userGoals;
if (oppGoals > userGoals) championsLeagueGroupResults[i].points += 3;else if (userGoals === oppGoals) championsLeagueGroupResults[i].points += 1;
}
}
championsLeagueLog.push("Champions League Group Match: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + opp.name);
if (userGoals > oppGoals) championsLeagueLog.push((selectedTeamName || "You") + " win! +$10M prestige bonus");else if (userGoals === oppGoals) championsLeagueLog.push("Draw. +$3M prestige bonus");else championsLeagueLog.push((selectedTeamName || "You") + " lose.");
budget += userGoals > oppGoals ? 10 : userGoals === oppGoals ? 3 : 0;
championsLeagueCurrentRound++;
if (championsLeagueCurrentRound > 3) {
// Group stage over, check if user advances
championsLeagueGroupResults.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;
});
var userPos = 1;
for (var i = 0; i < 4; i++) if (selectedTeamName && championsLeagueGroupResults[i].name === selectedTeamName) userPos = i + 1;
if (userPos <= 2) {
championsLeagueStage = "Semifinal";
championsLeagueKnockoutTeams = [championsLeagueGroupResults[0].name, championsLeagueGroupResults[1].name];
championsLeagueKnockoutRound = 1;
championsLeagueLog.push((selectedTeamName || "You") + " advance to the Champions League Semifinals!");
} else {
championsLeagueActive = false;
championsLeagueUserEliminated = true;
championsLeagueLog.push((selectedTeamName || "You") + " are eliminated from the Champions League group stage.");
}
}
} else if (championsLeagueStage === "Semifinal" && championsLeagueKnockoutRound === 1) {
// Find opponent from other group
var otherGroup = [];
for (var i = 0; i < championsLeagueTeams.length; i++) {
var t = championsLeagueTeams[i];
var inUserGroup = false;
for (var j = 0; j < 4; j++) if (championsLeagueUserGroup[j].name === t.name) inUserGroup = true;
if (!inUserGroup) otherGroup.push(t);
}
// Find top 2 from other group
var otherGroupResults = [];
for (var i = 0; i < 4; i++) {
otherGroupResults.push({
name: otherGroup[i].name,
points: 0,
gf: 0,
ga: 0
});
}
// Simulate other group (random for now)
for (var r = 0; r < 3; r++) {
for (var i = 0; i < 4; i++) {
var a = otherGroup[i];
var b = otherGroup[(i + r + 1) % 4];
var aGoals = randomInt(0, 4),
bGoals = randomInt(0, 4);
for (var k = 0; k < 4; k++) {
if (otherGroupResults[k].name === a.name) {
otherGroupResults[k].gf += aGoals;
otherGroupResults[k].ga += bGoals;
if (aGoals > bGoals) otherGroupResults[k].points += 3;else if (aGoals === bGoals) otherGroupResults[k].points += 1;
}
if (otherGroupResults[k].name === b.name) {
otherGroupResults[k].gf += bGoals;
otherGroupResults[k].ga += aGoals;
if (bGoals > aGoals) otherGroupResults[k].points += 3;else if (aGoals === bGoals) otherGroupResults[k].points += 1;
}
}
}
}
otherGroupResults.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;
});
// User plays 1st of other group if user was 2nd, else 2nd
var userPos = 1;
for (var i = 0; i < 2; i++) if (selectedTeamName && championsLeagueKnockoutTeams[i] === selectedTeamName) userPos = i + 1;
var oppName = userPos === 1 ? otherGroupResults[1].name : otherGroupResults[0].name;
var opp = null;
for (var i = 0; i < championsLeagueTeams.length; i++) if (championsLeagueTeams[i].name === oppName) opp = championsLeagueTeams[i];
championsLeagueKnockoutOpponent = opp;
// Simulate match
var userGoals = 0,
oppGoals = 0;
for (var turn = 0; turn < 5; turn++) {
var atkP = squad[turn];
var defP = opp.players[turn];
var atkChance = atkP.attack + randomInt(0, atkP.stamina);
var defChance = 0;
if (defP && typeof defP.defense === "number" && typeof defP.stamina === "number") {
defChance = defP.defense + randomInt(0, defP.stamina);
} else {
defChance = 10 + randomInt(0, 10);
}
if (atkChance > defChance + 3) userGoals++;
var oAtkP = opp.players[turn];
var oDefP = squad[turn];
var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina);
var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina);
if (oAtkChance > oDefChance + 3) oppGoals++;
}
championsLeagueLog.push("Champions League Semifinal: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + opp.name);
if (userGoals > oppGoals) {
championsLeagueLog.push((selectedTeamName || "You") + " win! " + (selectedTeamName || "You") + " advance to the Champions League Final! +$20M bonus");
budget += 20;
championsLeagueStage = "Final";
championsLeagueKnockoutRound = 2;
} else if (userGoals === oppGoals) {
championsLeagueLog.push("Draw. Decided by coin toss...");
if (randomInt(0, 1) === 0) {
championsLeagueLog.push((selectedTeamName || "You") + " win the toss! " + (selectedTeamName || "You") + " advance to the Final! +$20M bonus");
budget += 20;
championsLeagueStage = "Final";
championsLeagueKnockoutRound = 2;
} else {
championsLeagueLog.push((selectedTeamName || "You") + " lose the toss. Eliminated in Semifinal.");
championsLeagueActive = false;
championsLeagueUserEliminated = true;
}
} else {
championsLeagueLog.push((selectedTeamName || "You") + " lose. Eliminated in Semifinal.");
championsLeagueActive = false;
championsLeagueUserEliminated = true;
}
} else if (championsLeagueStage === "Final" && championsLeagueKnockoutRound === 2) {
// Find other finalist
var otherFinalist = null;
for (var i = 0; i < championsLeagueTeams.length; i++) {
var t = championsLeagueTeams[i];
if (selectedTeamName && t.name !== selectedTeamName && t.name !== championsLeagueKnockoutOpponent.name) {
otherFinalist = t;
break;
}
}
if (!otherFinalist) {
// Pick random
otherFinalist = championsLeagueTeams[randomInt(0, championsLeagueTeams.length - 1)];
}
championsLeagueKnockoutOpponent = otherFinalist;
// Simulate match
var userGoals = 0,
oppGoals = 0;
for (var turn = 0; turn < 5; turn++) {
var atkP = squad[turn];
var defP = otherFinalist.players[turn];
var atkChance = atkP.attack + randomInt(0, atkP.stamina);
var defChance = 0;
if (defP && typeof defP.defense === "number" && typeof defP.stamina === "number") {
defChance = defP.defense + randomInt(0, defP.stamina);
} else {
defChance = 10 + randomInt(0, 10);
}
if (atkChance > defChance + 3) userGoals++;
var oAtkP = otherFinalist.players[turn];
var oDefP = squad[turn];
var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina);
var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina);
if (oAtkChance > oDefChance + 3) oppGoals++;
}
championsLeagueLog.push("Champions League Final: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + otherFinalist.name);
if (userGoals > oppGoals) {
championsLeagueLog.push((selectedTeamName || "You") + " are Champions League Winners! +$50M and huge prestige!");
budget += 50;
championsLeagueActive = false;
championsLeagueUserEliminated = true;
} else if (userGoals === oppGoals) {
championsLeagueLog.push("Draw. Decided by coin toss...");
if (randomInt(0, 1) === 0) {
championsLeagueLog.push((selectedTeamName || "You") + " win the toss! " + (selectedTeamName || "You") + " are Champions League Winners! +$50M and huge prestige!");
budget += 50;
championsLeagueActive = false;
championsLeagueUserEliminated = true;
} else {
championsLeagueLog.push((selectedTeamName || "You") + " lose the toss. Runners-up in the Champions League.");
championsLeagueActive = false;
championsLeagueUserEliminated = true;
}
} else {
championsLeagueLog.push((selectedTeamName || "You") + " lose. Runners-up in the Champions League.");
championsLeagueActive = false;
championsLeagueUserEliminated = true;
}
}
}
// Find all fixtures for this matchday (all teams play one match)
if (currentFixtureIdx >= leagueFixtures.length) {
matchLog.push("Season is over!");
showMatchLog();
matchInProgress = false;
return;
}
// 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;
}
}
}
// Simulate all matches in this matchday
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.realSquad) {
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.realSquad) {
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
var homeGoals = 0,
awayGoals = 0;
for (var turn = 0; turn < 5; turn++) {
// Home attack
var atkP = homePlayers[turn];
var defP = awayPlayers[turn];
var atkChance = atkP.attack + randomInt(0, atkP.stamina);
var defChance = defP.defense + randomInt(0, defP.stamina);
if (atkChance > defChance + 3) {
homeGoals++;
}
// Away attack
var oAtkP = awayPlayers[turn];
var oDefP = homePlayers[turn];
var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina);
var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina);
if (oAtkChance > oDefChance + 3) {
awayGoals++;
}
}
// Update league table
homeTeam.played += 1;
awayTeam.played += 1;
homeTeam.goalsFor += homeGoals;
homeTeam.goalsAgainst += awayGoals;
awayTeam.goalsFor += awayGoals;
awayTeam.goalsAgainst += homeGoals;
if (homeGoals > awayGoals) {
homeTeam.points += 3;
homeTeam.wins += 1;
awayTeam.losses += 1;
} else if (homeGoals < awayGoals) {
awayTeam.points += 3;
awayTeam.wins += 1;
homeTeam.losses += 1;
} else {
homeTeam.points += 1;
awayTeam.points += 1;
homeTeam.draws += 1;
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].name;
// Track actual goals for user and opponent for correct log
var userScored = 0;
var oppScored = 0;
for (var turn = 0; turn < 5; turn++) {
// User attack
var atkP = squad[turn];
var defP = homeIdx === userTeamIdx ? awayPlayers[turn] : homePlayers[turn];
var atkChance = atkP.attack + randomInt(0, atkP.stamina);
var defChance = defP.defense + randomInt(0, defP.stamina);
if (atkChance > defChance + 3 && userScored < (homeIdx === userTeamIdx ? homeGoals : awayGoals)) {
matchLog.push("Minute " + (turn * 18 + 5) + ": " + atkP.name + " scores!");
userScored++;
} 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];
var oAtkChance = oAtkP.attack + randomInt(0, oAtkP.stamina);
var oDefChance = oDefP.defense + randomInt(0, oDefP.stamina);
if (oAtkChance > oDefChance + 3 && oppScored < (homeIdx === userTeamIdx ? awayGoals : homeGoals)) {
matchLog.push("Minute " + (turn * 18 + 12) + ": " + oAtkP.name + " scores!");
oppScored++;
} else if (oDefChance > oAtkChance + 5) {
matchLog.push("Minute " + (turn * 18 + 15) + ": " + oDefP.name + " blocks a shot.");
}
}
matchLog.push("Full Time: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + oppName);
// Rewards
if (userGoals > oppGoals) {
matchResult = "win";
matchLog.push((selectedTeamName || "You") + " win! +$20M");
budget += 20;
} else if (userGoals < oppGoals) {
matchResult = "lose";
matchLog.push((selectedTeamName || "You") + " lose.");
} else {
matchResult = "draw";
matchLog.push("Draw. +$5M");
budget += 5;
}
}
}
// Advance fixture pointer by number of fixtures played this matchday
currentFixtureIdx += matchdayFixtures.length;
updateBudgetText();
showMatchLog();
matchInProgress = false;
// If Champions League is active and not eliminated, and there are more CL matches to play, only show one CL match result at a time
if (championsLeagueActive && !championsLeagueUserEliminated) {
// Only auto-play next CL match if a flag is set (to prevent showing the same match again)
if (!simulateMatch._justPlayedCL) {
// Group stage: play next group match if not finished
if (championsLeagueStage === "Group" && championsLeagueCurrentRound <= 3) {
// Set flag so next simulateMatch call doesn't immediately repeat
simulateMatch._justPlayedCL = true;
LK.setTimeout(function () {
simulateMatch._justPlayedCL = false;
simulateMatch();
}, 1200);
}
// Semifinal: if just finished, and now in Final, auto-play Final
else if (championsLeagueStage === "Final" && championsLeagueKnockoutRound === 2) {
simulateMatch._justPlayedCL = true;
LK.setTimeout(function () {
simulateMatch._justPlayedCL = false;
simulateMatch();
}, 1200);
}
}
}
}
function refreshUI() {
clearAllUI();
// Remove any previous CL summary if present (in case of UI refresh)
if (showMatchLog._clText && showMatchLog._clText.destroy) {
showMatchLog._clText.destroy();
showMatchLog._clText = null;
}
// 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)
// Always update opponentTeam to match the next fixture before updating UI
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
if (!opponentTeam || opponentTeam.name !== leagueTeams[oppIdx].name) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
}
updateOpponentLabels();
updateBudgetText();
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!");
// Do NOT call refreshUI here to avoid screen reset
}
}, 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;
}
// --- Limit to at most 1 Champions League match per Play Match button press ---
if (championsLeagueActive && !championsLeagueUserEliminated) {
simulateMatch._justPlayedCL = true;
}
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 (selectedTeamName && sortedLeague[i].name === selectedTeamName) {
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(); // 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 QUALIFICATION ---
// Sadece 1. olan takım ve diğer liglerin şampiyonları gitsin
championsLeagueUserQualified = false;
var leagueChampionName = sortedLeague[0].name;
// --- PROMOTION/DEMOTION SYSTEM ---
// Küme düşme ve üst lige çıkma sistemi
// 4. Lig'de 1. bitiren kullanıcı üst lige çıkar
if (currentLeagueLevel === 4 && selectedTeamName && leagueChampionName === selectedTeamName) {
showInfo("Tebrikler! 4. Lig'i kazandınız ve 3. Lig'e yükseldiniz!");
currentLeagueLevel = 3;
leagueClubNames = leagueClubNames3;
// Reset league for 3. Lig
initLeague();
// Place user team in 3. Lig
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// 4. Lig'den 3. Lig'e çıkan kullanıcı, 3. Lig'den sonuncu olan takımla yer değiştirir
var lig3LastIdx = leagueTeams.length - 1;
var relegatedTeamName = leagueTeams[lig3LastIdx].name;
// 4. Lig listesine düşen takımı ekle
if (leagueClubNames4.indexOf(relegatedTeamName) === -1) {
leagueClubNames4.push(relegatedTeamName);
}
// Kullanıcı takımını 4. Lig listesinden çıkar
var userIdxIn4 = leagueClubNames4.indexOf(selectedTeamName);
if (userIdxIn4 !== -1) {
leagueClubNames4.splice(userIdxIn4, 1);
}
// 3. Lig listesinden düşen takımı çıkar
var relegatedIdxIn3 = leagueClubNames3.indexOf(relegatedTeamName);
if (relegatedIdxIn3 !== -1) {
leagueClubNames3.splice(relegatedIdxIn3, 1);
}
// Kullanıcı takımını 3. Lig listesine ekle
if (leagueClubNames3.indexOf(selectedTeamName) === -1) {
leagueClubNames3.push(selectedTeamName);
}
initTransferList();
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// 3. Lig'de 1. bitiren kullanıcı üst lige çıkar
if (currentLeagueLevel === 3 && selectedTeamName && leagueChampionName === selectedTeamName) {
showInfo("Tebrikler! 3. Lig'i kazandınız ve 2. Lig'e yükseldiniz!");
currentLeagueLevel = 2;
leagueClubNames = leagueClubNames2;
// Reset league for 2. Lig
initLeague();
// Place user team in 2. Lig
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// 3. Lig'den 2. Lig'e çıkan kullanıcı, 2. Lig'den sonuncu olan takımla yer değiştirir
var lig2LastIdx = leagueTeams.length - 1;
var relegatedTeamName = leagueTeams[lig2LastIdx].name;
// 3. Lig listesine düşen takımı ekle
if (leagueClubNames3.indexOf(relegatedTeamName) === -1) {
leagueClubNames3.push(relegatedTeamName);
}
// Kullanıcı takımını 3. Lig listesinden çıkar
var userIdxIn3 = leagueClubNames3.indexOf(selectedTeamName);
if (userIdxIn3 !== -1) {
leagueClubNames3.splice(userIdxIn3, 1);
}
// 2. Lig listesinden düşen takımı çıkar
var relegatedIdxIn2 = leagueClubNames2.indexOf(relegatedTeamName);
if (relegatedIdxIn2 !== -1) {
leagueClubNames2.splice(relegatedIdxIn2, 1);
}
// Kullanıcı takımını 2. Lig listesine ekle
if (leagueClubNames2.indexOf(selectedTeamName) === -1) {
leagueClubNames2.push(selectedTeamName);
}
initTransferList();
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// 2. Lig'de 1. bitiren kullanıcı üst lige çıkar
if (currentLeagueLevel === 2 && selectedTeamName && leagueChampionName === selectedTeamName) {
showInfo("Tebrikler! 2. Lig'i kazandınız ve Süper Lig'e yükseldiniz!");
currentLeagueLevel = 1;
leagueClubNames = leagueClubNames1;
// Reset league for Süper Lig
initLeague();
// Place user team in Süper Lig
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// 2. Lig'den Süper Lig'e çıkan kullanıcı, Süper Lig'den sonuncu olan takımla yer değiştirir
// Süper Lig'den sonuncu olan takım 2. Lig'e düşer
// Sadece gerçek takımlar arasında değişim yapılır, kullanıcı takımı hariç
var superLigLastIdx = leagueTeams.length - 1;
var relegatedTeamName = leagueTeams[superLigLastIdx].name;
// 2. Lig'e düşen takım, 2. Lig listesine eklenir
if (leagueClubNames2.indexOf(relegatedTeamName) === -1) {
leagueClubNames2.push(relegatedTeamName);
}
// Kullanıcı takımı 2. Lig listesinden çıkarılır (eğer varsa)
var userIdxIn2 = leagueClubNames2.indexOf(selectedTeamName);
if (userIdxIn2 !== -1) {
leagueClubNames2.splice(userIdxIn2, 1);
}
// Süper Lig listesinden düşen takımı çıkar
var relegatedIdxIn1 = leagueClubNames1.indexOf(relegatedTeamName);
if (relegatedIdxIn1 !== -1) {
leagueClubNames1.splice(relegatedIdxIn1, 1);
}
// Kullanıcı takımını Süper Lig listesine ekle (eğer yoksa)
if (leagueClubNames1.indexOf(selectedTeamName) === -1) {
leagueClubNames1.push(selectedTeamName);
}
// Only reset transfer market for new season
initTransferList();
// Set first opponent
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// Süper Lig'de sonuncu bitiren kullanıcı 2. Lig'e düşer
if (currentLeagueLevel === 1 && selectedTeamName && sortedLeague[sortedLeague.length - 1].name === selectedTeamName) {
showInfo("Üzgünüz! Süper Lig'de sonuncu oldunuz ve 2. Lig'e düştünüz.");
currentLeagueLevel = 2;
leagueClubNames = leagueClubNames2;
// Reset league for 2. Lig
initLeague();
// Place user team in 2. Lig
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// Süper Lig'den düşen kullanıcı takımını Süper Lig listesinden çıkar
var userIdxIn1 = leagueClubNames1.indexOf(selectedTeamName);
if (userIdxIn1 !== -1) {
leagueClubNames1.splice(userIdxIn1, 1);
}
// 2. Lig'e düşen kullanıcı takımını 2. Lig listesine ekle (eğer yoksa)
if (leagueClubNames2.indexOf(selectedTeamName) === -1) {
leagueClubNames2.push(selectedTeamName);
}
// 2. Lig'den çıkan takımı Süper Lig'e ekle (otomatik olarak bir üstteki kodda yapılır)
// Only reset transfer market for new season
initTransferList();
// Set first opponent
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// 2. Lig'de sonuncu bitiren kullanıcı 3. Lig'e düşer
if (currentLeagueLevel === 2 && selectedTeamName && sortedLeague[sortedLeague.length - 1].name === selectedTeamName) {
showInfo("Üzgünüz! 2. Lig'de sonuncu oldunuz ve 3. Lig'e düştünüz.");
currentLeagueLevel = 3;
leagueClubNames = leagueClubNames3;
// Reset league for 3. Lig
initLeague();
// Place user team in 3. Lig
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// 2. Lig'den düşen kullanıcı takımını 2. Lig listesinden çıkar
var userIdxIn2 = leagueClubNames2.indexOf(selectedTeamName);
if (userIdxIn2 !== -1) {
leagueClubNames2.splice(userIdxIn2, 1);
}
// 3. Lig listesine ekle
if (leagueClubNames3.indexOf(selectedTeamName) === -1) {
leagueClubNames3.push(selectedTeamName);
}
initTransferList();
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// 3. Lig'de sonuncu bitiren kullanıcı 4. Lig'e düşer
if (currentLeagueLevel === 3 && selectedTeamName && sortedLeague[sortedLeague.length - 1].name === selectedTeamName) {
showInfo("Üzgünüz! 3. Lig'de sonuncu oldunuz ve 4. Lig'e düştünüz.");
currentLeagueLevel = 4;
leagueClubNames = leagueClubNames4;
// Reset league for 4. Lig
initLeague();
// Place user team in 4. Lig
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// 3. Lig'den düşen kullanıcı takımını 3. Lig listesinden çıkar
var userIdxIn3 = leagueClubNames3.indexOf(selectedTeamName);
if (userIdxIn3 !== -1) {
leagueClubNames3.splice(userIdxIn3, 1);
}
// 4. Lig listesine ekle
if (leagueClubNames4.indexOf(selectedTeamName) === -1) {
leagueClubNames4.push(selectedTeamName);
}
initTransferList();
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// --- Süper Lig: Champions League qualification as before ---
if (currentLeagueLevel === 1) {
if (selectedTeamName && leagueChampionName === selectedTeamName) {
championsLeagueUserQualified = true;
}
// Prepare Champions League teams for next season
championsLeagueTeams = [];
// 1. olan takımı ekle (kullanıcı ise kendi kadrosu, değilse gerçek kadro veya random)
if (selectedTeamName && leagueChampionName === selectedTeamName) {
championsLeagueTeams.push({
name: selectedTeamName,
players: squad.map(clonePlayer)
});
} else {
// Find real squad or make random
var real = realSquads[leagueChampionName];
var players = real ? real.map(clonePlayer) : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()];
championsLeagueTeams.push({
name: leagueChampionName,
players: players
});
}
// Diğer liglerin şampiyonlarını ekle (örnek: İngiltere, Almanya, İspanya, Fransa, İtalya, Hollanda, Portekiz)
// Her biri için örnek kadro ekleniyor
var otherChampions = [{
name: "Manchester City",
players: [new Player("Erling Haaland", 21, 10, 18, 170), new Player("Phil Foden", 17, 13, 17, 130), new Player("Kevin De Bruyne", 17, 14, 16, 120), new Player("Rodri", 14, 18, 17, 120), new Player("Ederson", 6, 18, 16, 90)]
}, {
name: "Bayern Munich",
players: [new Player("Jamal Musiala", 17, 12, 17, 120), new Player("Harry Kane", 20, 10, 16, 100), new Player("Joshua Kimmich", 14, 15, 16, 100), new Player("Leroy Sané", 17, 10, 16, 95), new Player("Manuel Neuer", 6, 19, 16, 90)]
}, {
name: "Real Madrid",
players: [new Player("Vinícius Júnior", 19, 12, 18, 150), new Player("Jude Bellingham", 18, 14, 18, 150), new Player("Rodrygo", 16, 10, 16, 100), new Player("Toni Kroos", 14, 15, 15, 90), new Player("Thibaut Courtois", 7, 19, 16, 90)]
}, {
name: "Paris SG",
players: [new Player("Kylian Mbappé", 20, 12, 19, 180), new Player("Ousmane Dembélé", 17, 10, 16, 90), new Player("Achraf Hakimi", 13, 15, 16, 90), new Player("Marquinhos", 10, 17, 16, 90), new Player("Gianluigi Donnarumma", 6, 18, 16, 90)]
}, {
name: "Inter",
players: [new Player("Lautaro Martínez", 18, 11, 16, 95), new Player("Hakan Çalhanoğlu", 15, 13, 16, 80), new Player("Nicolò Barella", 14, 14, 16, 80), new Player("Federico Dimarco", 13, 13, 15, 75), new Player("Yann Sommer", 7, 18, 15, 70)]
}, {
name: "PSV",
players: [new Player("Luuk de Jong", 16, 8, 15, 60), new Player("Joey Veerman", 14, 12, 15, 55), new Player("Johan Bakayoko", 15, 10, 15, 55), new Player("Olivier Boscagli", 10, 15, 15, 50), new Player("Walter Benítez", 7, 17, 15, 50)]
}, {
name: "Benfica",
players: [new Player("Rafa Silva", 16, 12, 16, 60), new Player("João Mário", 14, 13, 15, 55), new Player("Ángel Di María", 15, 10, 15, 55), new Player("Nicolás Otamendi", 10, 15, 15, 50), new Player("Anatoliy Trubin", 7, 17, 15, 50)]
}];
// Hepsini ekle
for (var i = 0; i < otherChampions.length; i++) {
championsLeagueTeams.push({
name: otherChampions[i].name,
players: otherChampions[i].players.map(clonePlayer)
});
}
// Toplam 8 takım olduysa devam et, yoksa random güçlü takımlarla tamamla
while (championsLeagueTeams.length < 8) {
championsLeagueTeams.push({
name: "Strong FC " + (championsLeagueTeams.length + 1),
players: [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()]
});
}
// 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;
}
championsLeagueActive = championsLeagueUserQualified;
championsLeagueCurrentRound = 0;
championsLeagueLog = [];
championsLeagueResult = null;
championsLeaguePrize = 0;
championsLeagueStage = "";
championsLeagueOpponent = null;
championsLeagueUserPoints = 0;
championsLeagueUserGroup = [];
championsLeagueGroupResults = [];
championsLeagueKnockoutTeams = [];
championsLeagueKnockoutRound = 0;
championsLeagueKnockoutOpponent = null;
championsLeagueKnockoutLog = [];
championsLeagueKnockoutResult = null;
championsLeagueKnockoutStage = "";
championsLeagueUserEliminated = false;
if (championsLeagueUserQualified) {
showInfo("Tebrikler! Sadece lig şampiyonu ve diğer liglerin şampiyonları Şampiyonlar Ligi'ne katıldı! Yeni sezonda ekstra ödüller için mücadele et.");
}
// Reset league and start new season
initLeague();
// Always ensure custom team is present in leagueTeams every season
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
// 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].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// If not promoted or Süper Lig, just reset league for same division
initLeague();
if (selectedTeamName && leagueTeams[0].name !== selectedTeamName) {
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === selectedTeamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = selectedTeamName;
leagueTeams[0].realSquad = squad.map(clonePlayer);
}
}
initTransferList();
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
return;
}
// Next opponent in league
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
}
clearMatchText();
nextBtn.destroy();
nextBtn = null;
refreshUI();
};
game.addChild(nextBtn);
};
game.addChild(playBtn);
}
// --- INIT UI ---
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);
refreshUI();
}
// --- GAME START ---
// --- TEAM SELECTION SYSTEM ---
var teamSelectionLabels = [];
var teamSelectionBtns = [];
var selectedTeamName = null;
function showTeamSelection() {
// Clear everything
clearAllUI();
clearArray(teamSelectionLabels);
clearArray(teamSelectionBtns);
// --- LIG SEÇİMİ EKRANI ---
var leagueSelectTitle = new Text2("Hangi Ligde Oynamak İstersin?", {
size: 90,
fill: 0x00CEC9
});
leagueSelectTitle.x = 80;
leagueSelectTitle.y = 200;
game.addChild(leagueSelectTitle);
teamSelectionLabels.push(leagueSelectTitle);
var leagueNames = [{
name: "Süper Lig",
level: 1,
color: 0x00B894
}, {
name: "2. Lig",
level: 2,
color: 0x0984E3
}, {
name: "3. Lig",
level: 3,
color: 0x6c5ce7
}, {
name: "4. Lig",
level: 4,
color: 0x00b894
},
// Other countries
{
name: "Premier League (İngiltere)",
level: 101,
color: 0x1e90ff
}, {
name: "Bundesliga (Almanya)",
level: 102,
color: 0xff0000
}, {
name: "La Liga (İspanya)",
level: 103,
color: 0xf4c542
}, {
name: "Ligue 1 (Fransa)",
level: 104,
color: 0x00b894
}, {
name: "Serie A (İtalya)",
level: 105,
color: 0x2d3436
}, {
name: "Eredivisie (Hollanda)",
level: 106,
color: 0xfdcb6e
}, {
name: "Primeira Liga (Portekiz)",
level: 107,
color: 0xe17055
}];
// 3. ve 4. Lig'i Süper Lig ve 2. Lig'in sağına koymak için sıralama değiştirildi
leagueNames.splice(2, 0, leagueNames.splice(2, 1)[0]);
leagueNames.splice(3, 0, leagueNames.splice(3, 1)[0]);
var leagueBtnY = 400;
var leagueBtnSpacing = 120;
for (var i = 0; i < leagueNames.length; i++) {
(function (idx) {
var league = leagueNames[idx];
var btn = new Text2(league.name, {
size: 80,
fill: league.color
});
btn.x = 200;
btn.y = leagueBtnY + idx * leagueBtnSpacing;
btn.interactive = true;
btn.down = function (x, y, obj) {
// Remove league selection UI
for (var j = 0; j < teamSelectionLabels.length; j++) {
if (teamSelectionLabels[j] && teamSelectionLabels[j].destroy) teamSelectionLabels[j].destroy();
}
for (var j = 0; j < teamSelectionBtns.length; j++) {
if (teamSelectionBtns[j] && teamSelectionBtns[j].destroy) teamSelectionBtns[j].destroy();
}
teamSelectionLabels = [];
teamSelectionBtns = [];
// Defensive: If leagueClubLists[league.level] is not an array, show error
var leagueClubLists = [null, leagueClubNames1, leagueClubNames2, leagueClubNames3, leagueClubNames4, leagueClubNamesEngland, leagueClubNamesGermany, leagueClubNamesSpain, leagueClubNamesFrance, leagueClubNamesItaly, leagueClubNamesNetherlands, leagueClubNamesPortugal];
if (!leagueClubLists[league.level] || typeof leagueClubLists[league.level].length !== "number" || leagueClubLists[league.level].length === 0) {
var errLabel = new Text2("Bu ligde takım bulunamadı.", {
size: 70,
fill: 0xFF7675
});
errLabel.x = 200;
errLabel.y = 400;
game.addChild(errLabel);
teamSelectionLabels.push(errLabel);
return;
}
// Show team selection for this league
showTeamSelectionForLeague(league.level);
};
game.addChild(btn);
teamSelectionBtns.push(btn);
})(i);
}
// --- LIG SEÇİMİNDEN SONRA TAKIM SEÇİMİ ---
function showTeamSelectionForLeague(leagueLevel) {
clearAllUI();
clearArray(teamSelectionLabels);
clearArray(teamSelectionBtns);
var leagueClubLists = [null, leagueClubNames1, leagueClubNames2, leagueClubNames3, leagueClubNames4, leagueClubNamesEngland,
// 101
leagueClubNamesGermany,
// 102
leagueClubNamesSpain,
// 103
leagueClubNamesFrance,
// 104
leagueClubNamesItaly,
// 105
leagueClubNamesNetherlands,
// 106
leagueClubNamesPortugal // 107
];
var leagueHeaders = [null, "Süper Lig", "2. Lig", "3. Lig", "4. Lig", "Premier League (İngiltere)", "Bundesliga (Almanya)", "La Liga (İspanya)", "Ligue 1 (Fransa)", "Serie A (İtalya)", "Eredivisie (Hollanda)", "Primeira Liga (Portekiz)"];
var leagueColors = [null, 0x00B894, 0x0984E3, 0x6c5ce7, 0x00b894, 0x1e90ff, 0xff0000, 0xf4c542, 0x00b894, 0x2d3436, 0xfdcb6e, 0xe17055];
var title = new Text2("Takımını Seç!", {
size: 90,
fill: 0x00CEC9
});
title.x = 80;
title.y = 200;
game.addChild(title);
teamSelectionLabels.push(title);
var header = new Text2(leagueHeaders[leagueLevel], {
size: 60,
fill: leagueColors[leagueLevel]
});
header.x = 200;
header.y = 320;
game.addChild(header);
teamSelectionLabels.push(header);
var clubs = leagueClubLists[leagueLevel];
var btnSpacing = 90;
var btnX = 200;
var startY = 400;
// Defensive: If clubs is not an array or is undefined/null, show error and return
if (!clubs || typeof clubs.length !== "number" || clubs.length === 0) {
var errLabel = new Text2("Bu ligde takım bulunamadı.", {
size: 70,
fill: 0xFF7675
});
errLabel.x = btnX;
errLabel.y = startY;
game.addChild(errLabel);
teamSelectionLabels.push(errLabel);
} else {
if (clubs && typeof clubs.length === "number" && clubs.length > 0) {
for (var i = 0; i < clubs.length; i++) {
(function (idx) {
var clubName = clubs[idx];
var btn = new Text2(clubName, {
size: 70,
fill: 0xFDCB6E
});
btn.x = btnX;
btn.y = startY + idx * btnSpacing;
btn.interactive = true;
btn.down = function (x, y, obj) {
selectedTeamName = clubName;
currentLeagueLevel = leagueLevel;
leagueClubNames = clubs;
// Remove selection UI
for (var j = 0; j < teamSelectionLabels.length; j++) {
if (teamSelectionLabels[j] && teamSelectionLabels[j].destroy) teamSelectionLabels[j].destroy();
}
for (var j = 0; j < teamSelectionBtns.length; j++) {
if (teamSelectionBtns[j] && teamSelectionBtns[j].destroy) teamSelectionBtns[j].destroy();
}
teamSelectionLabels = [];
teamSelectionBtns = [];
// Start game with this team
startGameWithTeam(selectedTeamName);
};
game.addChild(btn);
teamSelectionBtns.push(btn);
})(i);
}
}
}
// Add "Kendi Takımını Oluştur" button
var customBtn = new Text2("Kendi Takımını Oluştur", {
size: 70,
fill: 0x00b894
});
customBtn.x = btnX;
customBtn.y = startY + (clubs && typeof clubs.length === "number" ? clubs.length : 0) * btnSpacing + 120;
customBtn.interactive = true;
customBtn.down = function (x, y, obj) {
// Remove selection UI
for (var j = 0; j < teamSelectionLabels.length; j++) {
if (teamSelectionLabels[j] && teamSelectionLabels[j].destroy) teamSelectionLabels[j].destroy();
}
for (var j = 0; j < teamSelectionBtns.length; j++) {
if (teamSelectionBtns[j] && teamSelectionBtns[j].destroy) teamSelectionBtns[j].destroy();
}
teamSelectionLabels = [];
teamSelectionBtns = [];
// --- Custom Team Name Input UI ---
var inputBg = LK.getAsset('character', {
width: 900,
height: 200,
color: 0x222222,
anchorX: 0,
anchorY: 0
});
inputBg.x = 400;
inputBg.y = 700;
game.addChild(inputBg);
var inputLabel = new Text2("Takım Adını Gir:", {
size: 60,
fill: 0x00B894
});
inputLabel.x = 420;
inputLabel.y = 720;
game.addChild(inputLabel);
var nameText = new Text2("", {
size: 60,
fill: "#fff"
});
nameText.x = 420;
nameText.y = 800;
game.addChild(nameText);
// Per-letter buttons (including space)
var alphabetArr = ["A", "B", "C", "Ç", "D", "E", "F", "G", "Ğ", "H", "I", "İ", "J", "K", "L", "M", "N", "O", "Ö", "P", "R", "S", "Ş", "T", "U", "Ü", "V", "Y", "Z", "a", "b", "c", "ç", "d", "e", "f", "g", "ğ", "h", "ı", "i", "j", "k", "l", "m", "n", "o", "ö", "p", "r", "s", "ş", "t", "u", "ü", "v", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", " "];
var maxLen = 18;
var currentName = "";
var letterBtns = [];
var lettersPerRow = 10;
var startX = 420,
startY = 900,
btnW = 90,
btnH = 90,
gap = 16;
for (var i = 0; i < alphabetArr.length; i++) {
(function (idx) {
var ch = alphabetArr[idx];
var btn = new Text2(ch === " " ? "␣" : ch, {
size: 54,
fill: 0xFDCB6E
});
btn.x = startX + idx % lettersPerRow * (btnW + gap);
btn.y = startY + Math.floor(idx / lettersPerRow) * (btnH + gap);
btn.interactive = true;
btn.down = function () {
if (currentName.length < maxLen) {
currentName += ch;
nameText.setText(currentName);
}
};
game.addChild(btn);
letterBtns.push(btn);
})(i);
}
// Backspace button
var backBtn = new Text2("Sil", {
size: 54,
fill: 0xFF7675
});
backBtn.x = startX + (lettersPerRow + 1) * (btnW + gap);
backBtn.y = startY;
backBtn.interactive = true;
backBtn.down = function () {
if (currentName.length > 0) {
currentName = currentName.slice(0, -1);
nameText.setText(currentName);
}
};
game.addChild(backBtn);
// Confirm button
var okBtn = new Text2("Tamam", {
size: 64,
fill: 0x00CEC9
});
okBtn.x = startX + (lettersPerRow + 1) * (btnW + gap);
okBtn.y = startY + btnH + gap;
okBtn.interactive = true;
okBtn.down = function () {
var teamName = currentName.trim().length > 0 ? currentName.trim() : "Benim Takımım";
// Clean up input UI
inputBg.destroy();
inputLabel.destroy();
nameText.destroy();
for (var i = 0; i < letterBtns.length; i++) letterBtns[i].destroy();
backBtn.destroy();
okBtn.destroy();
selectedTeamName = teamName;
// Set up a new team with random players
allPlayers = [];
for (var i = 0; i < SQUAD_SIZE + BENCH_SIZE; i++) {
allPlayers.push(makeRandomPlayer());
}
updateSquadAndBench();
initTransferList();
// Start custom team in selected league
currentLeagueLevel = leagueLevel;
leagueClubNames = leagueClubLists[leagueLevel];
// Set up league with user as custom team
initLeague();
leagueTeams[0].name = teamName;
userTeamIdx = 0;
// Set first opponent in league
var oppIdx = getCurrentOpponentIdx();
if (oppIdx !== null) {
opponentTeam = makeOpponentTeam();
opponentTeam.name = leagueTeams[oppIdx].name;
} else {
opponentTeam = makeOpponentTeam();
}
// Reset youth academy and offers
youthAcademy = [];
if (youthTimer) {
LK.clearInterval(youthTimer);
youthTimer = null;
}
transferOffers = [];
if (OFFER_TIMER) {
LK.clearInterval(OFFER_TIMER);
OFFER_TIMER = null;
}
clearArray(offerLabels);
clearArray(acceptOfferBtns);
clearArray(rejectOfferBtns);
matchInProgress = false;
matchLog = [];
matchResult = null;
selectedPlayerIdx = null;
selectedBenchIdx = null;
budget = INITIAL_BUDGET;
initUI();
};
game.addChild(okBtn);
};
game.addChild(customBtn);
teamSelectionBtns.push(customBtn);
}
}
function startGameWithTeam(teamName) {
budget = INITIAL_BUDGET;
// Start in the league selected by the user
// currentLeagueLevel and leagueClubNames are already set by selection UI
if (currentLeagueLevel === 1) {
leagueClubNames = leagueClubNames1;
} else if (currentLeagueLevel === 2) {
leagueClubNames = leagueClubNames2;
} else if (currentLeagueLevel === 3) {
leagueClubNames = leagueClubNames3;
} else if (currentLeagueLevel === 4) {
leagueClubNames = leagueClubNames4;
} else if (currentLeagueLevel === 101) {
leagueClubNames = leagueClubNamesEngland;
} else if (currentLeagueLevel === 102) {
leagueClubNames = leagueClubNamesGermany;
} else if (currentLeagueLevel === 103) {
leagueClubNames = leagueClubNamesSpain;
} else if (currentLeagueLevel === 104) {
leagueClubNames = leagueClubNamesFrance;
} else if (currentLeagueLevel === 105) {
leagueClubNames = leagueClubNamesItaly;
} else if (currentLeagueLevel === 106) {
leagueClubNames = leagueClubNamesNetherlands;
} else if (currentLeagueLevel === 107) {
leagueClubNames = leagueClubNamesPortugal;
} else {
leagueClubNames = leagueClubNames1;
}
// Set up league with user as chosen team
initLeague();
// Always ensure custom team is present in leagueTeams every season
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === teamName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
// Replace "You" with custom team if not present
leagueTeams[0].name = teamName;
leagueTeams[0].realSquad = allPlayers.slice(0, SQUAD_SIZE).map(clonePlayer);
}
// Find index of chosen team in leagueTeams
var idx = -1;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === teamName) {
idx = i;
break;
}
}
if (idx === -1) idx = 1; // fallback
// Swap "You" with chosen team in leagueTeams
if (idx !== 0) {
var userTeam = leagueTeams[0];
var chosenTeam = leagueTeams[idx];
// Swap all properties except name
var tmpName = userTeam.name;
userTeam.name = chosenTeam.name;
chosenTeam.name = tmpName;
// Swap realSquad if present
var tmpSquad = userTeam.realSquad;
userTeam.realSquad = chosenTeam.realSquad;
chosenTeam.realSquad = tmpSquad;
// Swap points etc.
var props = ["points", "played", "wins", "draws", "losses", "goalsFor", "goalsAgainst"];
for (var p = 0; p < props.length; p++) {
var prop = props[p];
var tmp = userTeam[prop];
userTeam[prop] = chosenTeam[prop];
chosenTeam[prop] = tmp;
}
}
userTeamIdx = 0;
// Set allPlayers, squad, bench to chosen team's real squad
if (realSquads[teamName]) {
allPlayers = [];
var real = realSquads[teamName];
for (var i = 0; i < real.length; i++) {
allPlayers.push(clonePlayer(real[i]));
}
// Fill bench with randoms
for (var i = 0; i < BENCH_SIZE; i++) {
allPlayers.push(makeRandomPlayer());
}
updateSquadAndBench();
} else {
initPlayers();
}
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].name;
} else {
opponentTeam = makeOpponentTeam();
}
matchInProgress = false;
matchLog = [];
matchResult = null;
selectedPlayerIdx = null;
selectedBenchIdx = null;
initUI();
}
// Override newGame to show team selection
function newGame() {
showTeamSelection();
}
newGame();
// --- END ---