예제 #1
0
        static void Main(string[] args)
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayTennis();

            Console.ReadKey();
        }
 public void RealisticTennisGame(TennisGame game)
 {
     String[] points =          {"player1", "player1", "player2", "player2", "player1", "player1"};
       String[] expected_scores = {"Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1"};
       for (int i = 0; i < 6; i++) {
     game.WonPoint(points[i]);
     Assert.AreEqual(expected_scores[i], game.GetScore());
       }
 }
예제 #3
0
 public void RealisticTennisGame(TennisGame game)
 {
     String[] points          = { "player1", "player1", "player2", "player2", "player1", "player1" };
     String[] expected_scores = { "Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1" };
     for (int i = 0; i < 6; i++)
     {
         game.WonPoint(points[i]);
         Assert.AreEqual(expected_scores[i], game.GetScore());
     }
 }
 public void checkAllScores(TennisGame game) {
   int highestScore = Math.Max(this.player1Score, this.player2Score);
   for (int i = 0; i < highestScore; i++) {
     if (i < this.player1Score)
       game.WonPoint("player1");
     if (i < this.player2Score)
       game.WonPoint("player2");
   }
   Assert.AreEqual(this.expectedScore, game.GetScore());
 }
        public void Convert_Points_To_Score(
            int player1Points, int player2Points, string expected)
        {
            // Giwen
            var game = new TennisGame(player1Points, player2Points);

            // When
            var score = game.GetScore();

            // Then
            Assert.Equal(expected, score);
        }
        public void CheckRealisticGame()
        {
            var game = new TennisGame("player1", "player2");

            string[] points         = { "player1", "player1", "player2", "player2", "player1", "player1" };
            string[] expectedScores = { "Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1" };

            for (var i = 0; i < 6; i++)
            {
                game.WonPoint(game.PlayerList.First(p => p.Name == points[i]).Id, game.PlayerList.First(p => p.Name != points[i]).Id);
                Assert.AreEqual(expectedScores[i], game.GetScore());
            }
        }
        public void CheckRealisticGame()
        {
            var game = new TennisGame("player1", "player2");

            string[] points         = { "player1", "player1", "player2", "player2", "player1", "player1" };
            string[] expectedScores = { "Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1" };

            for (var i = 0; i < 6; i++)
            {
                game.PointScored(points[i] == "player1" ? game.PlayerOne : game.PlayerTwo);
                Assert.AreEqual(expectedScores[i], game.GetGameScore());
            }
        }
예제 #8
0
        public void checkAllScores(TennisGame game)
        {
            int highestScore = Math.Max(this.player1Score, this.player2Score);

            for (int i = 0; i < highestScore; i++)
            {
                if (i < this.player1Score)
                {
                    game.WonPoint("player1");
                }
                if (i < this.player2Score)
                {
                    game.WonPoint("player2");
                }
            }
            Assert.AreEqual(this.expectedScore, game.GetScore());
        }
예제 #9
0
        public void AssertTennisScore(int player1Score, int player2Score, string expectedScore)
        {
            var game         = new TennisGame("player1", "player2");
            var highestScore = Math.Max(player1Score, player2Score);

            for (var i = 0; i < highestScore; i++)
            {
                if (i < player1Score)
                {
                    game.WonPoint("player1");
                }
                if (i < player2Score)
                {
                    game.WonPoint("player2");
                }
            }
            Assert.AreEqual(expectedScore, game.GetScore());
        }
예제 #10
0
 //Game Creation
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     game = new TennisGame(First_Player.Text, Second_Player.Text);
     Player_1_Up.IsEnabled = true;
     Player_2_Up.IsEnabled = true;
     Player1_Name1.Content = game.Player_1().Name();
     Player1_Name2.Content = game.Player_1().Name();
     Player2_Name1.Content = game.Player_2().Name();
     Player2_Name2.Content = game.Player_2().Name();
     foreach (Window window in Application.Current.Windows)
     {
         if (window.GetType() == typeof(ViewPanel))
         {
             (window as ViewPanel).Player1_Name_small.Content = game.Player_1().Name();
             (window as ViewPanel).Player2_Name_small.Content = game.Player_2().Name();
         }
     }
     UpdateAll();
 }
        public void CheckTennisGame(int player1Score, int player2Score, string expectedScore)
        {
            var game = new TennisGame("player1", "player2");

            var highestScore = Math.Max(player1Score, player2Score);

            for (var i = 0; i < highestScore; i++)
            {
                if (i < player1Score)
                {
                    game.PointScored(game.PlayerOne);
                }
                if (i < player2Score)
                {
                    game.PointScored(game.PlayerTwo);
                }
            }
            Assert.AreEqual(expectedScore, game.GetGameScore());
        }
        public void CheckTennisGame(int player1Score, int player2Score, string expectedScore)
        {
            var game         = new TennisGame("player1", "player2");
            var p1           = game.PlayerList.First(p => p.Name == "player1");
            var p2           = game.PlayerList.First(p => p.Name == "player2");
            var highestScore = Math.Max(player1Score, player2Score);

            for (var i = 0; i < highestScore; i++)
            {
                if (i < player1Score)
                {
                    game.WonPoint(p1.Id, p2.Id);
                }
                if (i < player2Score)
                {
                    game.WonPoint(p2.Id, p1.Id);
                }
            }
            Assert.AreEqual(expectedScore, game.GetScore());
        }
예제 #13
0
        public static void Main(string[] args)
        {
            TennisGame game = new TennisGame("GZ", "CNN");

            game.FirstPlayerScore();
            game.Score();
            game.SecondPlayerScore();
            game.Score();

            game.FirstPlayerScore();
            game.FirstPlayerScore();
            game.SecondPlayerScore();
            game.SecondPlayerScore();
            game.Score();

            game.SecondPlayerScore();
            game.Score();

            game.SecondPlayerScore();
            game.Score();
        }
예제 #14
0
 public GameStateWon(TennisGame game, Party winningParty)
     : base(game)
 {
     _winningParty = winningParty;
 }
예제 #15
0
 public GameStateAdvantageScoring(TennisGame game)
     : base(game)
 {
 }
예제 #16
0
        static void Main(string[] args)
        {
            TennisGame tennisGame = new TennisGame();

            Console.WriteLine(tennisGame.GetScore("Federer", "Nadal", 2, 1));
        }
예제 #17
0
 public IGameState GetNormalGameState(TennisGame game)
 {
     return new GameStateSimpleNoAdScoring(game);
 }
예제 #18
0
 public IGameState GetStandardGameState(TennisGame game)
 {
     return new GameStateAdvantageScoring(game);
 }
예제 #19
0
        public void AddPoint(Party party)
        {
            if (SetOver)
                throw new InvalidOperationException("Cannot add points to won sets.");

            _currentGame.AddPoint(party);

            if (_currentGame.GameOver)
            {
                IncreaseScore(party);
                _setState = _setState.GameAdded(party);

                if (!_setState.SetOver)
                    _currentGame = _setState.GetNextGame(_tournamentRules);
            }
        }
예제 #20
0
 public GameStateAdvantage(TennisGame game, Party advantageParty)
     : base(game)
 {
     _advantageParty = advantageParty;
 }
예제 #21
0
 public TennisSet(ITournamentRules tournamentRules, Party partyA, Party partyB, Func<TennisSet, ISetState> setStateFactory)
     : base(partyA, partyB)
 {
     _setState = setStateFactory(this);
     _tournamentRules = tournamentRules;
     _currentGame = _setState.GetNextGame(tournamentRules);
 }
예제 #22
0
 public void Teardown()
 {
     tennis = null;
 }
예제 #23
0
 protected GameStateBase(TennisGame game)
 {
     Game = game;
 }
예제 #24
0
        public void CheckTennisGame()
        {
            var game = new TennisGame("player1", "player2");

            CheckAllScores(game);
        }
예제 #25
0
 public GameStateDeuce(TennisGame game)
     : base(game)
 {
 }
예제 #26
0
 public GameStateSimpleNoAdScoring(TennisGame game)
     : base(game)
 {
 }
예제 #27
0
 public void Setup()
 {
     tennis = new Tennis.TennisGame("Federer", "Nadal");
 }
예제 #28
0
        public void CheckGame()
        {
            var game = new TennisGame("player1", "player2");

            RealisticTennisGame(game);
        }
예제 #29
0
 public GameStateTieBreakScoring(TennisGame game)
     : base(game)
 {
 }