User prompt
2.ligdeki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
portekizdeki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
hollandadaki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
italyadaki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
fransadaki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
seçtiğimiz takımı her sezon kontrol edelim oynadığımız maçlardaki puan her sezon seçtiğimiz takıma gelsin ve onunla maç yapalım
User prompt
şampiyonlar ligi puan durumunu kaldır ve şampiyonlar ligi maçlarını league table ın sağına koy
User prompt
ispanyadaki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
ingilteredeki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
Süperligdeki bütün takımlara gerçek hayattaki oyuncularını ekle
User prompt
seçtiğimiz takım asla değişmesin her sezon aynı takımı oynayalım
User prompt
oyuna Avrupa Ligi ekle 2.lig 3.lig ve 4.lig hariç her ligin 3. ve 4. sü gitsin
User prompt
2. lig 3.lig ve 4.lig hariç her ligin 1. ve 2. si şampiyonlar ligine gitsin
User prompt
budgeti gösterirken . dan sonra maksimum 3 sayı göster
User prompt
kalan maçları lig tablosunun altına koy
User prompt
ligde kalan maçları göster
User prompt
sezon sonu transfer teklifleri sadece türkiyeden gelmesin
User prompt
berabere kalınca lige göre para gelsin Premier Lig 5M La Liga 3.5M Serie A 3M Bundesliga 2.5M Ligue 1 1.5M Süper Lig 1.5M Eredivisie 1M Liga Portugal 1M 2.lig 0.25M 3.lig 0.15M 4.lig 0.05M
User prompt
maç kazanınca lige göre para gelsin Premier Lig 10M La Liga 7M Serie A 6M Bundesliga 5M Ligue 1 3M Süper Lig 3M Eredivisie 2M Liga Portugal 2M 2.lig 0.5M 3.lig 0.3M 4.lig 0.1M
User prompt
sırayla gitme
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a3d2f
});
/****
* Game Code
****/
// --- CONSTANTS ---
// Player class: represents a footballer
var Player = function Player(name, attack, defense, stamina, value, seasonsRemaining) {
var self = {};
self.name = name;
self.attack = attack;
self.defense = defense;
self.stamina = stamina;
self.value = value;
self.maxStamina = stamina;
self.inSquad = false; // true if in starting 5
self.seasonsRemaining = typeof seasonsRemaining === "number" ? seasonsRemaining : null; // null for non-transfer players, or integer for transfer market
return self;
};
// Team class: holds a list of players
var Team = function Team(name, players) {
var self = {};
self.name = name;
self.players = players; // array of Player
return self;
};
var SQUAD_SIZE = 5;
var BENCH_SIZE = 3;
var INITIAL_BUDGET = 100;
var PLAYER_MIN_VALUE = 10;
var PLAYER_MAX_VALUE = 40;
// --- GLOBALS ---
var allPlayers = []; // All players owned by user
var squad = []; // Starting 5
var bench = []; // Bench 3
var transferList = []; // Players available to buy
var budget = INITIAL_BUDGET;
var opponentTeam = null;
var matchInProgress = false;
var matchLog = [];
var matchResult = null;
var selectedPlayerIdx = null; // For swapping
var selectedBenchIdx = null; // For swapping
var infoText = null;
var budgetText = null;
var matchText = null;
var transferText = null;
var transferBtns = [];
var swapBtns = [];
var playBtn = null;
var nextBtn = null;
var sellBtns = [];
var buyBtns = [];
var squadLabels = [];
var benchLabels = [];
var opponentLabels = [];
var guiY = 0;
// --- CHAMPIONS LEAGUE SYSTEM ---
var championsLeagueTeams = []; // Array of {name, players, ...}
var championsLeagueFixtures = []; // Array of {homeIdx, awayIdx}
var championsLeagueCurrentRound = 0;
var championsLeagueActive = false;
var championsLeagueUserQualified = false;
var championsLeagueLog = [];
var championsLeagueResult = null;
var championsLeaguePrize = 0;
var championsLeagueStage = ""; // "Group", "Quarterfinal", etc.
var championsLeagueOpponent = null;
var championsLeagueUserPoints = 0;
var championsLeagueUserGroup = [];
var championsLeagueGroupResults = [];
var championsLeagueKnockoutTeams = [];
var championsLeagueKnockoutRound = 0;
var championsLeagueKnockoutOpponent = null;
var championsLeagueKnockoutLog = [];
var championsLeagueKnockoutResult = null;
var championsLeagueKnockoutStage = "";
var championsLeagueUserEliminated = false;
// --- EUROPA LEAGUE SYSTEM ---
var europaLeagueTeams = []; // Array of {name, players, ...}
var europaLeagueFixtures = []; // Array of {homeIdx, awayIdx}
var europaLeagueCurrentRound = 0;
var europaLeagueActive = false;
var europaLeagueUserQualified = false;
var europaLeagueLog = [];
var europaLeagueResult = null;
var europaLeaguePrize = 0;
var europaLeagueStage = ""; // "Group", "Quarterfinal", etc.
var europaLeagueOpponent = null;
var europaLeagueUserPoints = 0;
var europaLeagueUserGroup = [];
var europaLeagueGroupResults = [];
var europaLeagueKnockoutTeams = [];
var europaLeagueKnockoutRound = 0;
var europaLeagueKnockoutOpponent = null;
var europaLeagueKnockoutLog = [];
var europaLeagueKnockoutResult = null;
var europaLeagueKnockoutStage = "";
var europaLeagueUserEliminated = 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 = [
// Türkiye
"Galatasaray", "Fenerbahce", "Besiktas", "Trabzonspor", "Basaksehir", "Sivasspor", "Konyaspor", "Antalyaspor", "Alanyaspor",
// İngiltere
"Manchester City", "Arsenal", "Liverpool", "Chelsea", "Manchester United", "Tottenham",
// İspanya
"Real Madrid", "Barcelona", "Atletico Madrid", "Sevilla", "Valencia",
// Almanya
"Bayern Munich", "Borussia Dortmund", "RB Leipzig", "Bayer Leverkusen", "Union Berlin",
// İtalya
"Inter", "Juventus", "AC Milan", "Napoli", "Roma",
// Fransa
"Paris SG", "Marseille", "Lyon", "Monaco", "Lille",
// Hollanda
"PSV", "Ajax", "Feyenoord", "AZ Alkmaar", "Twente",
// Portekiz
"Benfica", "Porto", "Sporting CP", "Braga", "Guimaraes"]; // --- UTILS ---
// --- 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", [["Fernando Muslera", 7, 18, 16, 35], ["Sacha Boey", 10, 14, 15, 28], ["Victor Nelsson", 9, 15, 15, 29], ["Lucas Torreira", 10, 17, 17, 35], ["Mauro Icardi", 19, 8, 16, 42]]);
addSquad("Fenerbahce", [["Dominik Livakovic", 6, 17, 16, 34], ["Ferdi Kadıoğlu", 13, 15, 16, 32], ["Alexander Djiku", 9, 15, 15, 28], ["Fred", 12, 15, 16, 34], ["Edin Dzeko", 17, 7, 15, 38]]);
addSquad("Besiktas", [["Mert Günok", 6, 17, 15, 30], ["Valentin Rosier", 10, 13, 14, 25], ["Omar Colley", 8, 16, 15, 31], ["Salih Uçan", 12, 13, 15, 30], ["Cenk Tosun", 16, 7, 15, 34]]);
addSquad("Trabzonspor", [["Uğurcan Çakır", 6, 17, 16, 33], ["Joaquin Fernandez", 8, 15, 14, 28], ["Stefano Denswil", 9, 14, 14, 27], ["Enis Bardhi", 14, 8, 14, 29], ["Paul Onuachu", 16, 7, 15, 32]]);
addSquad("Basaksehir", [["Volkan Babacan", 6, 16, 14, 25], ["Leo Duarte", 8, 15, 14, 27], ["Ousseynou Ba", 9, 14, 14, 26], ["Danijel Aleksic", 12, 12, 14, 25], ["Joao Figueiredo", 14, 8, 14, 28]]);
addSquad("Sivasspor", [["Ali Şaşal Vural", 6, 16, 14, 24], ["Aaron Appindangoye", 8, 15, 14, 25], ["Hakan Arslan", 10, 13, 14, 25], ["Clinton N'Jie", 13, 8, 14, 27], ["Rey Manaj", 15, 8, 14, 28]]);
addSquad("Konyaspor", [["Ibrahim Sehic", 6, 16, 14, 24], ["Francisco Calvo", 8, 15, 14, 25], ["Guilherme", 10, 13, 14, 25], ["Oğulcan Ülgün", 11, 13, 14, 25], ["Sokol Cikalleshi", 14, 8, 14, 27]]);
addSquad("Antalyaspor", [["Helton Leite", 6, 16, 14, 24], ["Veysel Sarı", 8, 15, 14, 24], ["Bünyamin Balcı", 10, 13, 14, 24], ["Fernando", 11, 13, 14, 25], ["Adam Buksa", 14, 8, 14, 27]]);
addSquad("Alanyaspor", [["Runar Runarsson", 6, 16, 14, 24], ["Fidan Aliti", 8, 15, 14, 24], ["Yusuf Özdemir", 10, 13, 14, 24], ["Efecan Karaca", 13, 8, 14, 26], ["Oğuz Aydın", 14, 8, 14, 27]]);
addSquad("Adana Demirspor", [["Ertaç Özbir", 6, 16, 14, 25], ["Benjamin Stambouli", 9, 14, 14, 26], ["Younès Belhanda", 14, 10, 14, 28], ["Emre Akbaba", 13, 10, 14, 27], ["Mario Balotelli", 16, 7, 14, 30]]);
addSquad("Kayserispor", [["Silviu Lung", 6, 16, 14, 24], ["Onur Bulut", 8, 14, 14, 24], ["Bernard Mensah", 12, 13, 14, 25], ["Miguel Cardoso", 13, 8, 14, 27], ["Mame Thiam", 15, 8, 14, 28]]);
addSquad("Hatayspor", [["Erce Kardeşler", 6, 16, 14, 24], ["Sam Adekugbe", 8, 14, 14, 24], ["Rayane Aabid", 10, 13, 14, 25], ["Ruben Ribeiro", 13, 8, 14, 27], ["Ayoub El Kaabi", 15, 8, 14, 28]]);
addSquad("Gaziantep FK", [["Günay Güvenç", 6, 16, 14, 24], ["Papy Djilobodji", 10, 13, 14, 25], ["Halil Akbunar", 8, 14, 14, 24], ["Alexandru Maxim", 13, 8, 14, 27], ["Joao Figueiredo", 14, 8, 14, 28]]);
addSquad("Rizespor", [["Gökhan Akkan", 6, 16, 14, 24], ["Mithat Pala", 8, 15, 14, 24], ["Yannick Bolasie", 10, 13, 14, 24], ["Fernando Boldrin", 11, 13, 14, 25], ["Joel Pohjanpalo", 14, 8, 14, 27]]);
addSquad("Pendikspor", [["Burak Öğür", 6, 16, 14, 24], ["Emeka Eze", 8, 15, 14, 24], ["Elyas Bouzaiene", 10, 13, 14, 24], ["Ahmed Ildiz", 11, 13, 14, 25], ["Leandro Kappel", 14, 8, 14, 27]]);
addSquad("Samsunspor", [["Nurullah Aslan", 6, 16, 14, 24], ["Zeki Yavru", 8, 15, 14, 24], ["Ali Ülgen", 10, 13, 14, 24], ["Yasin Öztekin", 11, 13, 14, 25], ["Douglas Tanque", 14, 8, 14, 27]]);
addSquad("Kasımpaşa", [["Ertuğrul Taşkıran", 6, 16, 14, 24], ["Hasan Bilal", 8, 15, 14, 24], ["Tarkan Serbest", 10, 13, 14, 24], ["Aytaç Kara", 11, 13, 14, 25], ["Mamadou Fall", 14, 8, 14, 27]]);
addSquad("İstanbulspor", [["Alperen Uysal", 6, 16, 14, 24], ["Okan Erdoğan", 8, 15, 14, 24], ["Ali Yaşar", 10, 13, 14, 24], ["Deme N'Diaye", 11, 13, 14, 25], ["Valon Ethemi", 14, 8, 14, 27]]);
addSquad("Fatih Karagümrük", [["Emiliano Viviano", 6, 16, 14, 24], ["Ervin Zukanovic", 8, 15, 14, 24], ["Lucas Biglia", 10, 13, 14, 24], ["Emre Mor", 11, 13, 14, 25], ["Mbaye Diagne", 14, 8, 14, 27]]);
addSquad("MKE Ankaragücü", [["Gökhan Akkan", 6, 16, 14, 24], ["Atakan Çankaya", 8, 15, 14, 24], ["Endri Çekiçi", 10, 13, 14, 24], ["Geraldo", 11, 13, 14, 25], ["Ali Sowe", 14, 8, 14, 27]]);
// --- 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)
// Premier League 2024/25: Real squads for all 20 teams (5 players each, demo stats)
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]]);
addSquad("Liverpool", [["Mohamed Salah", 19, 10, 16, 110], ["Virgil van Dijk", 10, 18, 16, 90], ["Alisson", 6, 18, 16, 85], ["Trent Alexander-Arnold", 13, 15, 15, 85], ["Alexis Mac Allister", 14, 13, 15, 70]]);
addSquad("Chelsea", [["Enzo Fernández", 14, 14, 16, 80], ["Cole Palmer", 16, 10, 15, 70], ["Reece James", 12, 15, 15, 70], ["Christopher Nkunku", 17, 11, 15, 85], ["Thiago Silva", 7, 17, 14, 60]]);
addSquad("Manchester United", [["Bruno Fernandes", 16, 12, 16, 90], ["Marcus Rashford", 17, 10, 15, 85], ["Casemiro", 12, 16, 15, 80], ["Lisandro Martínez", 9, 16, 15, 70], ["André Onana", 6, 17, 15, 65]]);
addSquad("Tottenham", [["Heung-Min Son", 19, 11, 17, 110], ["James Maddison", 15, 12, 15, 75], ["Cristian Romero", 9, 16, 15, 70], ["Dejan Kulusevski", 14, 11, 15, 70], ["Guglielmo Vicario", 6, 16, 15, 60]]);
addSquad("Newcastle United", [["Alexander Isak", 17, 10, 15, 80], ["Bruno Guimarães", 14, 14, 15, 75], ["Kieran Trippier", 12, 15, 15, 70], ["Sven Botman", 9, 16, 15, 65], ["Nick Pope", 6, 16, 15, 65]]);
addSquad("Aston Villa", [["Ollie Watkins", 16, 10, 15, 70], ["Douglas Luiz", 13, 14, 15, 70], ["Emiliano Martínez", 6, 17, 15, 65], ["John McGinn", 13, 12, 15, 65], ["Pau Torres", 9, 15, 15, 65]]);
addSquad("West Ham", [["Jarrod Bowen", 15, 10, 15, 65], ["Lucas Paquetá", 14, 12, 15, 65], ["James Ward-Prowse", 13, 13, 15, 65], ["Kurt Zouma", 9, 15, 15, 60], ["Alphonse Areola", 6, 16, 15, 60]]);
addSquad("Brighton", [["Kaoru Mitoma", 15, 10, 15, 65], ["Pascal Groß", 13, 13, 15, 65], ["Lewis Dunk", 9, 15, 15, 60], ["João Pedro", 14, 10, 15, 60], ["Bart Verbruggen", 6, 16, 15, 60]]);
addSquad("Everton", [["Dominic Calvert-Lewin", 15, 10, 15, 60], ["James Tarkowski", 9, 15, 15, 60], ["Jordan Pickford", 6, 16, 15, 60], ["Abdoulaye Doucouré", 13, 12, 15, 60], ["Amadou Onana", 12, 13, 15, 60]]);
addSquad("Crystal Palace", [["Eberechi Eze", 15, 10, 15, 60], ["Marc Guéhi", 9, 15, 15, 60], ["Joachim Andersen", 9, 15, 15, 60], ["Michael Olise", 14, 10, 15, 60], ["Sam Johnstone", 6, 16, 15, 60]]);
addSquad("Wolves", [["Matheus Cunha", 15, 10, 15, 60], ["Pedro Neto", 14, 10, 15, 60], ["Max Kilman", 9, 15, 15, 60], ["Mario Lemina", 12, 13, 15, 60], ["José Sá", 6, 16, 15, 60]]);
addSquad("Fulham", [["João Palhinha", 13, 15, 15, 65], ["Andreas Pereira", 14, 12, 15, 60], ["Bernd Leno", 6, 16, 15, 60], ["Willian", 14, 10, 15, 60], ["Tim Ream", 9, 15, 15, 60]]);
addSquad("Brentford", [["Ivan Toney", 16, 10, 15, 70], ["Bryan Mbeumo", 15, 10, 15, 65], ["Ben Mee", 9, 15, 15, 60], ["Mathias Jensen", 13, 12, 15, 60], ["Mark Flekken", 6, 16, 15, 60]]);
addSquad("Bournemouth", [["Dominic Solanke", 15, 10, 15, 60], ["Philip Billing", 13, 12, 15, 60], ["Lloyd Kelly", 9, 15, 15, 60], ["Ryan Christie", 13, 12, 15, 60], ["Neto", 6, 16, 15, 60]]);
addSquad("Nottingham Forest", [["Morgan Gibbs-White", 15, 10, 15, 60], ["Taiwo Awoniyi", 15, 10, 15, 60], ["Danilo", 13, 12, 15, 60], ["Serge Aurier", 9, 15, 15, 60], ["Matt Turner", 6, 16, 15, 60]]);
addSquad("Burnley", [["Zeki Amdouni", 14, 10, 15, 60], ["Josh Brownhill", 13, 12, 15, 60], ["James Trafford", 6, 16, 15, 60], ["Jordan Beyer", 9, 15, 15, 60], ["Lyle Foster", 15, 10, 15, 60]]);
addSquad("Sheffield United", [["Oli McBurnie", 14, 10, 15, 60], ["Gustavo Hamer", 13, 12, 15, 60], ["Anel Ahmedhodžić", 9, 15, 15, 60], ["Wes Foderingham", 6, 16, 15, 60], ["Cameron Archer", 15, 10, 15, 60]]);
addSquad("Luton Town", [["Carlton Morris", 14, 10, 15, 60], ["Elijah Adebayo", 14, 10, 15, 60], ["Marvelous Nakamba", 12, 13, 15, 60], ["Tom Lockyer", 9, 15, 15, 60], ["Thomas Kaminski", 6, 16, 15, 60]]);
// --- 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)
// --- SPAIN: La Liga (2024/25, 5 oyuncu örnek) ---
addSquad("Real Madrid", [["Thibaut Courtois", 6, 19, 16, 90], ["Antonio Rüdiger", 9, 17, 16, 80], ["Jude Bellingham", 18, 14, 18, 150], ["Vinícius Júnior", 19, 12, 18, 150], ["Rodrygo", 17, 11, 16, 100]]);
addSquad("Barcelona", [["Marc-André ter Stegen", 6, 18, 16, 85], ["Ronald Araújo", 9, 17, 16, 80], ["Frenkie de Jong", 14, 14, 16, 90], ["Pedri", 15, 13, 17, 100], ["Robert Lewandowski", 20, 9, 15, 100]]);
addSquad("Atletico Madrid", [["Jan Oblak", 6, 18, 16, 85], ["José María Giménez", 9, 16, 15, 75], ["Antoine Griezmann", 18, 11, 16, 95], ["Álvaro Morata", 17, 10, 15, 80], ["Rodrigo De Paul", 14, 13, 16, 80]]);
addSquad("Sevilla", [["Yassine Bounou", 6, 17, 15, 70], ["Jesús Navas", 13, 13, 15, 70], ["Ivan Rakitić", 14, 12, 15, 70], ["Lucas Ocampos", 15, 10, 15, 70], ["Youssef En-Nesyri", 16, 10, 15, 75]]);
addSquad("Real Sociedad", [["Álex Remiro", 6, 16, 15, 65], ["Robin Le Normand", 9, 15, 15, 65], ["Mikel Merino", 14, 13, 16, 75], ["Takefusa Kubo", 15, 10, 15, 70], ["Mikel Oyarzabal", 16, 10, 15, 75]]);
addSquad("Villarreal", [["Pepe Reina", 6, 16, 14, 60], ["Pau Torres", 9, 15, 15, 65], ["Dani Parejo", 14, 13, 15, 70], ["Gerard Moreno", 17, 10, 15, 80], ["Álex Baena", 15, 10, 15, 65]]);
addSquad("Real Betis", [["Claudio Bravo", 6, 16, 14, 60], ["Germán Pezzella", 9, 15, 15, 65], ["Guido Rodríguez", 13, 14, 15, 70], ["Nabil Fekir", 16, 11, 15, 75], ["Borja Iglesias", 16, 10, 15, 70]]);
addSquad("Athletic Bilbao", [["Unai Simón", 6, 16, 15, 65], ["Iñigo Martínez", 9, 15, 15, 65], ["Iker Muniain", 15, 10, 15, 70], ["Oihan Sancet", 14, 12, 15, 65], ["Nico Williams", 15, 10, 15, 70]]);
addSquad("Valencia", [["Giorgi Mamardashvili", 6, 16, 15, 65], ["Gabriel Paulista", 9, 15, 15, 65], ["José Gayà", 13, 14, 15, 70], ["Hugo Duro", 15, 10, 15, 65], ["André Almeida", 14, 12, 15, 65]]);
addSquad("Celta Vigo", [["Iván Villar", 6, 16, 14, 60], ["Unai Núñez", 9, 15, 15, 65], ["Fran Beltrán", 13, 13, 15, 65], ["Iago Aspas", 17, 10, 15, 75], ["Jørgen Strand Larsen", 15, 10, 15, 65]]);
addSquad("Osasuna", [["Sergio Herrera", 6, 16, 14, 60], ["David García", 9, 15, 15, 65], ["Lucas Torró", 13, 13, 15, 65], ["Moi Gómez", 14, 12, 15, 65], ["Ante Budimir", 15, 10, 15, 65]]);
addSquad("Getafe", [["David Soria", 6, 16, 14, 60], ["Djené Dakonam", 9, 15, 15, 65], ["Nemanja Maksimović", 13, 13, 15, 65], ["Mason Greenwood", 15, 10, 15, 70], ["Borja Mayoral", 15, 10, 15, 65]]);
addSquad("Alaves", [["Antonio Sivera", 6, 16, 14, 60], ["Abdel Abqar", 9, 15, 15, 60], ["Rubén Duarte", 13, 13, 15, 60], ["Luis Rioja", 14, 12, 15, 60], ["Kike García", 15, 10, 15, 60]]);
addSquad("Granada", [["André Ferreira", 6, 16, 14, 60], ["Miguel Rubio", 9, 15, 15, 60], ["Ricard Sánchez", 13, 13, 15, 60], ["Bryan Zaragoza", 15, 10, 15, 65], ["Myrto Uzuni", 15, 10, 15, 65]]);
addSquad("Mallorca", [["Predrag Rajković", 6, 16, 14, 60], ["Antonio Raíllo", 9, 15, 15, 60], ["Dani Rodríguez", 13, 13, 15, 60], ["Vedat Muriqi", 16, 10, 15, 70], ["Kang-in Lee", 15, 10, 15, 65]]);
addSquad("Las Palmas", [["Álvaro Valles", 6, 16, 14, 60], ["Saúl Coco", 9, 15, 15, 60], ["Kirian Rodríguez", 13, 13, 15, 60], ["Jonathan Viera", 15, 10, 15, 65], ["Sandro Ramírez", 15, 10, 15, 60]]);
addSquad("Cadiz", [["Conan Ledesma", 6, 16, 14, 60], ["Fali", 9, 15, 15, 60], ["Alfonso Espino", 13, 13, 15, 60], ["Rubén Alcaraz", 14, 12, 15, 60], ["Roger Martí", 15, 10, 15, 60]]);
addSquad("Rayo Vallecano", [["Stole Dimitrievski", 6, 16, 14, 60], ["Alejandro Catena", 9, 15, 15, 60], ["Óscar Valentín", 13, 13, 15, 60], ["Isi Palazón", 15, 10, 15, 65], ["Raúl de Tomás", 15, 10, 15, 65]]);
addSquad("Girona", [["Paulo Gazzaniga", 6, 16, 14, 60], ["David López", 9, 15, 15, 60], ["Aleix García", 13, 13, 15, 60], ["Viktor Tsygankov", 15, 10, 15, 65], ["Cristhian Stuani", 15, 10, 15, 65]]);
addSquad("Almeria", [["Fernando Martínez", 6, 16, 14, 60], ["Rodrigo Ely", 9, 15, 15, 60], ["Lucas Robertone", 13, 13, 15, 60], ["Largie Ramazani", 15, 10, 15, 60], ["Luis Suárez", 15, 10, 15, 65]]);
// ... (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() {
var shownBudget = (Math.round(budget * 1000) / 1000).toString();
budgetText.setText("Budget: $" + shownBudget + "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)
// --- Show remaining league matches for user's team BELOW the league table ---
var remX = leagueX; // align with league table
var remY = leagueY + 70 + sortedLeague.length * 48 + 40; // just below league table
var remainingMatches = [];
for (var i = currentFixtureIdx; i < leagueFixtures.length; i++) {
var f = leagueFixtures[i];
if (f.homeIdx === userTeamIdx || f.awayIdx === userTeamIdx) {
var oppIdx = f.homeIdx === userTeamIdx ? f.awayIdx : f.homeIdx;
var oppName = leagueTeams[oppIdx] ? leagueTeams[oppIdx].name : "N/A";
var homeAway = f.homeIdx === userTeamIdx ? "Ev" : "Deplasman";
remainingMatches.push({
oppName: oppName,
homeAway: homeAway
});
}
}
if (remainingMatches.length > 0) {
var remHeader = makeLabel("Kalan Maçlar", remX, remY, 44, "#fdcb6e");
game.addChild(remHeader);
opponentLabels.push(remHeader);
for (var i = 0; i < Math.min(remainingMatches.length, 10); i++) {
var m = remainingMatches[i];
var remLabel = makeLabel(i + 1 + ". " + m.oppName + " (" + m.homeAway + ")", remX, remY + 60 + i * 38, 32, "#fff");
game.addChild(remLabel);
opponentLabels.push(remLabel);
}
remY += 60 + Math.min(remainingMatches.length, 10) * 38 + 20;
}
// --- Champions League matches: show only CL matches to the right of the league table ---
var clX = leagueX + leagueWidth + 80; // right of league table
var clY = leagueY;
if (championsLeagueActive || championsLeagueUserEliminated || showMatchLog._shownCLLogs && showMatchLog._shownCLLogs.length > 0) {
var clHeader = makeLabel("Şampiyonlar Ligi Maçları", clX, clY, 54, "#00b894");
game.addChild(clHeader);
opponentLabels.push(clHeader);
// Show only Champions League matches (from log)
if (showMatchLog._shownCLLogs && showMatchLog._shownCLLogs.length > 0) {
var logY = clY + 70;
var logHeader = makeLabel("ŞL Maçları", clX, logY, 36, "#00b894");
game.addChild(logHeader);
opponentLabels.push(logHeader);
var shownLogs = showMatchLog._shownCLLogs.slice(-8); // show last 8
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);
}
}
// Show next CL opponent if available
if (championsLeagueOpponent && (championsLeagueStage === "Group" || championsLeagueStage === "Semifinal" || championsLeagueStage === "Final")) {
var oppY = clY + 420;
var oppLabel = makeLabel("Sonraki Rakip: " + championsLeagueOpponent.name, clX, oppY, 36, "#fdcb6e");
game.addChild(oppLabel);
opponentLabels.push(oppLabel);
}
}
// 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 (updated values)
var leagueWinPrizes = {
5: 10,
// Premier Lig (England)
6: 7,
// La Liga (Spain)
8: 6,
// Serie A (Italy)
7: 5,
// Bundesliga (Germany)
9: 3,
// Ligue 1 (France)
1: 3,
// Süper Lig (Turkey)
10: 2,
// Eredivisie (Netherlands)
11: 2,
// Liga Portugal
2: 0.5,
// 2. Lig
3: 0.3,
// 3. Lig
4: 0.1 // 4. Lig
};
var winPrize = leagueWinPrizes[currentLeagueLevel] || 0.5;
matchLog.push((selectedTeamName || "You") + " win! +$" + winPrize + "M");
budget += winPrize;
} else if (userGoals < oppGoals) {
matchResult = "lose";
matchLog.push((selectedTeamName || "You") + " lose.");
} else {
matchResult = "draw";
// League-based draw prize money
var leagueDrawPrizes = {
5: 5,
// Premier Lig (England)
6: 3.5,
// La Liga (Spain)
8: 3,
// Serie A (Italy)
7: 2.5,
// Bundesliga (Germany)
9: 1.5,
// Ligue 1 (France)
1: 1.5,
// Süper Lig (Turkey)
10: 1,
// Eredivisie (Netherlands)
11: 1,
// Liga Portugal
2: 0.25,
// 2. Lig
3: 0.15,
// 3. Lig
4: 0.05 // 4. Lig
};
var drawPrize = leagueDrawPrizes[currentLeagueLevel] || 0.25;
matchLog.push("Draw. +$" + drawPrize + "M");
budget += drawPrize;
}
}
}
// 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 & EUROPA LEAGUE QUALIFICATION ---
// 2. Lig, 3. Lig ve 4. Lig hariç her ligin 1. ve 2. si Şampiyonlar Ligi'ne, 3. ve 4. sü Avrupa Ligi'ne gitsin
championsLeagueUserQualified = false;
europaLeagueUserQualified = false;
var leagueChampionName = sortedLeague[0].name;
var leagueSecondName = sortedLeague.length > 1 ? sortedLeague[1].name : null;
var leagueThirdName = sortedLeague.length > 2 ? sortedLeague[2].name : null;
var leagueFourthName = sortedLeague.length > 3 ? sortedLeague[3].name : null;
var eligibleForCL = currentLeagueLevel !== 2 && currentLeagueLevel !== 3 && currentLeagueLevel !== 4;
var eligibleForEL = currentLeagueLevel !== 2 && currentLeagueLevel !== 3 && currentLeagueLevel !== 4;
if (eligibleForCL) {
if (selectedTeamName && (leagueChampionName === selectedTeamName || leagueSecondName === selectedTeamName)) {
championsLeagueUserQualified = true;
}
}
if (eligibleForEL) {
if (selectedTeamName && (leagueThirdName === selectedTeamName || leagueFourthName === selectedTeamName)) {
europaLeagueUserQualified = true;
}
}
// --- 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 & Avrupa Ligi qualification as before ---
if (currentLeagueLevel === 1) {
if (selectedTeamName && leagueChampionName === selectedTeamName) {
championsLeagueUserQualified = true;
}
// Prepare Champions League teams for next season
championsLeagueTeams = [];
europaLeagueTeams = [];
// 1. ve 2. takımı ekle (kullanıcı ise kendi kadrosu, değilse gerçek kadro veya random)
if (eligibleForCL) {
// 1. takım
if (selectedTeamName && leagueChampionName === selectedTeamName) {
championsLeagueTeams.push({
name: selectedTeamName,
players: squad.map(clonePlayer)
});
} else {
var real1 = realSquads[leagueChampionName];
var players1 = real1 ? real1.map(clonePlayer) : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()];
championsLeagueTeams.push({
name: leagueChampionName,
players: players1
});
}
// 2. takım
if (leagueSecondName) {
if (selectedTeamName && leagueSecondName === selectedTeamName && !(leagueChampionName === selectedTeamName)) {
championsLeagueTeams.push({
name: selectedTeamName,
players: squad.map(clonePlayer)
});
} else if (leagueSecondName !== leagueChampionName) {
var real2 = realSquads[leagueSecondName];
var players2 = real2 ? real2.map(clonePlayer) : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()];
championsLeagueTeams.push({
name: leagueSecondName,
players: players2
});
}
}
}
// 3. ve 4. takımı Avrupa Ligi'ne ekle
if (eligibleForEL) {
if (leagueThirdName) {
if (selectedTeamName && leagueThirdName === selectedTeamName) {
europaLeagueTeams.push({
name: selectedTeamName,
players: squad.map(clonePlayer)
});
} else {
var real3 = realSquads[leagueThirdName];
var players3 = real3 ? real3.map(clonePlayer) : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()];
europaLeagueTeams.push({
name: leagueThirdName,
players: players3
});
}
}
if (leagueFourthName) {
if (selectedTeamName && leagueFourthName === selectedTeamName) {
europaLeagueTeams.push({
name: selectedTeamName,
players: squad.map(clonePlayer)
});
} else if (leagueFourthName !== leagueThirdName) {
var real4 = realSquads[leagueFourthName];
var players4 = real4 ? real4.map(clonePlayer) : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()];
europaLeagueTeams.push({
name: leagueFourthName,
players: players4
});
}
}
}
// Diğer liglerin 1. ve 2. takımlarını ekle (2. Lig, 3. Lig, 4. Lig hariç) ve 3. ve 4. takımlarını Avrupa Ligi'ne ekle
var otherLeagues = [{
clubs: leagueClubNamesEngland,
real: realSquads,
level: 5
}, {
clubs: leagueClubNamesSpain,
real: realSquads,
level: 6
}, {
clubs: leagueClubNamesGermany,
real: realSquads,
level: 7
}, {
clubs: leagueClubNamesItaly,
real: realSquads,
level: 8
}, {
clubs: leagueClubNamesFrance,
real: realSquads,
level: 9
}, {
clubs: leagueClubNamesNetherlands,
real: realSquads,
level: 10
}, {
clubs: leagueClubNamesPortugal,
real: realSquads,
level: 11
}];
for (var l = 0; l < otherLeagues.length; l++) {
var clubs = otherLeagues[l].clubs;
var real = otherLeagues[l].real;
// Simulate league table for this league (sort by real squad total stats)
var leagueTable = [];
for (var i = 0; i < clubs.length; i++) {
var cname = clubs[i];
var squadArr = real[cname] ? real[cname] : [makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer(), makeRandomPlayer()];
var total = 0;
for (var j = 0; j < 5; j++) {
var p = squadArr[j];
total += (p.attack || 0) + (p.defense || 0) + (p.stamina || 0);
}
leagueTable.push({
name: cname,
players: squadArr,
total: total
});
}
leagueTable.sort(function (a, b) {
return b.total - a.total;
});
// 1. ve 2. takımı Şampiyonlar Ligi'ne ekle
for (var pos = 0; pos < 2; pos++) {
if (leagueTable[pos]) {
championsLeagueTeams.push({
name: leagueTable[pos].name,
players: leagueTable[pos].players.map(clonePlayer)
});
}
}
// 3. ve 4. takımı Avrupa Ligi'ne ekle
for (var pos = 2; pos < 4; pos++) {
if (leagueTable[pos]) {
europaLeagueTeams.push({
name: leagueTable[pos].name,
players: leagueTable[pos].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()]
});
}
while (europaLeagueTeams.length < 8) {
europaLeagueTeams.push({
name: "Avrupa FC " + (europaLeagueTeams.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;
}
for (var i = europaLeagueTeams.length - 1; i > 0; i--) {
var j = randomInt(0, i);
var temp = europaLeagueTeams[i];
europaLeagueTeams[i] = europaLeagueTeams[j];
europaLeagueTeams[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;
europaLeagueActive = europaLeagueUserQualified;
europaLeagueCurrentRound = 0;
europaLeagueLog = [];
europaLeagueResult = null;
europaLeaguePrize = 0;
europaLeagueStage = "";
europaLeagueOpponent = null;
europaLeagueUserPoints = 0;
europaLeagueUserGroup = [];
europaLeagueGroupResults = [];
europaLeagueKnockoutTeams = [];
europaLeagueKnockoutRound = 0;
europaLeagueKnockoutOpponent = null;
europaLeagueKnockoutLog = [];
europaLeagueKnockoutResult = null;
europaLeagueKnockoutStage = "";
europaLeagueUserEliminated = 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.");
}
if (europaLeagueUserQualified) {
showInfo("Tebrikler! 3. veya 4. bitirdiniz ve Avrupa Ligi'ne katıldınız!");
}
// Reset league and start new season
initLeague();
// Always ensure custom team is present in leagueTeams every season
if ((typeof window !== "undefined" ? window._lockedTeamName : _lockedTeamName) && leagueTeams[0].name !== (typeof window !== "undefined" ? window._lockedTeamName : _lockedTeamName)) {
var lockedName = typeof window !== "undefined" ? window._lockedTeamName : _lockedTeamName;
var foundCustom = false;
for (var i = 0; i < leagueTeams.length; i++) {
if (leagueTeams[i].name === lockedName) {
foundCustom = true;
break;
}
}
if (!foundCustom) {
leagueTeams[0].name = lockedName;
// Takım kadrosunu da sabit tut
if (typeof window !== "undefined" && window._lockedPlayers) {
allPlayers = window._lockedPlayers.map(clonePlayer);
} else if (typeof _lockedPlayers !== "undefined" && _lockedPlayers) {
allPlayers = _lockedPlayers.map(clonePlayer);
}
updateSquadAndBench();
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) {
// Takım seçiminden sonra, seçilen takım adını ve kadrosunu global olarak sakla
if (typeof window !== "undefined") window._lockedTeamName = teamName;else _lockedTeamName = teamName;
if (typeof window !== "undefined") window._lockedPlayers = allPlayers ? allPlayers.map(clonePlayer) : null;else _lockedPlayers = allPlayers ? allPlayers.map(clonePlayer) : null;
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
@@ -588,71 +588,35 @@
opponentLabels.push(remLabel);
}
remY += 60 + Math.min(remainingMatches.length, 10) * 38 + 20;
}
- // --- Champions League group/knockout matches: show to the right of the league table ---
+ // --- Champions League matches: show only CL matches 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");
+ if (championsLeagueActive || championsLeagueUserEliminated || showMatchLog._shownCLLogs && showMatchLog._shownCLLogs.length > 0) {
+ var clHeader = makeLabel("Şampiyonlar Ligi Maçları", 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)
+ // Show only Champions League matches (from log)
if (showMatchLog._shownCLLogs && showMatchLog._shownCLLogs.length > 0) {
- var logY = clY + 500;
- var logHeader = makeLabel("ŞL Sonuçları", clX, logY, 36, "#00b894");
+ var logY = clY + 70;
+ var logHeader = makeLabel("ŞL Maçları", clX, logY, 36, "#00b894");
game.addChild(logHeader);
opponentLabels.push(logHeader);
- var shownLogs = showMatchLog._shownCLLogs.slice(-5); // show last 5
+ var shownLogs = showMatchLog._shownCLLogs.slice(-8); // show last 8
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);
}
}
+ // Show next CL opponent if available
+ if (championsLeagueOpponent && (championsLeagueStage === "Group" || championsLeagueStage === "Semifinal" || championsLeagueStage === "Final")) {
+ var oppY = clY + 420;
+ var oppLabel = makeLabel("Sonraki Rakip: " + championsLeagueOpponent.name, clX, oppY, 36, "#fdcb6e");
+ game.addChild(oppLabel);
+ opponentLabels.push(oppLabel);
+ }
}
// Opponent team player display removed as per requirements
}
function clearMatchText() {