//This is based on the assumption that stat is going to be in seconds (possibly with miliseconds) public override void SetResult(string stat, TTeam.ITeam winner) { float tmp = matchLength; //a safety check just in case stat is not a number try { matchLength = float.Parse(stat); if (matchLength < 0) { matchLength = 0; throw new NegativeMatchLengthException(CreateCopy()); } } //float.parse throws FormatException if stat can't be converted catch (FormatException) { throw new NotNumberMatchLengthException(CreateCopy()); } winner.SetMatchResult(true, tmp != 0, tmp != 0 && this.Winner == winner, stat + " - " + tmp.ToString()); if (winner == TeamA) { TeamB.SetMatchResult(false, tmp != 0, tmp != 0 && this.Winner == TeamB, stat + " - " + tmp.ToString()); } else { TeamA.SetMatchResult(false, tmp != 0, tmp != 0 && this.Winner == TeamA, stat + " - " + tmp.ToString()); } base.SetResult(stat, winner); }
public Match(Match match) { this.teamA = match.teamA; this.teamB = match.teamB; this.winner = match.winner; this.RefA = match.RefA; }
public virtual void Walkover(TTeam.ITeam absentee) { if (IsWalkover == true) { winner = null; } isWalkover = true; }
public Match(TTeam.ITeam a, TTeam.ITeam b, List <TPerson.Referee> r) { if (a == b) { throw new IncorrectOpponentException(); } teamA = a; teamB = b; RefA = r.ElementAt(0); }
//check whether or not a team has played in this round public Boolean IsPlaying(TTeam.ITeam team) { Boolean flag = false; for (int i = 0; i < listMatches.Count; i++) { flag = flag || listMatches[i].IsPlaying(team); } return(flag); }
//returns a match played in the round by a specified team public TMatch.Match GetMatch(TTeam.ITeam team) { for (int i = 0; i < listMatches.Count; i++) { if (listMatches[i].IsPlaying(team)) { return(listMatches[i]); } } throw new TeamNotPlayingException(CreateCopy(), team); }
//those virtual methods will be defined in subclasses public virtual void SetResult(string stat, TTeam.ITeam winner) { if (winner == TeamA || winner == TeamB || winner == null) { this.winner = winner; } else { throw new WinnerIsNotPlayingException(CreateCopy()); } }
//check whether or not two teams are playing against each other public Boolean IsScheduled(TTeam.ITeam team1, TTeam.ITeam team2) { for (int i = 0; i < listMatches.Count; i++) { if (listMatches[i].IsPlaying(team1) && listMatches[i].IsPlaying(team2)) { return(true); } } return(false); }
//setting the result from the level of tournament. Used in early console versions public void SetResult(string stat, TTeam.ITeam winner, TTeam.ITeam loser) { for (int i = 0; i < rounds.Count; i++) { if (rounds[i].IsScheduled(winner, loser)) { rounds[i].SetResult(stat, winner); break; } } }
public static Match CreateMatch(TTeam.ITeam team1, TTeam.ITeam team2, List <TPerson.Referee> refs) { if (team1 is DodgeballTeam) { return(new TMatch.DodgeballMatch(team1, team2, refs)); } else if (team1 is TugOfWarTeam) { return(new TMatch.TugOfWarMatch(team1, team2, refs)); } else { return(new TMatch.VolleyballMatch(team1, team2, refs)); } }
public override void SetResult(string stat, TTeam.ITeam winner) { int playersEliminatedChange = 0, playersLeftChange = 0; if (this.Winner == winner) { playersLeftChange = winnerPlayersLeft; } else { if (this.Winner != null) { playersEliminatedChange = 6 - winnerPlayersLeft; } } //if stat is not a number parse will throw format exception try { winnerPlayersLeft = int.Parse(stat); if (winnerPlayersLeft <= 0) { winnerPlayersLeft = 0; throw new NegativePlayersNumberException(CreateCopy()); } if (winnerPlayersLeft > 6) { winnerPlayersLeft = 0; throw new TooHighPlayersLeftException(CreateCopy()); } } catch (FormatException) { throw new NotIntPlayersException(CreateCopy()); } winner.SetMatchResult(true, playersEliminatedChange != 0 || playersLeftChange != 0, (playersEliminatedChange != 0 || playersLeftChange != 0) && this.Winner == winner, (winnerPlayersLeft - playersLeftChange).ToString() + ", " + playersEliminatedChange.ToString()); if (winner == TeamA) { TeamB.SetMatchResult(false, playersEliminatedChange != 0 || playersLeftChange != 0, (playersEliminatedChange != 0 || playersLeftChange != 0) && this.Winner == TeamB, (-playersLeftChange).ToString() + ", " + (6 - winnerPlayersLeft - playersEliminatedChange).ToString()); } else { TeamA.SetMatchResult(false, playersEliminatedChange != 0 || playersLeftChange != 0, (playersEliminatedChange != 0 || playersLeftChange != 0) && this.Winner == TeamA, (-playersLeftChange).ToString() + ", " + (6 - winnerPlayersLeft - playersEliminatedChange).ToString()); } base.SetResult(stat, winner); }
//withdraw a team from the PlayOffs public void WithdrawTeam(TTeam.ITeam t) { if (rounds[0].GetMatch(t).Winner == t) { rounds[0].GetMatch(t).Walkover(t); if (rounds[0].IsFinished()) { if (rounds.Count == 2) { rounds.RemoveAt(1); } GenerateRound(new List <TTeam.ITeam> { rounds[0].ListMatches[0].Winner, rounds[0].ListMatches[1].Winner }, "final"); } } t.Withdraw(); }
//SetResult sets a result of a match played by a team public void SetResult(string stat, TTeam.ITeam winner) { if (!rounds[0].IsFinished()) { rounds[0].SetResult(stat, winner); } else { if (!rounds[1].IsFinished()) { rounds[1].SetResult(stat, winner); } else { throw new AlreadyFinishedException(CreateCopy(), GetWinner()); } } if (rounds[0].IsFinished() && !rounds[1].IsFinished()) { GenerateRound(new List <TTeam.ITeam> { rounds[0].ListMatches[0].Winner, rounds[0].ListMatches[1].Winner }, "final"); } }
internal void SetResult(string stat, TTeam.ITeam winner) { GetMatch(winner).SetResult(stat, winner); }
public DuplicateTeamException(TTeam.ITeam team) { this.team = team; }
public TeamNotPlayingException(TRound.Round round, TTeam.ITeam team) : base(round) { this.team = team; }
public void RemoveTeam(TTeam.ITeam team) { IsObjectNotDefined(team, "Iteam"); teams.Remove(team); }
public AlreadyPlayingInRoundException(TRound.Round round, TMatch.Match match, TTeam.ITeam team) : base(round) { this.match = match; this.team = team; }
public void AddTeam(TTeam.ITeam team = null) { IsObjectNotDefined(team, "ITeam"); teams.Add(team); }
public WrongWinnerException(TMatch.Match match, TTeam.ITeam winner) : base(match) { supposedWinner = winner; }
public ThirdSetException(TMatch.Match match, TTeam.ITeam winner) : base(match) { this.winner = winner; }
//the expected format is "team1.Name: scoreInSet1, scoreInSet2, scoreInSet3(0 if not played). team2.Name: scoreInSet1, scoreInSet2, scoreInSet3(0 if not played)" public override void SetResult(string stat, TTeam.ITeam winner) { int resultCheck = 0, scoreDiff = 0; int earlierScoreDiff = 0, earlierPoints = 0; if (WasPlayed()) { for (int i = 0; i < 3; i++) { earlierScoreDiff += scoreTeamA[i] - scoreTeamB[i]; if (scoreTeamA[i] > scoreTeamB[i]) { earlierPoints++; } if (scoreTeamA[i] < scoreTeamB[i]) { earlierPoints--; } } if (earlierPoints > 0) { earlierPoints++; } else { earlierPoints += 2; } } //split the strings into strings containing name of the teams and their scores string[] tmp = stat.Split(new string[] { ". ", ", ", ": " }, StringSplitOptions.RemoveEmptyEntries); //string should split into 8 smaller string (2 for names of teams, 6 in total for scores in sets) if (tmp.Length != 8) { throw new WrongStatFormatException(CreateCopy()); } for (int i = 0; i < 3; i++) { int scoreRequired; if (i != 2) { scoreRequired = 21; } else { scoreRequired = 15; } try { if (tmp[0].Equals(TeamA.Name) && tmp[4].Equals(TeamB.Name)) { scoreTeamA[i] = int.Parse(tmp[i + 1]); scoreTeamB[i] = int.Parse(tmp[i + 5]); } else { if (tmp[0].Equals(TeamB.Name) && tmp[4].Equals(TeamA.Name)) { scoreTeamB[i] = int.Parse(tmp[i + 1]); scoreTeamA[i] = int.Parse(tmp[i + 5]); } else { if (TeamA.Name.Equals(tmp[0]) || TeamB.Name.Equals(tmp[0])) { Console.WriteLine(TeamA.Name + " " + TeamB.Name); throw new WrongNameInStatException(CreateCopy(), tmp[4]); } else { ToString(); throw new WrongNameInStatException(CreateCopy(), tmp[0]); } } } //score should be equal or higher than 0, but equal or lower than 21 in first two sets //and equal or lower than 15 in the third set if (scoreTeamA[i] < 0 || scoreTeamB[i] < 0) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new NegativeScoreException(CreateCopy()); } if (scoreTeamA[i] > scoreRequired || scoreTeamB[i] > scoreRequired) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new TooHighScoreException(CreateCopy()); } } catch (FormatException) { throw new NonIntScoreException(CreateCopy()); } //Checking whether the score makes sense and reflects the winner //if a team has won in 2 sets third one should end 0:0 if (Math.Abs(resultCheck) == 2) { if (scoreTeamA[i] != 0 || scoreTeamB[i] != 0) { if (resultCheck > 0) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new ThirdSetException(CreateCopy(), TeamA); } else { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new ThirdSetException(CreateCopy(), TeamB); } } } //Checking if exactly one team has reached the required points else { if (scoreTeamA[i] == scoreTeamB[i] || (scoreTeamA[i] < scoreRequired && scoreTeamB[i] < scoreRequired)) { throw new NoSetWinnerException(CreateCopy(), i + 1); } if (scoreTeamA[i] == scoreRequired) { resultCheck++; } if (scoreTeamB[i] == scoreRequired) { resultCheck--; } scoreDiff += scoreTeamA[i] - scoreTeamB[i]; } } //checking if a team which should have won by what the stat indicates was set as a winner if ((resultCheck > 0 && TeamA != winner) || (resultCheck < 0 && TeamB != winner)) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new WrongWinnerException(CreateCopy(), winner); } int temp = 0; if (WasPlayed()) { temp = 3 - earlierPoints; } if (winner == TeamA) { TeamA.SetMatchResult(true, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamA, (1 + Math.Abs(resultCheck) - earlierPoints).ToString() + ", " + (scoreDiff - earlierScoreDiff).ToString()); TeamB.SetMatchResult(false, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamB, (2 - Math.Abs(resultCheck) - temp).ToString() + ", " + (earlierScoreDiff - scoreDiff).ToString()); } else { TeamA.SetMatchResult(false, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamA, (2 - Math.Abs(resultCheck) - temp).ToString() + ", " + (earlierScoreDiff - scoreDiff).ToString()); TeamB.SetMatchResult(true, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamB, (1 + Math.Abs(resultCheck) - earlierPoints).ToString() + ", " + (scoreDiff - earlierScoreDiff).ToString()); } base.SetResult(stat, winner); }
public NotEnoughTeamsLeftNumber(TRound.League league, TTeam.ITeam team) : base(league) { this.team = team; }
//It's just a basic try, can be changed if needed public bool IsPlaying(TTeam.ITeam team) { return(team == TeamA || team == TeamB); }
public DodgeballMatch(TTeam.ITeam a, TTeam.ITeam b, List <TPerson.Referee> r) : base(a, b, r) { }
//constructor uses a constructor of its superclass public TugOfWarMatch(TTeam.ITeam a, TTeam.ITeam b, List <TPerson.Referee> r) : base(a, b, r) { }
//Main constructor public VolleyballMatch(TTeam.ITeam a, TTeam.ITeam b, List <TPerson.Referee> r) : base(a, b, r) { SetReferees(r); }
public AlreadyFinishedException(TRound.PlayOff playoff, TTeam.ITeam winner) : base(playoff) { this.winner = winner; }