Пример #1
0
    /// <summary>
    /// <para>This method create the match of the tournament of the group phase.</para>
    /// <para>Each group has 6 matches (Groups of 4)</para>
    /// </summary>
    private void CreateGroupPhaseMatches()
    {
        //pattern to assign a number of match in the group
        int[] mNumber      = new int[] { 0, 1, 2, 2, 1, 0 };
        int   matchesCount = 0;

        for (int i = 0; i < teamsAmount; i += 4)
        {
            int l = i;
            int v = i + 1;
            //Create 6 matches
            while (matchesCount < 6)
            {
                MatchTourInfo match = new MatchTourInfo(teamList[l], 0, teamList[v], 0, mNumber[matchesCount], false);

                groupPhaseMatches.Add(match);
                matchesCount++;
                v++;

                if (v == i + 4)
                {
                    l++;
                    v = l + 1;
                }
            }
            matchesCount = 0;
        }
        //Order the list of matches by match number. 2 matches for group every round.
        List <MatchTourInfo> sortedList = groupPhaseMatches.OrderBy(match => match.matchNumber).ToList();

        groupPhaseMatches = sortedList;
    }
Пример #2
0
    /// <summary>
    /// Create matches for next final round
    /// </summary>
    /// <param name="startIndex">From which match is goinf to take winner</param>
    /// <param name="endIndex">Where list of winner end</param>
    private void CreateNextRoundInFinals(int startIndex, int endIndex)
    {
        List <TeamTourInfo> winnersLeftKey  = new List <TeamTourInfo>();
        List <TeamTourInfo> winnersRightKey = new List <TeamTourInfo>();

        for (int i = startIndex; i < endIndex; i++)
        {
            winnersLeftKey.Add(GetMatchWinnerTeamInfo(leftKeyFinalMatches[i]));
            winnersRightKey.Add(GetMatchWinnerTeamInfo(rightKeyFinalMatches[i]));
        }
        for (int i = 0; i < winnersLeftKey.Count; i += 2)
        {
            MatchTourInfo leftmatch = new MatchTourInfo(winnersLeftKey[i], 0, winnersLeftKey[i + 1], 0, matchesRound, false);
            leftKeyFinalMatches.Add(leftmatch);
            if (IsPlayerMatch(leftmatch))
            {
                playerMatches.Add(leftmatch);
            }

            MatchTourInfo rightMatch = new MatchTourInfo(winnersRightKey[i], 0, winnersRightKey[i + 1], 0, matchesRound, false);
            rightKeyFinalMatches.Add(rightMatch);
            if (IsPlayerMatch(rightMatch))
            {
                playerMatches.Add(rightMatch);
            }
        }
    }
Пример #3
0
 public MatchTourInfo(MatchTourInfo info)
 {
     localTeam   = info.localTeam;
     localGoals  = info.localGoals;
     visitTeam   = info.visitTeam;
     visitGoals  = info.visitGoals;
     matchNumber = info.matchNumber;
     played      = info.played;
 }
Пример #4
0
 /// <summary>
 /// Checks if a match has the player team, if so adds it to player's list matches
 /// </summary>
 /// <param name="match">Match to check</param>
 private bool IsPlayerMatch(MatchTourInfo match)
 {
     if (match.localTeam.teamName == teamSelected || match.visitTeam.teamName == teamSelected)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #5
0
 public string GetMatchWinnerString(MatchTourInfo match)
 {
     if (match.localGoals > match.visitGoals)
     {
         return("local");
     }
     else
     {
         return("visit");
     }
 }
Пример #6
0
 /// <summary>
 /// Return a winner of a match comparing scores.
 /// </summary>
 /// <param name="match">Match which want to be evaluate</param>
 /// <returns>String with name of the winner</returns>
 public TeamTourInfo GetMatchWinnerTeamInfo(MatchTourInfo match)
 {
     if (match.localGoals > match.visitGoals)
     {
         return(match.localTeam);
     }
     else
     {
         return(match.visitTeam);
     }
 }
Пример #7
0
    /// <summary>
    /// Get winner of both key and create final match
    /// </summary>
    private void CreateFinalMatch()
    {
        TeamTourInfo  leftKeyWinner  = GetMatchWinnerTeamInfo(leftKeyFinalMatches[leftKeyFinalMatches.Count - 1]);
        TeamTourInfo  rightKeyWinner = GetMatchWinnerTeamInfo(rightKeyFinalMatches[rightKeyFinalMatches.Count - 1]);
        MatchTourInfo final          = new MatchTourInfo(leftKeyWinner, 0, rightKeyWinner, 0, matchesRound, false);

        finalMatch = final;
        if (IsPlayerMatch(final))
        {
            playerMatches.Add(final);
        }
    }
Пример #8
0
    /// <summary>
    /// Simulate a npc match but cannot be a draw in the match
    /// For final matches.
    /// </summary>
    /// <param name="match">Npc's match with no info</param>
    /// <returns>Npc's match with new result</returns>
    private MatchTourInfo SimulateMatchNoDraws(MatchTourInfo match)
    {
        int localGoals = 0;
        int visitGoals = 0;

        while (localGoals == visitGoals)
        {
            localGoals = Random.Range(0, 6);
            visitGoals = Random.Range(0, 6);
        }

        match.localGoals = localGoals;
        match.visitGoals = visitGoals;
        match.played     = true;
        return(new MatchTourInfo(match));
    }
Пример #9
0
    /// <summary>
    /// Returns player's match with result got it from match controller.
    /// </summary>
    /// <param name="match">Player's match with no info</param>
    /// <returns>Player's match with new result</returns>
    private MatchTourInfo GetPlayerMatchResult(MatchTourInfo match)
    {
        if (match.localTeam.teamName == teamSelected)
        {
            match.localGoals = MatchController._matchController.LeftTeamScore;
            match.visitGoals = MatchController._matchController.RightTeamScore;
        }
        else
        {
            match.localGoals = MatchController._matchController.RightTeamScore;
            match.visitGoals = MatchController._matchController.LeftTeamScore;
        }

        match.played = true;

        return(new MatchTourInfo(match));
    }
Пример #10
0
    /// <summary>
    /// Get result from a match and look for teams that have played and update team tour information.
    /// </summary>
    /// <param name="match">Match with result information</param>
    private void UpdateTeamInformation(MatchTourInfo match)
    {
        //Local in 0 and visit in 1
        int localTeamIndex = GetTeamIndex(match.localTeam.teamName);
        int visitTeamIndex = GetTeamIndex(match.visitTeam.teamName);

        //Update goals
        teamList[localTeamIndex].goalsScored   += match.localGoals;
        teamList[localTeamIndex].goalsReceived += match.visitGoals;

        teamList[visitTeamIndex].goalsScored   += match.visitGoals;
        teamList[visitTeamIndex].goalsReceived += match.localGoals;

        //Update Victories, defeats, draws and points
        if (match.localGoals > match.visitGoals)
        {
            teamList[localTeamIndex].victories++;
            teamList[localTeamIndex].points += 3;
            teamList[visitTeamIndex].defeats++;
        }
        else if (match.localGoals < match.visitGoals)
        {
            teamList[localTeamIndex].defeats++;
            teamList[visitTeamIndex].victories++;
            teamList[visitTeamIndex].points += 3;
        }
        else
        {
            teamList[localTeamIndex].draws++;
            teamList[localTeamIndex].points++;
            teamList[visitTeamIndex].draws++;
            teamList[visitTeamIndex].points++;
        }

        //Update knockout victories and defeats.
        if (match.localGoals == 5)
        {
            teamList[localTeamIndex].knockoutVictories++;
            teamList[visitTeamIndex].knockoutDefeats++;
        }
        if (match.visitGoals == 5)
        {
            teamList[localTeamIndex].knockoutDefeats++;
            teamList[visitTeamIndex].knockoutVictories++;
        }
    }
Пример #11
0
    /// <summary>
    /// Create finals for gold cup
    /// </summary>
    private void CreateFinalMatchesFor12Teams()
    {
        //Left key
        //match 1
        MatchTourInfo rightMatch;
        MatchTourInfo leftMatch = new MatchTourInfo(teamsForFinals[0], 0, teamsForFinals[3], 0, 3, false);

        leftKeyFinalMatches.Add(leftMatch);
        if (IsPlayerMatch(leftMatch))
        {
            playerMatches.Add(leftMatch);
        }
        //match2
        if (teamsForFinals[6].teamGroup == "A" || teamsForFinals[6].teamGroup == "B")
        {
            leftMatch  = new MatchTourInfo(teamsForFinals[2], 0, teamsForFinals[6], 0, 3, false);
            rightMatch = new MatchTourInfo(teamsForFinals[4], 0, teamsForFinals[7], 0, 3, false);
        }
        else
        {
            leftMatch  = new MatchTourInfo(teamsForFinals[2], 0, teamsForFinals[7], 0, 3, false);
            rightMatch = new MatchTourInfo(teamsForFinals[4], 0, teamsForFinals[6], 0, 3, false);
        }
        leftKeyFinalMatches.Add(leftMatch);
        if (IsPlayerMatch(leftMatch))
        {
            playerMatches.Add(leftMatch);
        }

        //Right key
        //Match 3
        rightKeyFinalMatches.Add(rightMatch);
        if (IsPlayerMatch(rightMatch))
        {
            playerMatches.Add(rightMatch);
        }

        //Match 4
        rightMatch = new MatchTourInfo(teamsForFinals[5], 0, teamsForFinals[1], 0, 3, false);
        rightKeyFinalMatches.Add(rightMatch);
        if (IsPlayerMatch(rightMatch))
        {
            playerMatches.Add(rightMatch);
        }
    }
Пример #12
0
    /// <summary>
    /// Simulate a match between npc's getting match result with random numbers
    /// </summary>
    /// <param name="match">Npc's match with no info</param>
    /// <returns>Npc's match with new result</returns>
    private MatchTourInfo SimulateMatch(MatchTourInfo match)
    {
        int localGoals = Random.Range(0, 6);
        int visitGoals;

        if (localGoals == 5)
        {
            visitGoals = Random.Range(0, 5);
        }
        else
        {
            visitGoals = Random.Range(0, 6);
        }

        match.localGoals = localGoals;
        match.visitGoals = visitGoals;
        match.played     = true;
        return(new MatchTourInfo(match));
    }
Пример #13
0
    /// <summary>
    /// Check if team selected is in knockout stage
    /// </summary>
    /// <returns>True if it is, false if not</returns>
    public bool IsPlayerInFinals()
    {
        if (matchesRound == 3)
        {
            foreach (var team in teamsForFinals)
            {
                if (team.teamName == teamSelected)
                {
                    return(true);
                }
            }
        }

        if (matchesRound > 3)
        {
            for (int i = 0; i < leftKeyFinalMatches.Count; i++)
            {
                MatchTourInfo match = leftKeyFinalMatches[i];
                if (match.matchNumber == matchesRound - 1)
                {
                    if (match.played)
                    {
                        if (GetMatchWinnerTeamInfo(match).teamName == teamSelected)
                        {
                            return(true);
                        }
                    }

                    match = rightKeyFinalMatches[i];
                    if (match.played)
                    {
                        if (GetMatchWinnerTeamInfo(match).teamName == teamSelected)
                        {
                            return(true);
                        }
                    }
                }
            }
        }
        return(false);
    }
Пример #14
0
    /// <summary>
    /// Create the finals matches for world cup, Amercian Cup, Asia and Africa.
    /// Since they have the same pattern of combination in knockout stage
    /// </summary>
    private void CreateFinalMatchesFor32and16Teams()
    {
        for (int i = 0; i < teamsForFinals.Count; i += 4)
        {
            //Left key
            MatchTourInfo leftMatch = new MatchTourInfo(teamsForFinals[i], 0, teamsForFinals[i + 3], 0, 3, false);
            leftKeyFinalMatches.Add(leftMatch);
            if (IsPlayerMatch(leftMatch))
            {
                playerMatches.Add(leftMatch);
            }

            //Right key
            MatchTourInfo rightMatch = new MatchTourInfo(teamsForFinals[i + 1], 0, teamsForFinals[i + 2], 0, 3, false);
            rightKeyFinalMatches.Add(rightMatch);
            if (IsPlayerMatch(rightMatch))
            {
                playerMatches.Add(rightMatch);
            }
        }
    }
Пример #15
0
    public TourInfo(TournamentController tour)
    {
        tourName              = tour.tourName;
        teamSelected          = tour.teamSelected;
        matchTime             = tour.matchTime;
        tourLevel             = tour.tourLevel;
        teamsAmount           = tour.teamsAmount;
        groupsAmount          = tour.groupsAmount;
        matchesRound          = tour.matchesRound;
        teamsForKnockoutStage = tour.teamsForKnockoutStage;

        teamList          = tour.teamList;
        playerMatches     = tour.playerMatches;
        groupPhaseMatches = tour.groupPhaseMatches;

        teamsForFinals       = tour.teamsForFinals;
        leftKeyFinalMatches  = tour.leftKeyFinalMatches;
        rightKeyFinalMatches = tour.rightKeyFinalMatches;

        finalMatch = tour.finalMatch;
    }
Пример #16
0
    //Load this tournament
    public void LoadTour()
    {
        TourInfo info = SaveSystem.LoadTournament();

        tourName              = info.tourName;
        teamSelected          = info.teamSelected;
        matchTime             = info.matchTime;
        tourLevel             = info.tourLevel;
        teamsAmount           = info.teamsAmount;
        groupsAmount          = info.groupsAmount;
        matchesRound          = info.matchesRound;
        teamsForKnockoutStage = info.teamsForKnockoutStage;

        teamList          = info.teamList;
        playerMatches     = info.playerMatches;
        groupPhaseMatches = info.groupPhaseMatches;

        teamsForFinals       = info.teamsForFinals;
        leftKeyFinalMatches  = info.leftKeyFinalMatches;
        rightKeyFinalMatches = info.rightKeyFinalMatches;

        finalMatch = info.finalMatch;
    }
Пример #17
0
    /// <summary>
    /// Create finals for EuroCup
    /// </summary>
    private void CreateFinalMatchesFor24Teams()
    {
        MatchTourInfo leftMatch, rightMatch;

        //Left key matches
        //Match 1
        leftMatch = new MatchTourInfo(teamsForFinals[1], 0, teamsForFinals[5], 0, 3, false);
        leftKeyFinalMatches.Add(leftMatch);
        if (IsPlayerMatch(leftMatch))
        {
            playerMatches.Add(leftMatch);
        }

        //Match 2
        leftMatch = new MatchTourInfo(teamsForFinals[6], 0, teamsForFinals[15], 0, 3, false);
        leftKeyFinalMatches.Add(leftMatch);
        if (IsPlayerMatch(leftMatch))
        {
            playerMatches.Add(leftMatch);
        }

        //Match 3
        leftMatch = new MatchTourInfo(teamsForFinals[2], 0, teamsForFinals[14], 0, 3, false);
        leftKeyFinalMatches.Add(leftMatch);
        if (IsPlayerMatch(leftMatch))
        {
            playerMatches.Add(leftMatch);
        }

        //Match 3
        leftMatch = new MatchTourInfo(teamsForFinals[10], 0, teamsForFinals[9], 0, 3, false);
        leftKeyFinalMatches.Add(leftMatch);
        if (IsPlayerMatch(leftMatch))
        {
            playerMatches.Add(leftMatch);
        }

        //Right key matches
        //Match 1
        rightMatch = new MatchTourInfo(teamsForFinals[4], 0, teamsForFinals[13], 0, 3, false);
        rightKeyFinalMatches.Add(rightMatch);
        if (IsPlayerMatch(rightMatch))
        {
            playerMatches.Add(rightMatch);
        }

        //Match 2
        rightMatch = new MatchTourInfo(teamsForFinals[8], 0, teamsForFinals[7], 0, 3, false);
        rightKeyFinalMatches.Add(rightMatch);
        if (IsPlayerMatch(rightMatch))
        {
            playerMatches.Add(rightMatch);
        }

        //Match 3
        rightMatch = new MatchTourInfo(teamsForFinals[0], 0, teamsForFinals[12], 0, 3, false);
        rightKeyFinalMatches.Add(rightMatch);
        if (IsPlayerMatch(rightMatch))
        {
            playerMatches.Add(rightMatch);
        }

        //Match 4
        rightMatch = new MatchTourInfo(teamsForFinals[3], 0, teamsForFinals[11], 0, 3, false);
        rightKeyFinalMatches.Add(rightMatch);
        if (IsPlayerMatch(rightMatch))
        {
            playerMatches.Add(rightMatch);
        }
    }
Пример #18
0
    /// <summary>
    /// Itarate over list of finals matches and get a result.
    /// Create new matches for stage and add them at the end of final matches lists
    /// </summary>
    /// <param name="round">Match round</param>
    public void SimulateRoundOfMatchesInKnockOutStage()
    {
        //Final
        if (teamsForKnockoutStage == 16 && matchesRound == 6)
        {
            finalMatch = GetPlayerMatchResult(finalMatch);
            playerMatches[matchesRound] = GetPlayerMatchResult(playerMatches[matchesRound]);
            return;
        }
        if (teamsForKnockoutStage == 8 && matchesRound == 5)
        {
            finalMatch = GetPlayerMatchResult(finalMatch);
            playerMatches[matchesRound] = GetPlayerMatchResult(playerMatches[matchesRound]);
            return;
        }

        //Simulate matches of one round
        for (int i = 0; i < leftKeyFinalMatches.Count; i++)
        {
            MatchTourInfo leftMatch = leftKeyFinalMatches[i];
            if (leftMatch.matchNumber == matchesRound)
            {
                if (!IsPlayerMatch(leftMatch))
                {
                    if (!leftMatch.played)
                    {
                        leftMatch = SimulateMatchNoDraws(leftMatch);
                    }
                }
                else
                {
                    playerMatches[matchesRound] = GetPlayerMatchResult(playerMatches[matchesRound]);
                    leftMatch = GetPlayerMatchResult(leftMatch);
                }
            }

            MatchTourInfo rightMatch = rightKeyFinalMatches[i];
            if (rightMatch.matchNumber == matchesRound)
            {
                if (!IsPlayerMatch(rightMatch))
                {
                    if (!rightMatch.played)
                    {
                        rightMatch = SimulateMatchNoDraws(rightMatch);
                    }
                }
                else
                {
                    playerMatches[matchesRound] = GetPlayerMatchResult(playerMatches[matchesRound]);
                    rightMatch = GetPlayerMatchResult(rightMatch);
                }
            }
        }
        matchesRound++;

        //Create next matches
        if (teamsForKnockoutStage == 16)
        {
            switch (matchesRound)
            {
            //Create QuarteFinals
            case 4:
                CreateNextRoundInFinals(0, 4);
                break;

            //Create semifinals
            case 5:
                CreateNextRoundInFinals(4, 6);
                break;

            case 6:
                CreateFinalMatch();
                break;
            }
        }
        else
        {
            switch (matchesRound)
            {
            //Create semifinals
            case 4:
                CreateNextRoundInFinals(0, 2);
                break;

            case 5:
                CreateFinalMatch();
                break;
            }
        }
    }
Пример #19
0
    /// <summary>
    /// Show and control UI for knockout stage
    /// </summary>
    private void SetFinalsPanel()
    {
        //Set cup image
        Tournament tourCup = Resources.Load <Tournament>("Tours/" + tourInfo.tourName);

        tourCupImage.sprite = tourCup.cupImage;

        int index, limit = 0, matchListIndex = 0;

        if (tourInfo.teamsForKnockoutStage == 16)
        {
            index = 0;
            tourFinalsStructure.sprite = round16Structure;
            if (tourInfo.matchesRound == 3)
            {
                limit = 1;
                tourFinalsRound.text = "Round of 16";
                roundText.text       = "Round of 16";
            }
            else if (tourInfo.matchesRound == 4)
            {
                limit = 2;
                tourFinalsRound.text = "Quarter finals";
                roundText.text       = "Quarter finals";
            }
            else if (tourInfo.matchesRound == 5)
            {
                limit = 3;
                tourFinalsRound.text = "Semi-finals";
                roundText.text       = "Semi-finals";
            }
            else if (tourInfo.matchesRound == 6)
            {
                limit = 3;
                tourFinalsRound.text = "FINAL";
                roundText.text       = "FINAL";
                SetFinalUI();
            }
        }
        else
        {
            index = 1;
            tourFinalsStructure.sprite = round8Strucure;
            if (tourInfo.matchesRound == 3)
            {
                limit = 2;
                tourFinalsRound.text = "Quarter finals";
                roundText.text       = "Quarter finals";
            }
            else if (tourInfo.matchesRound == 4)
            {
                limit = 3;
                tourFinalsRound.text = "Semi-finals";
                roundText.text       = "Semi-finals";
            }
            else if (tourInfo.matchesRound == 5)
            {
                limit = 3;
                tourFinalsRound.text = "FINAL";
                roundText.text       = "FINAL";
                SetFinalUI();
            }
        }


        if (tourInfo.matchesRound >= 3)
        {
            leftKeyFinals.gameObject.SetActive(true);
            rightKeyFinals.gameObject.SetActive(true);
            for (int i = index; i < limit; i++)
            {
                Transform leftMatchUI  = leftKeyFinals.GetChild(i);
                Transform rightMatchUI = rightKeyFinals.GetChild(i);
                leftMatchUI.gameObject.SetActive(true);
                rightMatchUI.gameObject.SetActive(true);

                for (int j = 0; j < leftMatchUI.childCount; j++)
                {
                    //////////////////////////////////////////// //Left key UI
                    Transform     matchUI = leftMatchUI.GetChild(j).transform;
                    MatchTourInfo match   = tourInfo.leftKeyFinalMatches[matchListIndex];

                    Image localFlag = matchUI.GetChild(0).GetComponent <Image>();
                    Image visitFlag = matchUI.GetChild(1).GetComponent <Image>();

                    localFlag.sprite = GetTeamInformation(match.localTeam.teamName).flag;
                    visitFlag.sprite = GetTeamInformation(match.visitTeam.teamName).flag;

                    if (match.played)
                    {
                        if (tourInfo.GetMatchWinnerString(match) == "local")
                        {
                            localFlag.gameObject.SetActive(false);
                            visitFlag.gameObject.SetActive(true);
                        }
                        else
                        {
                            localFlag.gameObject.SetActive(true);
                            visitFlag.gameObject.SetActive(false);
                        }
                    }

                    ///////////////////////////Right key UI
                    matchUI = rightMatchUI.GetChild(j).transform;
                    match   = tourInfo.rightKeyFinalMatches[matchListIndex];

                    localFlag = matchUI.GetChild(0).GetComponent <Image>();
                    visitFlag = matchUI.GetChild(1).GetComponent <Image>();

                    localFlag.sprite = GetTeamInformation(match.localTeam.teamName).flag;
                    visitFlag.sprite = GetTeamInformation(match.visitTeam.teamName).flag;


                    if (match.played)
                    {
                        if (tourInfo.GetMatchWinnerString(match) == "local")
                        {
                            localFlag.gameObject.SetActive(false);
                            visitFlag.gameObject.SetActive(true);
                        }
                        else
                        {
                            localFlag.gameObject.SetActive(true);
                            visitFlag.gameObject.SetActive(false);
                        }
                    }

                    matchListIndex++;
                }
            }
        }
    }