-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// ---------------------- TEAM CLASS ----------------------
[Serializable]
public class Team
{
public string Name;
public string League;
public int Wins;
public int Draws;
public int Losses;
public int GoalsFor;
public int GoalsAgainst;
public Team(string name, string league)
{
Name = name;
League = league;
Wins = 0;
Draws = 0;
Losses = 0;
GoalsFor = 0;
GoalsAgainst = 0;
}
public int Points() => Wins * 3 + Draws;
public int GoalDifference() => GoalsFor - GoalsAgainst;
}
// ---------------------- MATCH CLASS ----------------------
public class Match
{
public Team HomeTeam;
public Team AwayTeam;
public int HomeGoals;
public int AwayGoals;
public Match(Team home, Team away)
{
HomeTeam = home;
AwayTeam = away;
}
public void PlayMatch()
{
System.Random rand = new System.Random();
HomeGoals = rand.Next(0, 5);
AwayGoals = rand.Next(0, 5);
HomeTeam.GoalsFor += HomeGoals;
HomeTeam.GoalsAgainst += AwayGoals;
AwayTeam.GoalsFor += AwayGoals;
AwayTeam.GoalsAgainst += HomeGoals;
if (HomeGoals > AwayGoals)
{
HomeTeam.Wins++;
AwayTeam.Losses++;
}
else if (HomeGoals < AwayGoals)
{
AwayTeam.Wins++;
HomeTeam.Losses++;
}
else
{
HomeTeam.Draws++;
AwayTeam.Draws++;
}
}
}
// ---------------------- GAME MANAGER ----------------------
public class DiskiFootballLeagueManager : MonoBehaviour
{
public List Teams = new List();
public List Matches = new List();
[Header("UI Elements")]
public GameObject rowPrefab; // Prefab for each league table row
public Transform tableParent; // Parent panel for table rows
public Text liveBannerText; // Text for Supersport PSL Live banner
void Start()
{
AddTeams(); // Add teams
ScheduleMatches(); // Schedule matches
PlaySeason(); // Simulate matches
DisplayLeagueTable("PSL"); // Display tables
DisplayLeagueTable("Premier League");
DisplayLeagueTable("LaLiga");
DisplayLeagueTable("Serie A");
DisplayLeagueTable("Bundesliga");
UpdateLiveBanner(); // Show live banner
}
void AddTeams()
{
// PSL
Teams.Add(new Team("Orlando Pirates", "PSL"));
Teams.Add(new Team("Kaizer Chiefs", "PSL"));
Teams.Add(new Team("Mamelodi Sundowns", "PSL"));
// Premier League
Teams.Add(new Team("Manchester United", "Premier League"));
Teams.Add(new Team("Liverpool", "Premier League"));
Teams.Add(new Team("Chelsea", "Premier League"));
// LaLiga
Teams.Add(new Team("Real Madrid", "LaLiga"));
Teams
Metadata
Metadata
Assignees
Labels
No labels