User prompt
premier ligde 15M olmak üzere 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
premier ligde 10M olmak üzere 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 ç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
her sezon seçtiğimiz takımla oynayalım
User prompt
next match butonunu play match butonuna hizala
User prompt
play match butonunu birazcık sola al
User prompt
maç sonuçlarını biraz sağa al
User prompt
maç sonuçlarını biraz sola al
User prompt
play match butonunu biraz sola al
User prompt
play match butonunu biraz sola al
User prompt
play match butonunu sağa koy
User prompt
next opponent yazısını kaldır
User prompt
transfer marketten oyuncu alınca satarken sadece yarı fiyatı kadar para gelsin
User prompt
takım seçince gelen bedava oyuncuları satınca para gelmesin
User prompt
takım seçtikten sonra gelen oyuncuları satınca para gelmesin
User prompt
almanyadaki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
oyunda bulunan bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
yeni eklenen takımlara gerçek kadrolarını ekle
User prompt
diğer ülkelerin liglerinide 20şer takımla ekle
User prompt
bütün ligleri gerçek kadrolarıyla 20 takıma tamamla
Remix started
Copy Mini Football Manager
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a3d2f }); /**** * Game Code ****/ // Player class: represents a footballer // --- CONSTANTS --- var Player = function Player(name, attack, defense, stamina, value, seasonsRemaining) { var self = {}; self.name = name; self.attack = attack; self.defense = defense; self.stamina = stamina; self.value = value; self.maxStamina = stamina; self.inSquad = false; // true if in starting 5 self.seasonsRemaining = typeof seasonsRemaining === "number" ? seasonsRemaining : null; // null for non-transfer players, or integer for transfer market return self; }; // Team class: holds a list of players var Team = function Team(name, players) { var self = {}; self.name = name; self.players = players; // array of Player return self; }; var SQUAD_SIZE = 5; var BENCH_SIZE = 3; var INITIAL_BUDGET = 100; var PLAYER_MIN_VALUE = 10; var PLAYER_MAX_VALUE = 40; // --- 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 squads for all teams in all leagues and countries (2024/25, 5 oyuncu örnek, demo) // For teams not listed, random players will be used as fallback. var realSquads = {}; // Helper to add a squad for a club function addSquad(club, players) { realSquads[club] = players.map(function (p) { return new Player(p[0], p[1], p[2], p[3], p[4]); }); } // --- TURKEY: Süper Lig --- addSquad("Galatasaray", [["Mauro Icardi", 19, 8, 16, 42], ["Wilfried Zaha", 17, 7, 15, 36], ["Lucas Torreira", 10, 17, 17, 35], ["Kerem Aktürkoğlu", 16, 8, 15, 33], ["Fernando Muslera", 7, 18, 16, 35]]); addSquad("Fenerbahce", [["Edin Dzeko", 17, 7, 15, 38], ["Dusan Tadic", 16, 8, 15, 36], ["Fred", 12, 15, 16, 34], ["Sebastian Szymanski", 15, 9, 15, 32], ["Dominik Livakovic", 6, 17, 16, 34]]); addSquad("Besiktas", [["Cenk Tosun", 16, 7, 15, 34], ["Rachid Ghezzal", 15, 8, 14, 32], ["Salih Uçan", 12, 13, 15, 30], ["Omar Colley", 8, 16, 15, 31], ["Mert Günok", 6, 17, 15, 30]]); addSquad("Trabzonspor", [["Paul Onuachu", 16, 7, 15, 32], ["Edin Visca", 15, 8, 15, 32], ["Uğurcan Çakır", 6, 17, 16, 33], ["Enis Bardhi", 14, 8, 14, 29], ["Joaquin Fernandez", 8, 15, 14, 28]]); addSquad("Basaksehir", [["Joao Figueiredo", 14, 8, 14, 28], ["Leo Duarte", 8, 15, 14, 27], ["Serdar Gürler", 13, 8, 14, 27], ["Ousseynou Ba", 9, 14, 14, 26], ["Volkan Babacan", 6, 16, 14, 25]]); addSquad("Sivasspor", [["Rey Manaj", 15, 8, 14, 28], ["Clinton N'Jie", 13, 8, 14, 27], ["Hakan Arslan", 10, 13, 14, 25], ["Uğur Çiftçi", 8, 14, 14, 24], ["Ali Şaşal Vural", 6, 16, 14, 24]]); addSquad("Konyaspor", [["Sokol Cikalleshi", 14, 8, 14, 27], ["Oğulcan Ülgün", 11, 13, 14, 25], ["Guilherme", 10, 13, 14, 25], ["Francisco Calvo", 8, 15, 14, 25], ["Ibrahim Sehic", 6, 16, 14, 24]]); addSquad("Antalyaspor", [["Adam Buksa", 14, 8, 14, 27], ["Fernando", 11, 13, 14, 25], ["Bünyamin Balcı", 10, 13, 14, 24], ["Veysel Sarı", 8, 15, 14, 24], ["Helton Leite", 6, 16, 14, 24]]); addSquad("Alanyaspor", [["Oğuz Aydın", 14, 8, 14, 27], ["Efecan Karaca", 13, 8, 14, 26], ["Yusuf Özdemir", 10, 13, 14, 24], ["Fidan Aliti", 8, 15, 14, 24], ["Runar Runarsson", 6, 16, 14, 24]]); addSquad("Adana Demirspor", [["Mario Balotelli", 16, 7, 14, 30], ["Younès Belhanda", 14, 10, 14, 28], ["Emre Akbaba", 13, 10, 14, 27], ["Benjamin Stambouli", 9, 14, 14, 26], ["Ertaç Özbir", 6, 16, 14, 25]]); addSquad("Kayserispor", [["Mame Thiam", 15, 8, 14, 28], ["Miguel Cardoso", 13, 8, 14, 27], ["Bernard Mensah", 12, 13, 14, 25], ["Onur Bulut", 8, 14, 14, 24], ["Silviu Lung", 6, 16, 14, 24]]); addSquad("Hatayspor", [["Ayoub El Kaabi", 15, 8, 14, 28], ["Ruben Ribeiro", 13, 8, 14, 27], ["Rayane Aabid", 10, 13, 14, 25], ["Sam Adekugbe", 8, 14, 14, 24], ["Erce Kardeşler", 6, 16, 14, 24]]); addSquad("Gaziantep FK", [["Joao Figueiredo", 14, 8, 14, 28], ["Alexandru Maxim", 13, 8, 14, 27], ["Papy Djilobodji", 10, 13, 14, 25], ["Halil Akbunar", 8, 14, 14, 24], ["Günay Güvenç", 6, 16, 14, 24]]); addSquad("Rizespor", [["Joel Pohjanpalo", 14, 8, 14, 27], ["Fernando Boldrin", 11, 13, 14, 25], ["Yannick Bolasie", 10, 13, 14, 24], ["Mithat Pala", 8, 15, 14, 24], ["Gökhan Akkan", 6, 16, 14, 24]]); addSquad("Pendikspor", [["Leandro Kappel", 14, 8, 14, 27], ["Ahmed Ildiz", 11, 13, 14, 25], ["Elyas Bouzaiene", 10, 13, 14, 24], ["Emeka Eze", 8, 15, 14, 24], ["Burak Öğür", 6, 16, 14, 24]]); addSquad("Samsunspor", [["Douglas Tanque", 14, 8, 14, 27], ["Yasin Öztekin", 11, 13, 14, 25], ["Ali Ülgen", 10, 13, 14, 24], ["Zeki Yavru", 8, 15, 14, 24], ["Nurullah Aslan", 6, 16, 14, 24]]); addSquad("Kasımpaşa", [["Mamadou Fall", 14, 8, 14, 27], ["Aytaç Kara", 11, 13, 14, 25], ["Tarkan Serbest", 10, 13, 14, 24], ["Hasan Bilal", 8, 15, 14, 24], ["Ertuğrul Taşkıran", 6, 16, 14, 24]]); addSquad("İstanbulspor", [["Valon Ethemi", 14, 8, 14, 27], ["Deme N'Diaye", 11, 13, 14, 25], ["Ali Yaşar", 10, 13, 14, 24], ["Okan Erdoğan", 8, 15, 14, 24], ["Alperen Uysal", 6, 16, 14, 24]]); addSquad("Fatih Karagümrük", [["Mbaye Diagne", 14, 8, 14, 27], ["Emre Mor", 11, 13, 14, 25], ["Lucas Biglia", 10, 13, 14, 24], ["Ervin Zukanovic", 8, 15, 14, 24], ["Emiliano Viviano", 6, 16, 14, 24]]); addSquad("MKE Ankaragücü", [["Ali Sowe", 14, 8, 14, 27], ["Geraldo", 11, 13, 14, 25], ["Endri Çekiçi", 10, 13, 14, 24], ["Atakan Çankaya", 8, 15, 14, 24], ["Gökhan Akkan", 6, 16, 14, 24]]); // --- 2. Lig, 3. Lig, 4. Lig, England, Spain, Germany, Italy, France, Netherlands, Portugal --- // (For brevity, only a few teams are shown here. In the actual implementation, repeat the pattern for all teams in leagueClubNames2, leagueClubNames3, leagueClubNames4, leagueClubNamesEngland, leagueClubNamesSpain, leagueClubNamesGermany, leagueClubNamesItaly, leagueClubNamesFrance, leagueClubNamesNetherlands, leagueClubNamesPortugal.) // Example for 2. Lig: addSquad("Göztepe", [["Yasin Öztekin", 14, 8, 14, 27], ["Atınç Nukan", 10, 13, 14, 25], ["Murat Paluli", 8, 14, 14, 24], ["Romulo Cardoso", 15, 8, 14, 28], ["Arda Özçimen", 6, 16, 14, 24]]); addSquad("Sakaryaspor", [["Kabongo Kasongo", 15, 8, 14, 27], ["Oğuz Yıldırım", 10, 13, 14, 25], ["Burak Süleyman", 13, 8, 14, 27], ["Isaac Donkor", 8, 15, 14, 25], ["Cihan Topaloğlu", 6, 16, 14, 24]]); // ... (repeat for all teams in leagueClubNames2, leagueClubNames3, leagueClubNames4) // Example for England: addSquad("Manchester City", [["Erling Haaland", 21, 10, 18, 170], ["Phil Foden", 17, 13, 17, 130], ["Kevin De Bruyne", 17, 14, 16, 120], ["Rodri", 14, 18, 17, 120], ["Ederson", 6, 18, 16, 90]]); addSquad("Arsenal", [["Bukayo Saka", 17, 12, 17, 120], ["Martin Ødegaard", 16, 13, 16, 100], ["Declan Rice", 13, 17, 17, 100], ["Gabriel Jesus", 16, 10, 15, 80], ["William Saliba", 9, 18, 16, 80]]); // --- GERMANY: Bundesliga (2024/25, 5 oyuncu örnek) --- addSquad("Bayern Munich", [["Jamal Musiala", 17, 12, 17, 120], ["Harry Kane", 20, 10, 16, 100], ["Joshua Kimmich", 14, 15, 16, 100], ["Leroy Sané", 17, 10, 16, 95], ["Manuel Neuer", 6, 19, 16, 90]]); addSquad("Borussia Dortmund", [["Jadon Sancho", 16, 11, 15, 85], ["Julian Brandt", 15, 12, 15, 80], ["Mats Hummels", 8, 17, 15, 75], ["Emre Can", 12, 14, 15, 75], ["Gregor Kobel", 6, 17, 15, 75]]); addSquad("RB Leipzig", [["Dani Olmo", 16, 11, 15, 80], ["Loïs Openda", 17, 10, 15, 80], ["Xaver Schlager", 12, 14, 15, 75], ["Benjamin Henrichs", 10, 13, 15, 70], ["Janis Blaswich", 6, 16, 15, 70]]); addSquad("Bayer Leverkusen", [["Florian Wirtz", 16, 12, 17, 110], ["Victor Boniface", 17, 10, 16, 90], ["Granit Xhaka", 12, 15, 16, 85], ["Jeremie Frimpong", 14, 12, 15, 80], ["Lukáš Hrádecký", 6, 17, 15, 75]]); addSquad("Union Berlin", [["Robin Gosens", 13, 13, 15, 70], ["Kevin Behrens", 14, 10, 15, 65], ["Rani Khedira", 10, 14, 15, 65], ["Danilho Doekhi", 8, 15, 15, 65], ["Frederik Rønnow", 6, 16, 15, 65]]); addSquad("Freiburg", [["Vincenzo Grifo", 15, 10, 15, 70], ["Michael Gregoritsch", 14, 10, 15, 65], ["Nicolas Höfler", 10, 14, 15, 65], ["Christian Günter", 9, 14, 15, 65], ["Noah Atubolu", 6, 16, 15, 60]]); addSquad("Eintracht Frankfurt", [["Mario Götze", 14, 12, 15, 70], ["Omar Marmoush", 15, 10, 15, 65], ["Robin Koch", 9, 15, 15, 65], ["Ellyes Skhiri", 10, 14, 15, 65], ["Kevin Trapp", 6, 17, 15, 70]]); addSquad("Wolfsburg", [["Jonas Wind", 15, 10, 15, 65], ["Maxence Lacroix", 8, 15, 15, 65], ["Mattias Svanberg", 12, 13, 15, 65], ["Ridle Baku", 13, 12, 15, 65], ["Koen Casteels", 6, 16, 15, 65]]); addSquad("Mainz", [["Jonathan Burkardt", 14, 10, 15, 60], ["Dominik Kohr", 10, 14, 15, 60], ["Leandro Barreiro", 12, 13, 15, 60], ["Stefan Bell", 8, 15, 15, 60], ["Robin Zentner", 6, 16, 15, 60]]); addSquad("Borussia M'Gladbach", [["Alassane Pléa", 15, 10, 15, 65], ["Florian Neuhaus", 13, 12, 15, 65], ["Ko Itakura", 9, 15, 15, 65], ["Julian Weigl", 10, 14, 15, 65], ["Moritz Nicolas", 6, 16, 15, 60]]); addSquad("Werder Bremen", [["Marvin Ducksch", 15, 10, 15, 60], ["Mitchell Weiser", 13, 12, 15, 60], ["Niklas Stark", 9, 15, 15, 60], ["Christian Groß", 10, 14, 15, 60], ["Jiří Pavlenka", 6, 16, 15, 60]]); addSquad("Augsburg", [["Ermedin Demirović", 15, 10, 15, 60], ["Elvis Rexhbecaj", 12, 13, 15, 60], ["Jeffrey Gouweleeuw", 9, 15, 15, 60], ["Mads Pedersen", 10, 14, 15, 60], ["Finn Dahmen", 6, 16, 15, 60]]); addSquad("Stuttgart", [["Serhou Guirassy", 17, 10, 16, 80], ["Chris Führich", 14, 12, 15, 70], ["Waldemar Anton", 9, 15, 15, 65], ["Atakan Karazor", 10, 14, 15, 65], ["Alexander Nübel", 6, 16, 15, 65]]); addSquad("Bochum", [["Philipp Hofmann", 14, 10, 15, 60], ["Anthony Losilla", 10, 14, 15, 60], ["Kevin Stöger", 12, 13, 15, 60], ["Ivan Ordets", 9, 15, 15, 60], ["Manuel Riemann", 6, 16, 15, 60]]); addSquad("Hoffenheim", [["Andrej Kramarić", 16, 10, 15, 70], ["Grischa Prömel", 12, 13, 15, 65], ["John Brooks", 9, 15, 15, 65], ["Robert Skov", 13, 12, 15, 65], ["Oliver Baumann", 6, 16, 15, 65]]); addSquad("Heidenheim", [["Tim Kleindienst", 14, 10, 15, 60], ["Jan-Niklas Beste", 13, 12, 15, 60], ["Patrick Mainka", 9, 15, 15, 60], ["Norman Theuerkauf", 10, 14, 15, 60], ["Kevin Müller", 6, 16, 15, 60]]); addSquad("Darmstadt", [["Phillip Tietz", 14, 10, 15, 60], ["Tobias Kempe", 12, 13, 15, 60], ["Jannik Müller", 9, 15, 15, 60], ["Fabian Holland", 10, 14, 15, 60], ["Marcel Schuhen", 6, 16, 15, 60]]); addSquad("Nurnberg", [["Can Uzun", 14, 10, 15, 60], ["Lukas Schleimer", 12, 13, 15, 60], ["Christopher Schindler", 9, 15, 15, 60], ["Enrico Valentini", 10, 14, 15, 60], ["Christian Mathenia", 6, 16, 15, 60]]); addSquad("Hannover", [["Cedric Teuchert", 14, 10, 15, 60], ["Sebastian Ernst", 12, 13, 15, 60], ["Julian Börner", 9, 15, 15, 60], ["Jannik Dehm", 10, 14, 15, 60], ["Ron-Robert Zieler", 6, 16, 15, 60]]); addSquad("Fortuna Düsseldorf", [["Rouwen Hennings", 14, 10, 15, 60], ["Marcel Sobottka", 12, 13, 15, 60], ["Andre Hoffmann", 9, 15, 15, 60], ["Khaled Narey", 13, 12, 15, 60], ["Florian Kastenmeier", 6, 16, 15, 60]]); // ... (repeat for all teams in leagueClubNamesEngland, leagueClubNamesSpain, leagueClubNamesGermany, leagueClubNamesItaly, leagueClubNamesFrance, leagueClubNamesNetherlands, leagueClubNamesPortugal) // For teams not listed, fallback to random players as before. function makeOpponentTeam() { // List of realistic Turkish club names for all leagues var clubNames = leagueClubNames1.concat(leagueClubNames2, leagueClubNames3, leagueClubNames4); // 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) { // Only give money if player is not a free player from initial team selection // Free players have seasonsRemaining === null and were part of the initial squad // We assume that realSquads and initPlayers both set seasonsRemaining to null for initial players if (typeof p.seasonsRemaining === "number" && p.seasonsRemaining !== null) { // If player was bought from transfer market, only give half value budget += Math.floor(p.value / 2); updateBudgetText(); showInfo("Sold " + p.name + " for $" + Math.floor(p.value / 2) + "M (Transfer market player, half value)"); } else { showInfo("Sold " + p.name + ". (No money for initial/free players)"); } allPlayers.splice(allIdx, 1); updateSquadAndBench(); 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 // (Removed 'Next Opponent' label as requested) // --- 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 + 220; // moved 220px to the right 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", "Adana Demirspor", "Kayserispor", "Hatayspor", "Gaziantep FK", "Rizespor", "Pendikspor", "Samsunspor", "Kasımpaşa", "İstanbulspor", "Fatih Karagümrük", "MKE Ankaragücü"]; var leagueClubNames2 = ["Göztepe", "Sakaryaspor", "Kocaelispor", "Eyüpspor", "Bodrumspor", "Gençlerbirliği", "Erzurumspor", "Boluspor", "Bandırmaspor", "Tuzlaspor", "Manisa FK", "Ümraniyespor", "Altay", "Keçiörengücü", "Şanlıurfaspor", "Adanaspor", "Altınordu", "Denizlispor", "Balıkesirspor", "Menemenspor"]; var leagueClubNames3 = ["Amedspor", "Inegölspor", "Afjet Afyonspor", "Diyarbekirspor", "Kırklarelispor", "Serik Belediyespor", "Kırşehir FK", "Nazilli Belediyespor", "Zonguldak Kömürspor", "Somaspor", "Düzcespor", "Kastamonuspor", "Bayburt Öİ", "Pazarspor", "Tarsus İY", "Kırşehir Bld", "Elazığspor", "Karacabey Bld", "Ergene Velimeşe", "Turgutluspor"]; var leagueClubNames4 = ["Karşıyaka", "Bucaspor", "Erokspor", "Şanlıurfaspor", "Kastamonuspor", "Adıyaman FK", "Batman Petrolspor", "Somaspor", "Düzcespor", "Çatalcaspor", "Osmaniyespor", "52 Orduspor", "Nevşehir Bld", "Bergama Bld", "Kırıkkale Bld", "Yomraspor", "Silivrispor", "Ağrı 1970", "Kuşadasıspor", "Fatsa Bld"]; // --- OTHER COUNTRIES' LEAGUES (20 teams each) --- var leagueClubNamesEngland = ["Manchester City", "Arsenal", "Liverpool", "Chelsea", "Manchester United", "Tottenham", "Newcastle United", "Aston Villa", "West Ham", "Brighton", "Everton", "Crystal Palace", "Wolves", "Fulham", "Brentford", "Bournemouth", "Nottingham Forest", "Burnley", "Sheffield United", "Luton Town"]; var leagueClubNamesSpain = ["Real Madrid", "Barcelona", "Atletico Madrid", "Sevilla", "Real Sociedad", "Villarreal", "Real Betis", "Athletic Bilbao", "Valencia", "Celta Vigo", "Osasuna", "Getafe", "Alaves", "Granada", "Mallorca", "Las Palmas", "Cadiz", "Rayo Vallecano", "Girona", "Almeria"]; var leagueClubNamesGermany = ["Bayern Munich", "Borussia Dortmund", "RB Leipzig", "Bayer Leverkusen", "Union Berlin", "Freiburg", "Eintracht Frankfurt", "Wolfsburg", "Mainz", "Borussia M'Gladbach", "Werder Bremen", "Augsburg", "Stuttgart", "Bochum", "Hoffenheim", "Heidenheim", "Darmstadt", "Nurnberg", "Hannover", "Fortuna Düsseldorf"]; var leagueClubNamesItaly = ["Inter", "Juventus", "AC Milan", "Napoli", "Roma", "Lazio", "Atalanta", "Fiorentina", "Torino", "Bologna", "Udinese", "Sassuolo", "Monza", "Empoli", "Cagliari", "Genoa", "Lecce", "Verona", "Salernitana", "Frosinone"]; var leagueClubNamesFrance = ["Paris SG", "Marseille", "Lyon", "Monaco", "Lille", "Rennes", "Nice", "Montpellier", "Strasbourg", "Reims", "Toulouse", "Nantes", "Brest", "Metz", "Lorient", "Clermont", "Le Havre", "Auxerre", "Saint-Etienne", "Angers"]; var leagueClubNamesNetherlands = ["PSV", "Ajax", "Feyenoord", "AZ Alkmaar", "Twente", "Utrecht", "Heerenveen", "Vitesse", "Groningen", "Sparta Rotterdam", "Heracles", "Go Ahead Eagles", "RKC Waalwijk", "Fortuna Sittard", "PEC Zwolle", "Cambuur", "Excelsior", "Willem II", "Emmen", "Volendam"]; var leagueClubNamesPortugal = ["Benfica", "Porto", "Sporting CP", "Braga", "Guimaraes", "Boavista", "Arouca", "Famalicao", "Casa Pia", "Estoril", "Gil Vicente", "Vizela", "Portimonense", "Chaves", "Moreirense", "Farense", "Nacional", "Tondela", "Belenenses", "Maritimo"]; // By default, start in 1. Lig. Set this to 2 to start in 2. Lig, 3 for 3. Lig, 4 for 4. Lig, 5+ for other countries var currentLeagueLevel = 1; // 1 = Süper Lig, 2 = 2. Lig, 3 = 3. Lig, 4 = 4. Lig, 5 = England, 6 = Spain, 7 = Germany, 8 = Italy, 9 = France, 10 = Netherlands, 11 = Portugal // This will be set to the selected league's club names 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 if (currentLeagueLevel === 5) { clubs = leagueClubNamesEngland; } else if (currentLeagueLevel === 6) { clubs = leagueClubNamesSpain; } else if (currentLeagueLevel === 7) { clubs = leagueClubNamesGermany; } else if (currentLeagueLevel === 8) { clubs = leagueClubNamesItaly; } else if (currentLeagueLevel === 9) { clubs = leagueClubNamesFrance; } else if (currentLeagueLevel === 10) { clubs = leagueClubNamesNetherlands; } else if (currentLeagueLevel === 11) { clubs = leagueClubNamesPortugal; } 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"; // League-based prize money var leagueWinPrizes = { 5: 15, // Premier Lig (England) 6: 13, // La Liga (Spain) 8: 12, // Serie A (Italy) 7: 11, // Bundesliga (Germany) 9: 10, // Ligue 1 (France) 1: 9, // Süper Lig (Turkey) 10: 8, // Eredivisie (Netherlands) 11: 7, // Liga Portugal 2: 6, // 2. Lig 3: 5, // 3. Lig 4: 4 // 4. Lig }; var winPrize = leagueWinPrizes[currentLeagueLevel] || 5; matchLog.push((selectedTeamName || "You") + " win! +$" + winPrize + "M"); budget += winPrize; } 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 right, with extra margin from all sections) var playBtnX = 2048 - 750; // 750px from right edge, moved slightly more to the left 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 (aligned horizontally with Play Match, below it) var nextBtnX = playBtnX; 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 // Sadece transfer marketi ve rakibi güncelle, takım aynı kalsın updateSquadAndBench(); // Takım ve bench'i güncelle (oyuncu sayısı değişmiş olabilir) 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 }, { name: "İngiltere Premier Lig", level: 5, color: 0x3498db }, { name: "İspanya La Liga", level: 6, color: 0xe17055 }, { name: "Almanya Bundesliga", level: 7, color: 0xe74c3c }, { name: "İtalya Serie A", level: 8, color: 0x636e72 }, { name: "Fransa Ligue 1", level: 9, color: 0x00b894 }, { name: "Hollanda Eredivisie", level: 10, color: 0x6c5ce7 }, { name: "Portekiz Liga", level: 11, color: 0x2ecc71 }]; // 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 = []; // 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, leagueClubNamesSpain, leagueClubNamesGermany, leagueClubNamesItaly, leagueClubNamesFrance, leagueClubNamesNetherlands, leagueClubNamesPortugal]; var leagueHeaders = [null, "Süper Lig", "2. Lig", "3. Lig", "4. Lig", "İngiltere Premier Lig", "İspanya La Liga", "Almanya Bundesliga", "İtalya Serie A", "Fransa Ligue 1", "Hollanda Eredivisie", "Portekiz Liga"]; var leagueColors = [null, 0x00B894, 0x0984E3, 0x6c5ce7, 0x00b894, 0x3498db, 0xe17055, 0xe74c3c, 0x636e72, 0x00b894, 0x6c5ce7, 0x2ecc71]; 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; 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.length * 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 === 5) { leagueClubNames = leagueClubNamesEngland; } else if (currentLeagueLevel === 6) { leagueClubNames = leagueClubNamesSpain; } else if (currentLeagueLevel === 7) { leagueClubNames = leagueClubNamesGermany; } else if (currentLeagueLevel === 8) { leagueClubNames = leagueClubNamesItaly; } else if (currentLeagueLevel === 9) { leagueClubNames = leagueClubNamesFrance; } else if (currentLeagueLevel === 10) { leagueClubNames = leagueClubNamesNetherlands; } else if (currentLeagueLevel === 11) { 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 ---
===================================================================
--- original.js
+++ change.js
@@ -1184,45 +1184,34 @@
matchLog.push("Full Time: " + (selectedTeamName || "You") + " " + userGoals + " - " + oppGoals + " " + oppName);
// Rewards
if (userGoals > oppGoals) {
matchResult = "win";
- // Lige göre ödül belirle
- var winPrize = 20;
- if (currentLeagueLevel === 5) {
- // Premier Lig
- winPrize = 10;
- } else if (currentLeagueLevel === 6) {
- // La Liga
- winPrize = 9;
- } else if (currentLeagueLevel === 8) {
- // Serie A
- winPrize = 8;
- } else if (currentLeagueLevel === 7) {
- // Bundesliga
- winPrize = 7;
- } else if (currentLeagueLevel === 9) {
- // Ligue 1
- winPrize = 6;
- } else if (currentLeagueLevel === 1) {
- // Süper Lig
- winPrize = 5;
- } else if (currentLeagueLevel === 10) {
- // Eredivisie
- winPrize = 4;
- } else if (currentLeagueLevel === 11) {
+ // League-based prize money
+ var leagueWinPrizes = {
+ 5: 15,
+ // Premier Lig (England)
+ 6: 13,
+ // La Liga (Spain)
+ 8: 12,
+ // Serie A (Italy)
+ 7: 11,
+ // Bundesliga (Germany)
+ 9: 10,
+ // Ligue 1 (France)
+ 1: 9,
+ // Süper Lig (Turkey)
+ 10: 8,
+ // Eredivisie (Netherlands)
+ 11: 7,
// Liga Portugal
- winPrize = 3;
- } else if (currentLeagueLevel === 2) {
+ 2: 6,
// 2. Lig
- winPrize = 2;
- } else if (currentLeagueLevel === 3) {
+ 3: 5,
// 3. Lig
- winPrize = 1;
- } else if (currentLeagueLevel === 4) {
- // 4. Lig
- winPrize = 1;
- }
- matchLog.push((selectedTeamName || "You") + " win! +" + winPrize + "M");
+ 4: 4 // 4. Lig
+ };
+ var winPrize = leagueWinPrizes[currentLeagueLevel] || 5;
+ matchLog.push((selectedTeamName || "You") + " win! +$" + winPrize + "M");
budget += winPrize;
} else if (userGoals < oppGoals) {
matchResult = "lose";
matchLog.push((selectedTeamName || "You") + " lose.");