Esempio n. 1
0
        /// <summary>
        /// Add a new point to this set
        /// </summary>
        /// <param name="newPoint"></param>
        public void Add(TennisPoint newPoint)
        {
            //Update statistics
            Statistics.Add(newPoint);

            //Start new game if necessary
            if (currentGame() != null)
            {
                if (currentGame().State == TennisGame.StateEnum.sFinished)
                {
                    StartNewGame();
                }
            }
            else
            {
                StartNewGame();
            }

            //Add this new point to the game
            if (currentGame().GetType() == typeof(TennisTiebreak))
            {
                TennisTiebreak currentTiebreak = (TennisTiebreak)currentGame();
                currentTiebreak.Add(newPoint);
            }
            else
            {
                currentGame().Add(newPoint);
            }


            //Check the score if the game is finished
            if (currentGame().State == TennisGame.StateEnum.sFinished)
            {
                RebuildScore();

                //Check if there is a winner for this set
                int GamesPerSet = PartOf.NumberGamesPerSet;

                if ((ScoreContestant1 >= GamesPerSet && ScoreContestant2 < ScoreContestant1 - 1) ||
                    (ScoreContestant2 >= GamesPerSet && ScoreContestant1 < ScoreContestant2 - 1) ||
                    (currentGame().GetType() == typeof(TennisTiebreak)))
                {
                    Duration.End();
                    Winner = currentGame().Winner;
                }

                if (Winner == 0)
                {
                    StartNewGame();
                }
            }
        }
        public TennisPoint Undo()
        {
            if (Points.Count == 0)
            {
                return(null);                           // can't undo.
            }
            TennisPoint PointUndone = Points.Last();

            Points.Remove(PointUndone);
            State  = StateEnum.sProgress;
            Winner = 0;

            RebuildScore();

            return(PointUndone);
        }
        public void ReadXmlBase(System.Xml.XmlReader reader, String Node)
        {
            String _ID             = reader.GetAttribute("ID");
            String _Winner         = reader.GetAttribute("Winner");
            String _Server         = reader.GetAttribute("Server");
            String _Receiver       = reader.GetAttribute("Receiver");
            String _PointsServer   = reader.GetAttribute("PointsServer");
            String _PointsReceiver = reader.GetAttribute("PointsReceiver");
            String _ScoreServer    = reader.GetAttribute("ScoreServer");
            String _ScoreReceiver  = reader.GetAttribute("ScoreReceiver");
            String _State          = reader.GetAttribute("State");
            String _StartTime      = reader.GetAttribute("StartTime");
            String _EndTime        = reader.GetAttribute("EndTime");
            String _PointsPerGame  = reader.GetAttribute("PointsPerGame");

            ID             = long.Parse(_ID);
            Winner         = int.Parse(_Winner);
            Server         = int.Parse(_Server);
            Receiver       = int.Parse(_Receiver);
            PointsServer   = int.Parse(_PointsServer);
            PointsReceiver = int.Parse(_PointsReceiver);
            ScoreServer    = (ScoreEnum)System.Enum.Parse(typeof(ScoreEnum), _ScoreServer);
            ScoreReceiver  = (ScoreEnum)System.Enum.Parse(typeof(ScoreEnum), _ScoreReceiver);
            State          = (StateEnum)System.Enum.Parse(typeof(StateEnum), _State);
            StartTime      = DateTime.Parse(_StartTime);
            if (_EndTime != null)
            {
                EndTime = DateTime.Parse(_EndTime);
            }
            PointsPerGame = int.Parse(_PointsPerGame);

            //Process points
            while (reader.Read() && !(reader.Name == Node && reader.NodeType == System.Xml.XmlNodeType.EndElement))
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    if (reader.Name == "Point")
                    {
                        TennisPoint _newPoint = new TennisPoint();
                        _newPoint.PartOf = this;
                        _newPoint.ReadXml(reader);

                        Points.Add(_newPoint);
                    }
                }
            }
        }
        public Boolean Add(TennisPoint newPoint)
        {
            if (State != StateEnum.sProgress)
            {
                throw new Exception("This game is not in progress");
            }

            Points.Add(newPoint);

            if (newPoint.Winner == Server)
            {
                PointsServer++;
                if (PointsServer >= PointsPerGame && PointsServer > PointsReceiver + 1)
                {
                    End(Server);
                }
                if (PointsServer >= PointsPerGame && this.PartOf.PartOf.DeuceSuddenDeath)
                {
                    End(Server);
                }
            }
            else
            {
                PointsReceiver++;
                if (PointsReceiver >= PointsPerGame && PointsReceiver > PointsServer + 1)
                {
                    End(Receiver);
                }
                if (PointsReceiver >= PointsPerGame && this.PartOf.PartOf.DeuceSuddenDeath)
                {
                    End(Receiver);
                }
            }

            if (PointsServer == PointsPerGame && PointsReceiver == PointsPerGame)         //Return to deuce.
            {
                PointsServer--;
                PointsReceiver--;
            }


            ScoreServer   = ConvertScore(PointsServer);
            ScoreReceiver = ConvertScore(PointsReceiver);

            return(true);
        }
Esempio n. 5
0
        public Boolean Add(TennisPoint newPoint)
        {
            if (State != StateEnum.sProgress)
            {
                throw new Exception("This game is not in progress");
            }

            Points.Add(newPoint);

            RebuildScore();

            if ((PointsServer >= PointsPerGame && PointsReceiver < PointsServer - 1) ||
                (PointsReceiver >= PointsPerGame && PointsServer < PointsReceiver - 1))
            {
                End(PointsServer > PointsReceiver ? startServer : startReceiver);
            }

            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Undo the last point
        /// </summary>
        public void Undo()
        {
            //If game is abnormally ended, reset the status
            if (Status == MatchStatus.Terminated || Status == MatchStatus.Resigned)
            {
                Winner = 0;
                Duration.Start(); // start a new session
                Status = MatchStatus.InProgress;
            }
            else
            {
                //If no points have been played, ignore
                if (Points.Count == 0)
                {
                    return;
                }

                //Remove the last point
                TennisPoint point = Points.Last();
                Points.Remove(point);

                //Remove the points from the statistics
                Statistics.Remove(point);

                //If there was a winner, reset the status
                if (Winner != 0)
                {
                    Winner = 0;
                    Duration.Start();
                    Status = MatchStatus.InProgress;
                }

                while (!currentSet().Undo())
                {
                    Sets.Remove(currentSet());
                }
            }


            //Make sure the next server is properly set. It is unknown if the current game has changed
            //so we set this every time.
            NextContestantToServe = currentGame().Server == 1 ? Contestant1 : Contestant2;
        }
Esempio n. 7
0
        /// <summary>
        /// Create a new point / rally instance
        /// </summary>
        /// <returns></returns>
        public TennisPoint CreateNewPoint()
        {
            TennisPoint newPoint = null;

            if (Winner == 0)
            {
                newPoint        = new TennisPoint();
                newPoint.PartOf = currentGame();
                newPoint.Server = currentGame().Server;

                if (currentGame().BreakPoint())
                {
                    newPoint.Type.Add(TennisPoint.PointType.BreakPoint);
                }
                if (currentGame().GamePoint())
                {
                    newPoint.Type.Add(TennisPoint.PointType.GamePoint);
                }
                if (CheckSetPoint() != 0)
                {
                    newPoint.Type.Add(TennisPoint.PointType.SetPoint);
                    if (currentGame().GamePoint())
                    {
                        newPoint.Type.Add(TennisPoint.PointType.SetPointServer);
                    }
                }
                if (CheckMatchPoint() != 0)
                {
                    newPoint.Type.Add(TennisPoint.PointType.MatchPoint);
                    if (currentGame().GamePoint())
                    {
                        newPoint.Type.Add(TennisPoint.PointType.MatchPointServer);
                    }
                }
            }

            return(newPoint);
        }
Esempio n. 8
0
        /// <summary>
        /// Add the given point to this match
        /// </summary>
        /// <param name="newPoint"></param>
        public void Add(TennisPoint newPoint)
        {
            if (Winner != 0)
            {
                return;
            }
            if (currentSet() == null)
            {
                StartNewSet();
            }

            newPoint.PartOf = currentGame();
            Points.Add(newPoint);

            currentSet().Add(newPoint);

            //Update statistics
            Statistics.Add(newPoint);

            if (currentSet().Winner != 0)
            {
                //the set is finished. Is the match finished?
                int NumberOfSetsToWin = (BestOutOf / 2) + 1;

                GetContestant(currentSet().Winner).SetsWon++;

                if (GetContestant(currentSet().Winner).SetsWon == NumberOfSetsToWin)
                {
                    Winner = currentSet().Winner;
                    End(MatchStatus.Completed);
                }
                else
                {
                    StartNewSet();
                }
            }
        }
        private void ProcessPoint(TennisPoint point, int Server, int Returner, int Delta)
        {
            //Total Points
            IncrementItem(Statistics.TotalPoints, Server, Delta);
            IncrementItem(Statistics.TotalPoints, Returner, Delta);
            IncrementItem(Statistics.TotalPointsWon, point.Winner, Delta);

            //Service and Return Points
            IncrementItem(Statistics.TotalServicePoints, Server, Delta);
            IncrementItem(Statistics.TotalReturnPoints, Returner, Delta);

            if (point.Winner == Server)
            {
                IncrementItem(Statistics.TotalServicePointsWon, Server, Delta);
            }
            else
            {
                IncrementItem(Statistics.TotalReturnPointsWon, Returner, Delta);
            }

            //First services and return points
            if (point.Serve == TennisPoint.PointServe.FirstServe)
            {
                IncrementItem(Statistics.FirstServicesPlayed, Server, Delta);
                IncrementItem(Statistics.FirstReturnPlayed, Returner, Delta);
                if (point.Winner == Server)
                {
                    IncrementItem(Statistics.FirstServicesWon, Server, Delta);
                }
                else
                {
                    IncrementItem(Statistics.FirstReturnWon, Returner, Delta);
                }
            }

            //Second services and return points
            if (point.Serve == TennisPoint.PointServe.SecondServe)
            {
                IncrementItem(Statistics.SecondServicesPlayed, Server, Delta);
                IncrementItem(Statistics.SecondReturnPlayed, Returner, Delta);
                if (point.Winner == Server)
                {
                    IncrementItem(Statistics.SecondServicesWon, Server, Delta);
                }
                else
                {
                    IncrementItem(Statistics.SecondReturnWon, Returner, Delta);
                }
            }

            //Aces and Double Faults
            if (point.Shot.Contains(TennisPoint.PointShot.Ace))
            {
                IncrementItem(Statistics.Aces, Server, Delta);
            }
            if (point.Error == TennisPoint.PointError.DoubleFault)
            {
                IncrementItem(Statistics.DoubleFaults, Server, Delta);
            }

            //Break points
            if (point.Type.Contains(TennisPoint.PointType.BreakPoint))
            {
                IncrementItem(Statistics.ServiceBreakPointsPlayed, Server, Delta);
                IncrementItem(Statistics.ReturnBreakPointsPlayed, Returner, Delta);
                if (point.Winner == Server)
                {
                    IncrementItem(Statistics.ServiceBreakPointsWon, Server, Delta);
                }
                else
                {
                    IncrementItem(Statistics.ReturnBreakPointsWon, Returner, Delta);
                }
            }

            //Set points
            if (point.Type.Contains(TennisPoint.PointType.SetPoint))
            {
                if (point.Type.Contains(TennisPoint.PointType.SetPointServer))
                {
                    IncrementItem(Statistics.ServiceSetPointsPlayed, Server, Delta);
                    if (point.Winner == Server)
                    {
                        IncrementItem(Statistics.ServiceSetPointsConverted, Server, Delta);
                    }
                }

                if (!point.Type.Contains(TennisPoint.PointType.SetPointServer))
                {
                    IncrementItem(Statistics.ReturnSetPointsPlayed, Returner, Delta);
                    if (point.Winner == Returner)
                    {
                        IncrementItem(Statistics.ReturnSetPointsConverted, Returner, Delta);
                    }
                }
            }

            //Match points
            if (point.Type.Contains(TennisPoint.PointType.MatchPoint))
            {
                if (point.Type.Contains(TennisPoint.PointType.MatchPointServer))
                {
                    IncrementItem(Statistics.ServiceMatchPointsPlayed, Server, Delta);
                    if (point.Winner == Server)
                    {
                        IncrementItem(Statistics.ServiceMatchPointsConverted, Server, Delta);
                    }
                }

                if (!point.Type.Contains(TennisPoint.PointType.MatchPointServer))
                {
                    IncrementItem(Statistics.ReturnMatchPointsPlayed, Returner, Delta);
                    if (point.Winner == Returner)
                    {
                        IncrementItem(Statistics.ReturnMatchPointsConverted, Returner, Delta);
                    }
                }
            }

            //Shots
            if (point.ResultType == TennisPoint.PointResultType.Winner)
            {
                IncrementItem(Statistics.PointWinners, point.Winner, Delta);
                foreach (TennisPoint.PointShot _shot in point.Shot)
                {
                    switch (_shot)
                    {
                    case TennisPoint.PointShot.Forehand:
                        IncrementItem(Statistics.ForehandWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Backhand:
                        IncrementItem(Statistics.BackhandWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Volley:
                        IncrementItem(Statistics.VolleyWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.OverheadShot:
                        IncrementItem(Statistics.OverheadWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Dropshot:
                        IncrementItem(Statistics.DropshotWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Passing:
                        IncrementItem(Statistics.PassingWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Lob:
                        IncrementItem(Statistics.LobWinner, point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.ApproachShot:
                        IncrementItem(Statistics.ApproachShotWinner, point.Winner, Delta);
                        break;

                    default:
                        break;
                    }
                }
            }
            if (point.ResultType == TennisPoint.PointResultType.ForcedError)
            {
                IncrementItem(Statistics.PointForcedErrors, 3 - point.Winner, Delta);
                foreach (TennisPoint.PointShot _shot in point.Shot)
                {
                    switch (_shot)
                    {
                    case TennisPoint.PointShot.Forehand:
                        IncrementItem(Statistics.ForehandForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Backhand:
                        IncrementItem(Statistics.BackhandForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Volley:
                        IncrementItem(Statistics.VolleyForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.OverheadShot:
                        IncrementItem(Statistics.OverheadForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Dropshot:
                        IncrementItem(Statistics.DropshotForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Passing:
                        IncrementItem(Statistics.PassingForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Lob:
                        IncrementItem(Statistics.LobForcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.ApproachShot:
                        IncrementItem(Statistics.ApproachShotForcedError, 3 - point.Winner, Delta);
                        break;

                    default:
                        break;
                    }
                }
            }
            if (point.ResultType == TennisPoint.PointResultType.UnforcedError)
            {
                IncrementItem(Statistics.PointUnforcedErrors, 3 - point.Winner, Delta);
                foreach (TennisPoint.PointShot _shot in point.Shot)
                {
                    switch (_shot)
                    {
                    case TennisPoint.PointShot.Forehand:
                        IncrementItem(Statistics.ForehandUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Backhand:
                        IncrementItem(Statistics.BackhandUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Volley:
                        IncrementItem(Statistics.VolleyUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.OverheadShot:
                        IncrementItem(Statistics.OverheadUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Dropshot:
                        IncrementItem(Statistics.DropshotUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Passing:
                        IncrementItem(Statistics.PassingUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.Lob:
                        IncrementItem(Statistics.LobUnforcedError, 3 - point.Winner, Delta);
                        break;

                    case TennisPoint.PointShot.ApproachShot:
                        IncrementItem(Statistics.ApproachShotUnforcedError, 3 - point.Winner, Delta);
                        break;

                    default:
                        break;
                    }
                }
            }

            //Number of games
            if (point.Type.Contains(TennisPoint.PointType.GamePoint) && point.Winner == point.Server)
            {
                IncrementItem(Statistics.ServiceGamesWon, point.Server, Delta);
                IncrementItem(Statistics.ServiceGamesPlayed, point.Server, Delta);
                IncrementItem(Statistics.ReturnGamesPlayed, 3 - point.Server, Delta);
            }
            if (point.Type.Contains(TennisPoint.PointType.BreakPoint) && point.Winner != point.Server)
            {
                IncrementItem(Statistics.ServiceGamesPlayed, point.Server, Delta);
                IncrementItem(Statistics.ReturnGamesWon, 3 - point.Server, Delta);
                IncrementItem(Statistics.ReturnGamesPlayed, 3 - point.Server, Delta);
            }
        }
 public void Remove(TennisPoint newPoint)
 {
     ProcessPoint(newPoint, newPoint.Server, 3 - newPoint.Server, -1);
 }
 public void Add(TennisPoint newPoint)
 {
     ProcessPoint(newPoint, newPoint.Server, 3 - newPoint.Server, 1);
     AddDuration();
 }