public TennisSet(TennisMatch parent) { PartOf = parent; Duration = new TennisDuration(); Games = new List <TennisGame>(); StartServer = PartOf.GetNextServer() == PartOf.Contestant1 ? 1 : 2; Statistics = new TennisStatistics(this); ScoreContestant1 = 0; ScoreContestant2 = 0; }
/// <summary> /// Create a new match from the given variant name /// </summary> /// <param name="_variant"></param> /// <returns></returns> public static TennisMatch CreateMatchFromVariant(String _variant) { List <TennisMatchVariant> Variants = TennisMatch.GetDefaultVariants(); var _selectedVariant = Variants.Where(x => x.Description.ToLower() == _variant.ToLower()); if (_selectedVariant.Count() != 1) { return(null); } return(TennisMatch.CreateMatchFromVariant(_selectedVariant.First())); }
/// <summary> /// Create a new match from the given variant /// </summary> /// <param name="_variant"></param> /// <returns></returns> public static TennisMatch CreateMatchFromVariant(TennisMatchVariant _variant) { TennisMatch _newMatch; _newMatch = new TennisMatch(); _newMatch.DeuceSuddenDeath = _variant.DeuceSuddenDeath; _newMatch.FinalSetIsTiebreak = _variant.FinalSetIsTiebreak; _newMatch.FinalSetTieBreakLength = _variant.FinalSetTieBreakLength; _newMatch.NumberGamesPerSet = _variant.NumberGamesPerSet; _newMatch.TieBreakAtSameScoreOf = _variant.TieBreakAtSameScoreOf; _newMatch.TieBreakFinalSet = _variant.TieBreakFinalSet; _newMatch.TieBreakLength = _variant.TieBreakLength; return(_newMatch); }
public int GetLocalPlayer() { if (m_LocalPlayer == 0) { TennisGame Game = this.PartOf; TennisSet Set = Game.PartOf; TennisMatch Match = Set.PartOf; m_LocalPlayer = 1; //if (Match.Contestant1.ContainsLocalPlayer) m_LocalPlayer = 1; if (Match.Contestant2.ContainsLocalPlayer) { m_LocalPlayer = 2; } } return(m_LocalPlayer); }
/// <summary> /// Return the contestant number of the player of this collection /// </summary> /// <param name="match"></param> /// <returns></returns> private int GetContestantID(TennisMatch match) { foreach (TennisPlayer Player in match.Contestant1.Players) { if (Player.ID == this.Player) { return(1); } } foreach (TennisPlayer Player in match.Contestant2.Players) { if (Player.ID == this.Player) { return(2); } } return(-1); }
/// <summary> /// Adds all statistics of the match to this collection /// </summary> /// <param name="match"></param> public void Add(TennisMatch match) { //get the contestant ID int ContestantID = GetContestantID(match); //clear the collection, in case the match was resumed Items.RemoveAll(x => x.MatchID == match.ID.ToString()); //add the new values if (ContestantID != -1) { foreach (TennisStatistic Statistic in match.Statistics.Items) { if (Statistic.Contestant == ContestantID) { SetItem(Statistic.Item, Statistic.Value, match.ID.ToString(), match.Type); } } } OnUpdatedMatch(EventArgs.Empty); }
public TennisStatistics(TennisMatch owner) { Items = new List <TennisStatistic>(); currentMatch = owner; currentSet = null; }
/// <summary> /// Adds all statistics of the match to this collection /// </summary> /// <param name="match"></param> public void Remove(TennisMatch match) { Remove(match.ID); }