Ejemplo n.º 1
0
            //this method is required for saving results in files
            public void SetResult(int[] scoreA, int[] scoreB)
            {
                scoreTeamA = scoreA;
                scoreTeamB = scoreB;
                int resultCheck = 0, scoreDiff = 0;

                for (int i = 0; i < 3; i++)
                {
                    if (scoreA[i] > scoreB[i])
                    {
                        resultCheck++;
                    }
                    else if (scoreTeamA[i] < scoreTeamB[i])
                    {
                        resultCheck--;
                    }
                    scoreDiff = scoreTeamA[i] - scoreTeamB[i];
                }
                if (Winner == TeamA)
                {
                    TeamA.SetMatchResult(true, false, false, (1 + Math.Abs(resultCheck)).ToString() + ", " + (scoreDiff).ToString());
                    TeamB.SetMatchResult(false, false, false, (2 - Math.Abs(resultCheck)).ToString() + ", " + (-scoreDiff).ToString());
                }
                if (Winner == TeamB)
                {
                    TeamA.SetMatchResult(false, false, false, (2 - Math.Abs(resultCheck)).ToString() + ", " + (-scoreDiff).ToString());
                    TeamB.SetMatchResult(true, false, false, (1 + Math.Abs(resultCheck)).ToString() + ", " + (scoreDiff).ToString());
                }
            }
Ejemplo n.º 2
0
            //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);
            }
Ejemplo n.º 3
0
 public void SetResult(float matchLength)
 {
     this.matchLength = matchLength;
     if (Winner != null)
     {
         TeamA.SetMatchResult(TeamA == Winner, false, false, matchLength + " - " + 0.ToString());
         TeamB.SetMatchResult(TeamB == Winner, false, false, matchLength + " - " + 0.ToString());
     }
 }
Ejemplo n.º 4
0
 public void SetResult(int wPlayersLeft)
 {
     winnerPlayersLeft = wPlayersLeft;
     if (Winner == TeamA)
     {
         TeamA.SetMatchResult(TeamA == Winner, false, false, winnerPlayersLeft + ", " + 6);
         TeamB.SetMatchResult(TeamB == Winner, false, false, 0 + ", " + (6 - winnerPlayersLeft));
     }
     if (Winner == TeamB)
     {
         TeamB.SetMatchResult(TeamB == Winner, false, false, winnerPlayersLeft + ", " + 6);
         TeamA.SetMatchResult(TeamA == Winner, false, false, 0 + ", " + (6 - winnerPlayersLeft));
     }
 }
Ejemplo n.º 5
0
            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);
            }
Ejemplo n.º 6
0
            //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);
            }