static void Main(string[] args) { TennisGame.TennisGame tg = new TennisGame.TennisGame(); System.Console.WriteLine("The Game begins:"); while (true) { System.Console.WriteLine("\n" + tg.GameState + "\n"); System.Console.WriteLine("Who shall score? (1 = Player1 | 2 = Player2):"); string ps = System.Console.ReadLine(); if (ps.Equals("1")) { tg.Player1.ScorePointAgainst(tg.Player2); } else if (ps.Equals("2")) { tg.Player2.ScorePointAgainst(tg.Player1); } else { return; } if (tg.Player1.Score == TennisScore.Game || tg.Player2.Score == TennisScore.Game) { System.Console.WriteLine("\n" + tg.GameState + "\n\nPress Any Key to exit..."); string aas = System.Console.ReadLine(); return; } } }
static void Main(string[] args) { Boolean running = true; Random rnd = new Random(); Player player1 = new Player(); Player player2 = new Player(); TennisGame game = new TennisGame(player1, player2); while (running) //main loop { if (rnd.Next(2) == 0) //Player1 scores { player1.IncrementPoints(); Console.WriteLine("Player1 scored and now has " + player1.GetPoints().ToString() + " points" ); } else //Player2 scores { player2.IncrementPoints(); Console.WriteLine("Player2 scored and now has " + player2.GetPoints().ToString() + " points"); } Console.WriteLine("Score is: " + game.GetScore()); // Score of the game if (GameIsWon(player1, player2)) //check if game is already won { running = false; } System.Threading.Thread.Sleep(_sleepTime); //Thread sleep to make it easier to follow game process in console } }
public void Should_Return_15Love_When_Player1_Scores() { var game = new TennisGame("0-0"); game = game.Player1Scores(); Assert.AreEqual("15-0", game.GetCurrentScore()); }
public void Should_Return_3015_When_Player1_Scores_Twice_And_Player2_Scores_Once() { var game = new TennisGame("0-0"); game = game.Player1Scores().Player1Scores().Player2Scores(); Assert.AreEqual("30-15", game.GetCurrentScore()); }
public void New_Game_Creates_With_Player_Scores_0_0() { var sut = new TennisGame.TennisGame(); Assert.IsNotNull(sut); Assert.AreEqual(TennisScore.Love, sut.Player1.Score); Assert.AreEqual(TennisScore.Love, sut.Player2.Score); }
public void TestMethod1() { var instance = Substitute.For <IRepository <Game> >(); var tennisGame = new TennisGame(instance); var scoreResult = tennisGame.ScoreResult(1); Assert.AreEqual("", scoreResult); }
public void GameState_Returns_Game_Score_When_No_Spacial_State_Is_Set() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 Assert.AreEqual("Thirty - Fifteen", sut.GameState); }
public void GameState_Returns_Game_For_Player1_When_Player1_Wins() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 sut.Player2.ScorePointAgainst(sut.Player1); // 30 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // 40 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // Game - 40 Assert.AreEqual("Game for Player1", sut.GameState); }
public void GameState_Returns_Duece_When_Botg_Players_Have_Score_Of_40() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 sut.Player2.ScorePointAgainst(sut.Player1); // 30 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // 40 - 30 sut.Player2.ScorePointAgainst(sut.Player1); // 40 - 40 Assert.AreEqual("Duece", sut.GameState); }
public void Initialize() { _player1 = new Player(); _player2 = new Player(); _game = new TennisGame(_player1, _player2); }
public void Should_Return_LoveLove() { var game = new TennisGame("0-0"); Assert.AreEqual("0-0", game.GetCurrentScore()); }
public void When_A_Player_Wins_No_Scores_Are_Counted_Anymore() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 sut.Player2.ScorePointAgainst(sut.Player1); // 30 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // 40 - 30 sut.Player2.ScorePointAgainst(sut.Player1); // 40 - 40 sut.Player1.ScorePointAgainst(sut.Player2); // Adv - 40 sut.Player1.ScorePointAgainst(sut.Player2); // Game - 40 sut.Player1.ScorePointAgainst(sut.Player2); // Game - 40 sut.Player2.ScorePointAgainst(sut.Player1); // Game - 40 Assert.AreEqual(TennisScore.Game, sut.Player1.Score); Assert.AreEqual(TennisScore.Fourty, sut.Player2.Score); }
public void When_Player_Scores_Score_Is_Increased() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); Assert.AreEqual(TennisScore.Fifteen, sut.Player1.Score); Assert.AreEqual(TennisScore.Love, sut.Player2.Score); }
public void When_Player1_Score_Is_Fourty_And_Scores_And_Has_1_Point_Lead_He_Wins() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 sut.Player2.ScorePointAgainst(sut.Player1); // 30 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // 40 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // Game - 30 <- Should be Assert.AreEqual(TennisScore.Game, sut.Player1.Score); }
public void When_Player1_Has_Advantage_And_Scores_He_Wins() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 sut.Player2.ScorePointAgainst(sut.Player1); // 30 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // 40 - 30 sut.Player2.ScorePointAgainst(sut.Player1); // 40 - 40 sut.Player1.ScorePointAgainst(sut.Player2); // Adv - 40 sut.Player1.ScorePointAgainst(sut.Player2); // Game - 40 Assert.AreEqual(TennisScore.Game, sut.Player1.Score); }
public void When_Player1_Has_Advantage_And_Player2_Scores_Game_Is_Set_To_Duece() { var sut = new TennisGame.TennisGame(); sut.Player1.ScorePointAgainst(sut.Player2); // 15 - 0 sut.Player2.ScorePointAgainst(sut.Player1); // 15 - 15 sut.Player1.ScorePointAgainst(sut.Player2); // 30 - 15 sut.Player2.ScorePointAgainst(sut.Player1); // 30 - 30 sut.Player1.ScorePointAgainst(sut.Player2); // 40 - 30 sut.Player2.ScorePointAgainst(sut.Player1); // 40 - 40 sut.Player1.ScorePointAgainst(sut.Player2); // Adv - 40 sut.Player2.ScorePointAgainst(sut.Player1); // 40 - 40 Assert.AreEqual(TennisScore.Fourty, sut.Player1.Score); Assert.AreEqual(TennisScore.Fourty, sut.Player2.Score); }