コード例 #1
0
 public TournamentModel(string Name, List <TeamModel> Teams, int ParalellMatches)
 {
     this.Name            = Name;
     this.Teams           = Teams.OrderBy(a => Guid.NewGuid()).ToList();
     this.ParalellMatches = ParalellMatches;
     CurrentRound         = new RoundModel(this.Teams);
 }
コード例 #2
0
        //Sets WAITING matches to CurrentMatches
        public void SetCurrentMatches()
        {
            int counter = 0;
            List <MatchModel> NextMatches = new List <MatchModel>();

            foreach (MatchModel match in CurrentRound.Matches)
            {
                if (match.MatchState == MatchState.INPROGRESS)
                {
                    NextMatches.Add(match);
                    counter++;
                }
                else if (match.MatchState == MatchState.WAITING)
                {
                    match.MatchState = MatchState.INPROGRESS;
                    NextMatches.Add(match);
                    counter++;
                }
                if (counter == ParalellMatches)
                {
                    CurrentMatches = NextMatches;
                    return;
                }
            }
            //Creates next round if no more matches are WAITING
            if (counter == 0)
            {
                CurrentRound.RoundFinished = true;
                if (!CurrentRound.LastRound)
                {
                    CurrentRound = CurrentRound.CreateNextRound();
                    SetCurrentMatches();
                }
                else
                {
                    CurrentMatches = new List <MatchModel>();
                }
                return;
            }
            CurrentMatches = NextMatches;
        }