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
        /// <summary>
        /// Switch the server to start serving the match. Default is Contestant 1
        /// </summary>
        public void SwitchServer()
        {
            if (Points.Count > 0)
            {
                throw new Exception("Can't switch server when the match has started.");
            }

            TennisContestant newServer = GetNextServer();

            currentSet().StartServer = newServer.ContestantNr;
            currentGame().Server     = newServer.ContestantNr;
            currentGame().Receiver   = 3 - currentGame().Server;
            if (currentGame().GetType() == typeof(TennisTiebreak))
            {
                TennisTiebreak _tiebreak = (TennisTiebreak)currentGame();
                _tiebreak.SetStartServer(newServer.ContestantNr);
            }
        }