示例#1
0
        /// <summary>
        /// Set the match source of this collection
        /// </summary>
        /// <param name="Match"></param>
        public void SetSource(TennisMatch Match)
        {
            Children.Clear();

            if (Match != null)
            {
                vmStatistics newStatistics = new vmStatistics("Match", Match.Statistics, this);
                newStatistics.Selected += newStatistics_Selected;

                Children.Add(newStatistics);

                Match.NewSet += Match_NewSet;

                int i = 1;

                foreach (TennisSet Set in Match.Sets)
                {
                    newStatistics           = new vmStatistics(String.Format("Set {0}", i), Set.Statistics, this);
                    newStatistics.Selected += newStatistics_Selected;

                    Children.Add(newStatistics);

                    i++;
                }

                Selected = this.Children[0];
            }
        }
        public async Task Format_WhenCompletedTwoSets_WithIncompletedSet_ExpectIncompletedGameWithScores()
        {
            _sut = new SetSetScoreFormatter('B', 'A');

            var sets = new List <TennisSet>
            {
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'A', 40, 0),

                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(false, ' ', 0, 15)
            };
            var tennisMatch = new TennisMatch(sets);

            var result = await _sut.Format(tennisMatch);

            result.Should().Be("3-6 6-4 0-0 0-15");
        }
示例#3
0
        /// <summary>
        /// Load the requested file/match
        /// </summary>
        /// <returns></returns>
        public async Task Load(String Filename)
        {
            try
            {
                //Load the data
                String XML = await Helpers.LocalStorage.Load(Filename);

                //CompressedXML = "";
                //Deserialize
                TennisMatch StoredMatch = (TennisMatch)Helpers.Serializer.XMLDeserialize(XML, typeof(TennisMatch));

                //Restore references

                //Set it as the current match
                Match = StoredMatch;
                StatisticsCollection.SetSource(_Match);
            }
            catch (Exception)
            {
                ExtendedEventArgs eea = new ExtendedEventArgs();
                eea.Error = "An error occured while loading the stored match";
                OnFatalError(eea);
                //throw new Exception();
            }
        }
        public async Task Format_WhenCompletedOneSet_7to5_WithCompletedSet_ExpectCompletedGameWithScores()
        {
            _sut = new SetSetScoreFormatter('A', 'B');

            var sets = new List <TennisSet>
            {
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'B', 40, 0),
                new TennisSet(true, 'A', 40, 0),
                new TennisSet(true, 'A', 40, 0)
            };
            var tennisMatch = new TennisMatch(sets);

            var result = await _sut.Format(tennisMatch);

            result.Should().Be("7-5 0-0");
        }
示例#5
0
        public void IsOver_Player1Has6WinGamesAndHasA1WinGamesOfDifferenceWithPlayer2_False()
        {
            var match = new TennisMatch();

            match.Player1.NumberOfWinGames = 6;
            match.Player2.NumberOfWinGames = 5;
            Assert.IsFalse(match.IsOver());
        }
示例#6
0
        public void IsOver_Player1Has7WinGamesAndHasAMinimumOf2GamesOfDifferenceWithPlayer2_True()
        {
            var match = new TennisMatch();

            match.Player1.NumberOfWinGames = 7;
            match.Player2.NumberOfWinGames = 5;
            Assert.IsTrue(match.IsOver());
        }
示例#7
0
        public void SetUp()
        {
            _serviceFactory = new Mock <ITennisServiceFactory>();
            _setService     = new Mock <TennisSet>(_serviceFactory.Object);

            _sut = new TennisMatch(_serviceFactory.Object);

            _serviceFactory.Setup(x => x.GetSetService()).Returns(_setService.Object);
        }
        public async Task Format_WhenNoMatches_Expect0_0()
        {
            _sut = new SetSetScoreFormatter('A', 'B');

            var tennisMatch = new TennisMatch(new List <TennisSet>());

            var result = await _sut.Format(tennisMatch);

            result.Should().Be("0-0");
        }
示例#9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Super Tennis Game 3000!");

            var tennisMatch = new TennisMatch();

            tennisMatch.Play();

            if (tennisMatch.TryGetWinner(out Player winnerOfTheMatch))
            {
                Console.WriteLine();
                Console.WriteLine($">>>>> {winnerOfTheMatch.Name} wins the match!!!!!");
            }
        }
        public async Task Format_WhenDeuce_AdvantageB_ExpectDeuce()
        {
            _sut = new SetSetScoreFormatter('A', 'B');

            var sets = new List <TennisSet>
            {
                new TennisSet(false, ' ', 40, 40, 'B')
            };
            var tennisMatch = new TennisMatch(sets);

            var result = await _sut.Format(tennisMatch);

            result.Should().Be("0-0 40-A");
        }
        public async Task Format_WhenCompleteGame_AndBWins_ExpectCompletedGameOnly()
        {
            _sut = new SetSetScoreFormatter('B', 'A');

            var sets = new List <TennisSet>
            {
                new TennisSet(true, 'B', 40, 0)
            };
            var tennisMatch = new TennisMatch(sets);

            var result = await _sut.Format(tennisMatch);

            result.Should().Be("1-0");
        }
        public async Task Format_WhenIncompleteGame_ExpectCompletedGames_CurrentScore()
        {
            _sut = new SetSetScoreFormatter('A', 'B');

            var sets = new List <TennisSet>
            {
                new TennisSet(false, ' ', 15, 0)
            };
            var tennisMatch = new TennisMatch(sets);

            var result = await _sut.Format(tennisMatch);

            result.Should().Be("0-0 15-0");
        }
        public Task <string> Format(TennisMatch matches)
        {
            var result = "0-0";

            if (matches.Sets.Count > 0)
            {
                var items = new List <string>
                {
                    CalculateCompletedGames(matches.Sets),
                    CalculateGameScores(matches.Sets)
                };

                result = string.Join(" ", items.Where(i => !string.IsNullOrWhiteSpace(i)));
            }

            return(Task.FromResult(result));
        }
示例#14
0
        public async Task <TennisMatch> Calculate(TennisGame game)
        {
            var tennisMatch = new TennisMatch(new List <TennisSet>());

            bool completed = false;

            while (!completed)
            {
                var setResult = await _setCalculator.Calculate(game);

                tennisMatch.Sets.Add(setResult.Set);
                game = setResult.Remaining;

                if (!setResult.Remaining.Points.Any())
                {
                    completed = true;
                }
            }

            return(tennisMatch);
        }
示例#15
0
        public void GetData(TennisMatch Match)
        {
            ID          = Match.ID;
            StartTime   = Match.Duration.FirstSession;
            Duration    = Match.Duration.Duration;
            Winner      = Match.Winner;
            Status      = Match.Status;
            Contestant1 = Match.Contestant1.getName();
            Contestant2 = Match.Contestant2.getName();
            MatchType   = Match.Type.ToString() + " | best of " + Match.BestOutOf.ToString();
            MatchType   = MatchType.ToUpper();
            Location    = Match.Location;
            Surface     = Match.MatchSurface == TennisMatch.Surface.ArtificialGrass ? "Artificial grass" :  Match.MatchSurface.ToString();

            Sets.Clear();

            foreach (TennisSet Set in Match.Sets)
            {
                vmSetScore _sSet = new vmSetScore(Set);
                Sets.Add(_sSet);
            }
        }
示例#16
0
        private TennisMatch ParseMatchDetails(HtmlNode node, int id)
        {
            var tennisMatch = new TennisMatch();

            tennisMatch.Id = id;

            var timeAndTour = node.InnerText.Replace("\r", "").Replace("\n", "").Replace("\t", "");
            // pattern is: <time>(<tour>)
            var splitted = timeAndTour.Split('(');

            var tour = splitted[1].Replace(")", "");

            tennisMatch.Time = splitted[0];
            tennisMatch.Tour = DecodeValue(tour);

            var playersElement = GetPlayersForMatchElement(node);
            var playersNames   = playersElement.InnerHtml.Replace("<br>", " - ");

            tennisMatch.Players = DecodeValue(playersNames);

            return(tennisMatch);
        }
示例#17
0
        public void IsOver_BothPlayersHaveNoWinGames_False()
        {
            var match = new TennisMatch();

            Assert.IsFalse(match.IsOver());
        }
示例#18
0
 public vmStoredMatch(TennisMatch Match)
 {
     GetData(Match);
 }
示例#19
0
        /// <summary>
        /// Start the match
        /// </summary>
        public void Start(vmNewMatch newMatch)
        {
            if (Match == null)
            {
                Match = new TennisMatch();
            }

            //Set the properties of the new match
            Match.Type = newMatch.GetType();
            Match.NumberGamesPerSet = newMatch.GamesPerSet;
            Match.BestOutOf         = newMatch.GetBestOutOf();
            Match.TieBreakFinalSet  = newMatch.TiebreakFinalSet;
            Match.LogLevel          = newMatch.GetLogLevel();
            Match.Location          = newMatch.Location;
            Match.MatchSurface      = newMatch.GetSurface();

            TennisMatchVariant _variant = newMatch.MatchVariants[newMatch.SelectedMatchIndex];

            Match.DeuceSuddenDeath       = _variant.DeuceSuddenDeath;
            Match.FinalSetIsTiebreak     = _variant.FinalSetIsTiebreak;
            Match.FinalSetTieBreakLength = _variant.FinalSetTieBreakLength;
            Match.NumberGamesPerSet      = _variant.NumberGamesPerSet;
            Match.TieBreakAtSameScoreOf  = _variant.TieBreakAtSameScoreOf;
            Match.TieBreakFinalSet       = _variant.TieBreakFinalSet;
            Match.TieBreakLength         = _variant.TieBreakLength;

            StatisticsCollection.SetSource(Match);

            //Add the players
            Tennis_Statistics.Game_Logic.TennisPlayer Player1 = new Game_Logic.TennisPlayer();
            Player1.Name        = newMatch.Player1.Name;
            Player1.ID          = newMatch.Player1.ID;
            Player1.LocalPlayer = newMatch.Player1.LocalPlayer;
            Tennis_Statistics.Game_Logic.TennisPlayer Player2 = new Game_Logic.TennisPlayer();
            Player2.Name        = newMatch.Player2.Name;
            Player2.ID          = newMatch.Player2.ID;
            Player2.LocalPlayer = newMatch.Player2.LocalPlayer;

            Match.Contestant1.Players.Add(Player1);
            Match.Contestant2.Players.Add(Player2);

            //Add partners
            if (Match.Type == TennisMatch.MatchType.Doubles)
            {
                Tennis_Statistics.Game_Logic.TennisPlayer Partner1 = new Game_Logic.TennisPlayer();
                Partner1.Name        = newMatch.Player1Partner.Name;
                Partner1.ID          = newMatch.Player2Partner.ID;
                Partner1.LocalPlayer = newMatch.Player1Partner.LocalPlayer;
                Tennis_Statistics.Game_Logic.TennisPlayer Partner2 = new Game_Logic.TennisPlayer();
                Partner2.Name        = newMatch.Player2Partner.Name;
                Partner2.ID          = newMatch.Player2Partner.ID;
                Partner2.LocalPlayer = newMatch.Player2Partner.LocalPlayer;

                Match.Contestant1.Players.Add(Partner1);
                Match.Contestant2.Players.Add(Partner2);
            }

            CurrentPoint.LogLevel = Match.LogLevel;

            //Start the new set
            Match.StartNewSet();

            NewPoint();
        }
 private void CheckMatchIsFavorite(TennisMatch match, List <Entity.Favorite> favorites)
 {
     match.IsFavorite = favorites.Any(f => match.Players.Contains(f.Name));
 }
示例#21
0
        /// <summary>
        /// Fill the collection with default match variants
        /// </summary>
        private void CreateMatchVariants()
        {
            MatchVariants = TennisMatch.GetDefaultVariants();

            SelectedMatchIndex = 0;
        }
 public void Init()
 {
     game = new TennisMatch();
 }