Esempio n. 1
0
        /// <summary>
        /// Start a new game or tiebreak if applicable
        /// </summary>
        public void StartNewGame()
        {
            //Check if another game is in progress
            if (this.currentGame() != null)
            {
                if (currentGame().State != TennisGame.StateEnum.sFinished)
                {
                    throw new Exception("Another game is already in progress");
                }
            }

            TennisGame newGame;

            if (ScoreContestant1 == ScoreContestant2 &&
                ScoreContestant1 == PartOf.TieBreakAtSameScoreOf &&
                (PartOf.TieBreakFinalSet || PartOf.Sets.Count != PartOf.BestOutOf)
                )
            {
                //The set has entered a tiebreak
                TennisTiebreak newTiebreak = new TennisTiebreak();
                newTiebreak.SetStartServer(StartServer);

                newGame               = newTiebreak;
                newGame.PartOf        = this;
                newGame.PointsPerGame = PartOf.TieBreakLength;
            }
            else
            {
                if (this.PartOf.Sets.Count == this.PartOf.BestOutOf && this.PartOf.Sets.Count > 1 && this.PartOf.FinalSetIsTiebreak)
                {
                    //The final set has started, and it is a tiebreak
                    TennisTiebreak newTiebreak = new TennisTiebreak();
                    newTiebreak.SetStartServer(StartServer);

                    newGame               = newTiebreak;
                    newGame.PartOf        = this;
                    newGame.PointsPerGame = this.PartOf.FinalSetTieBreakLength;
                }
                else
                {
                    //Start new regular game
                    newGame        = new TennisGame();
                    newGame.PartOf = this;
                }
            }

            if (Games.Count > 0)
            {
                newGame.Server = PartOf.GetNextServer().ContestantNr;
            }
            else
            {
                newGame.Server = StartServer;
            }
            newGame.Receiver = PartOf.GetReceiver().ContestantNr;
            newGame.Start();

            Games.Add(newGame);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <summary>
        /// Check if the set is on match point and if so return the number of the player who has it
        /// </summary>
        /// <returns></returns>
        private int CheckSetPoint()
        {
            TennisGame currentGame   = this.currentGame();
            int        ScoreServer   = 0;
            int        ScoreReceiver = 0;

            if (currentGame.Server == 1)
            {
                ScoreServer   = currentSet().ScoreContestant1;
                ScoreReceiver = currentSet().ScoreContestant2;
            }
            else
            {
                ScoreReceiver = currentSet().ScoreContestant1;
                ScoreServer   = currentSet().ScoreContestant2;
            }

            //Regular game
            if (currentGame.GetType() != typeof(TennisTiebreak))
            {
                if (ScoreServer >= NumberGamesPerSet - 1 && ScoreReceiver < ScoreServer && currentGame.GamePoint())
                {
                    return(currentGame.Server);
                }
                if (ScoreReceiver >= NumberGamesPerSet - 1 && ScoreServer < ScoreReceiver && currentGame.BreakPoint())
                {
                    return(3 - currentGame.Server);
                }
            }
            else
            {
                //Tiebreak
                TennisTiebreak Tiebreak = (TennisTiebreak)currentGame;

                return(Tiebreak.SetPoint());
            }

            return(0);
        }
Esempio n. 4
0
        /// <summary>
        /// Generates a match object from its XML representation.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.Name != "Set")
            {
                throw new Exception("Unexpected node encountered, Set expected");
            }

            String _ID               = reader.GetAttribute("ID");
            String _Winner           = reader.GetAttribute("Winner");
            String _StartServer      = reader.GetAttribute("StartServer");
            String _ScoreContestant1 = reader.GetAttribute("ScoreContestant1");
            String _ScoreContestant2 = reader.GetAttribute("ScoreContestant2");

            ID               = long.Parse(_ID);
            Winner           = int.Parse(_Winner);
            StartServer      = int.Parse(_StartServer);
            ScoreContestant1 = int.Parse(_ScoreContestant1);
            ScoreContestant2 = int.Parse(_ScoreContestant2);

            while (reader.Read() && !(reader.Name == "Set" && reader.NodeType == System.Xml.XmlNodeType.EndElement))
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Games":

                        while (reader.Read() && !(reader.Name == "Games" && reader.NodeType == System.Xml.XmlNodeType.EndElement))
                        {
                            if (reader.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                switch (reader.Name)
                                {
                                case "Game":

                                    TennisGame newGame = new TennisGame();
                                    newGame.PartOf = this;
                                    newGame.ReadXml(reader);
                                    this.PartOf.Points.AddRange(newGame.Points);

                                    this.Games.Add(newGame);

                                    break;

                                case "Tiebreak":

                                    TennisTiebreak newTiebreak = new TennisTiebreak();
                                    newTiebreak.ReadXml(reader);
                                    newTiebreak.PartOf = this;
                                    this.PartOf.Points.AddRange(newTiebreak.Points);

                                    this.Games.Add(newTiebreak);

                                    break;
                                }
                            }
                        }

                        break;

                    case "Statistics":

                        Statistics.ReadXml(reader);

                        break;

                    case "Duration":

                        Duration.ReadXml(reader);

                        break;
                    }
                }
            }
        }