Ejemplo n.º 1
0
        public DetermineWinner(ISide sideOne, ISide sideTwo)
        {
            random = new Random();

            this.sideOne = sideOne;
            this.sideTwo = sideTwo;
        }
Ejemplo n.º 2
0
        private void PlayMatches(List<IPlayMatch> matches, ref ISide champion)
        {
            var nextRound = new List<IPlayMatch>();
            var winningSides = new List<ISide>();

            if (matches.Count == 1)
            {
                champion = matches[0].Play();
                AddMatchScore(matches[0]);
                return;
            }

            foreach(var match in matches)
            {
                var winner = match.Play();
                AddMatchScore(match);
                winningSides.Add(winner);
            }

            for (int i = 0; i < winningSides.Count; i = i + 2)
            {
                if (i == winningSides.Count - 1 && winningSides.Count % 2 == 1)
                {
                    nextRound.Add(new PlayMatch(winningSides[i], winningSides[i]));
                }
                else
                {
                    nextRound.Add(new PlayMatch(winningSides[i], winningSides[i+1]));
                }
            }

            PlayMatches(nextRound, ref champion);
        }
Ejemplo n.º 3
0
        public DetermineWinner(ISide sideOne, ISide sideTwo)
        {
            random = new Random();

            this.sideOne = sideOne;
            this.sideTwo = sideTwo;
        }
Ejemplo n.º 4
0
        public void Play_4_Sides_Winner_Determined()
        {
            //Arrange
            var anotherMatch = new Mock <IPlayMatch>();

            playMatches.Add(anotherMatch.Object);

            target = new PlayTournament(playMatches);

            var winner = new Mock <ISide>();

            winner.SetupProperty <int>(w => w.Strength, 33);

            playMatch.Setup <ISide>(m => m.Play()).Returns(winner.Object);
            anotherMatch.Setup <ISide>(m => m.Play()).Returns(winner.Object);

            //Act
            ISide result = target.Play();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(winner.Object, result);
            playMatch.Verify(m => m.Play(), Times.Exactly(1));
            Assert.AreEqual(3, target.GetMatchScores().Count());
        }
Ejemplo n.º 5
0
        private void OnEnable()
        {
            _selfScore = new Score();
            _opponent  = _anotherSide.GetComponent <ISide>();

            _selfScore.OnScorreAdd    += _scoreDrawer.ChangeScore;
            _selfScore.OnScorreReduce += _scoreDrawer.ChangeScore;
        }
Ejemplo n.º 6
0
        public void Play_2_Sides_Winner_Determined()
        {
            //Arrange
            target = new PlayTournament(playMatches);
            Mock <ISide> winner = new Mock <ISide>();

            playMatch.Setup <ISide>(m => m.Play()).Returns(winner.Object);

            //Act
            ISide result = target.Play();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(winner.Object, result);
            playMatch.Verify(m => m.Play(), Times.AtMostOnce());
            Assert.AreEqual(1, target.GetMatchScores().Count);
        }
Ejemplo n.º 7
0
        public PlayMatch(IPlaySet playSet, ISide sideOne, ISide sideTwo)
        {
            if (playSet == null)
            {
                throw new ArgumentNullException("playSet");
            }

            if (sideOne == null)
            {
                throw new ArgumentNullException("sideOne");
            }

            if (sideTwo == null)
            {
                throw new ArgumentNullException("sideTwo");
            }

            this.sideOne = sideOne;
            this.sideTwo = sideTwo;
            this.playSet = playSet;
        }
Ejemplo n.º 8
0
        public PlayMatch(IPlaySet playSet, ISide sideOne, ISide sideTwo)
        {
            if (playSet == null)
            {
                throw new ArgumentNullException("playSet");
            }

            if (sideOne == null)
            {
                throw new ArgumentNullException("sideOne");
            }

            if (sideTwo == null)
            {
                throw new ArgumentNullException("sideTwo");
            }

            this.sideOne = sideOne;
            this.sideTwo = sideTwo;
            this.playSet = playSet;
        }
Ejemplo n.º 9
0
 public PlaySet(ISide sideOne, ISide sideTwo)
     : this(new PlayGame(sideOne, sideTwo))
 {
     this.sideOne = sideOne;
     this.sideTwo = sideTwo;
 }
Ejemplo n.º 10
0
 public PlayMatch(ISide sideOne, ISide sideTwo) : this(new PlaySet(sideOne, sideTwo), sideOne, sideTwo)
 {
 }
Ejemplo n.º 11
0
 public PlaySet(ISide sideOne, ISide sideTwo) : this(new PlayGame(sideOne, sideTwo))
 {
     this.sideOne = sideOne;
     this.sideTwo = sideTwo;
 }
Ejemplo n.º 12
0
 public PlayGame(ISide sideOne, ISide sideTwo)
     : this(new DetermineWinner(sideOne, sideTwo))
 {
 }
Ejemplo n.º 13
0
 internal static ISideRunner CreateRunner(this ISide me, IPrinter printer)
 {
     return((ISideRunner)Activator.CreateInstance(typeof(SideRunner <,>).MakeGenericType(me.GetType().GetTypeInfo().GenericTypeArguments), me, printer));
 }
Ejemplo n.º 14
0
 public PlayMatch(ISide sideOne, ISide sideTwo)
     : this(new PlaySet(sideOne, sideTwo), sideOne, sideTwo)
 {
 }
Ejemplo n.º 15
0
 public void AddSide(ISide side)
 {
     _directionSidesMap[(int) side.NormalDirection].Add(side);
 }
Ejemplo n.º 16
0
 public void SetSide(int direction, ISide side)
 {
     this.sides[direction] = side;
 }
Ejemplo n.º 17
0
 public PlayGame(ISide sideOne, ISide sideTwo) : this(new DetermineWinner(sideOne, sideTwo))
 {
 }
Ejemplo n.º 18
0
 public void RemoveSide(ISide side)
 {
     _directionSidesMap[(int) side.NormalDirection].Remove(side);
 }
Ejemplo n.º 19
0
        public static void Main(string[] args)
        {
            bool playAgain = true;

            while (playAgain)
            {
                playAgain = false;
                Console.WriteLine("Shall we play some Tennis?");
                Console.Write("How many sides: ");
                string numberOfPlayers = Console.ReadLine();

                int number = 0;
                if (!Int32.TryParse(numberOfPlayers, out number))
                {
                    Console.WriteLine("Sorry, the number of sides could not be understood. Please try again");
                    return;
                }

                if (number <= 0)
                {
                    Console.WriteLine("Sorry, the number of sides must be positive. Please try again");
                    return;
                }

                var matches = new List <IPlayMatch>();
                var sides   = new List <ISide>();
                var random  = new Random();

                for (int i = 0; i < number; i++)
                {
                    Console.Write("Team Name: ");
                    string name = Console.ReadLine();

                    ISide newSide = new PlayingSide();
                    newSide.TeamName          = name;
                    newSide.Strength          = random.Next(100);
                    newSide.ServingStrength   = random.Next(50);
                    newSide.ReturningStrength = random.Next(25);

                    sides.Add(newSide);
                    Console.Write(" added with strength: {0}, serving: {1}, returning: {2}\n", newSide.Strength,
                                  newSide.ServingStrength, newSide.ReturningStrength);

                    if (i == number - 1)
                    {
                        if (number % 2 == 1)
                        {
                            // let the last odd team play themselves
                            ISide anotherSide = new PlayingSide();
                            anotherSide.TeamName          = name;
                            anotherSide.Strength          = random.Next(100);
                            anotherSide.ServingStrength   = random.Next(50);
                            anotherSide.ReturningStrength = random.Next(25);
                        }
                    }
                }

                Console.Write("To Start Tournament Press <Enter>");
                Console.ReadLine();

                for (int i = 0; i < sides.Count; i = i + 2)
                {
                    matches.Add(new PlayMatch(new PlaySet(new PlayGame(new DetermineWinner(sides[i], sides[i + 1]))), sides[i], sides[i + 1]));
                }

                IPlayTournament playTournament = new PlayTournament(matches);

                ISide champion = playTournament.Play();
                IEnumerable <MatchScore> matchScores = playTournament.GetMatchScores();

                PrintMatchScores(matchScores);

                Console.WriteLine("----------------------------------------------------------------");
                Console.WriteLine("And the champion is....{0}, strength: {1}, serving: {2}, returning: {3}",
                                  champion.TeamName, champion.Strength, champion.ServingStrength,
                                  champion.ReturningStrength);

                Console.WriteLine("----------------------------------------------------------------");
                Console.WriteLine("----------------------------------------------------------------");
                Console.Write("Play Again? (Y or N): ");
                string again = Console.ReadLine();

                if (again == "Y" || again == "y")
                {
                    playAgain = true;
                }
            }
        }