public void TestRenderMatchResultPlayerTwoWinKills() { // Given var game = Match.GetInstance(); game.StartNewGame(); // When game.Update(); var p1 = game.GetPlayer(1); p1.Lives = 0; p1.Kills = 4; p1.Ship.Destroy(); var p2 = game.GetPlayer(2); p2.Lives = 0; p2.Kills = 10; p2.Ship.Destroy(); game.Update(); var summary = new SpaceInvadersRenderer().RenderSummary(game); // Then Assert.IsTrue(game.GameIsOver(), "Game did not end."); Assert.AreEqual(2, summary.Winner, "Winner was not set to 2."); Assert.AreEqual("Player 2 had more kills than player 1.", summary.WinReason, "Win reason was incorrect."); }
public void TestRenderMatchResultPlayerTwoWin() { // Given var game = Match.GetInstance(); game.StartNewGame(); // When game.Update(); game.GetPlayer(1).Lives = 0; game.GetPlayer(1).Ship.Destroy(); game.Update(); var summary = new SpaceInvadersRenderer().RenderSummary(game); // Then Assert.IsTrue(game.GameIsOver(), "Game did not end."); Assert.AreEqual(2, summary.Winner, "Winner was not set to 2."); Assert.AreEqual("Player 1 ran out of lives.", summary.WinReason, "Win reason was incorrect."); }
public void TestJsonDeserialization() { // Given CoordinateFlipper flipper; var game = CreateInterestingGameState(out flipper); var renderer = new SpaceInvadersRenderer(); var state = renderer.Render(game).State; var mapReal = renderer.Render(game).Map; Debug.WriteLine("Map:"); Debug.WriteLine(mapReal); // Prevent further shooting as that introduces randomness game.GetPlayer(1).AlienManager.TestPreventAllAliensShoot(); game.GetPlayer(2).AlienManager.TestPreventAllAliensShoot(); for (var i = 0; i < 5; i++) { game.Update(); //Debug.WriteLine(""); mapReal = renderer.Render(game).Map; //Debug.WriteLine(mapReal); } // When var match = JsonConvert.DeserializeObject<Match>(state, new JsonSerializerSettings { Converters = {new EntityConverter()}, NullValueHandling = NullValueHandling.Ignore } ); Match.SetInstance(match); // Prevent further shooting as that introduces randomness var mapPredicted = renderer.Render(match).Map; match.GetPlayer(1).AlienManager.TestPreventAllAliensShoot(); match.GetPlayer(2).AlienManager.TestPreventAllAliensShoot(); for (var i = 0; i < 5 + 1; i++) { match.Update(); //Debug.WriteLine(""); mapPredicted = renderer.Render(game).Map; //Debug.WriteLine(mapPredicted); } Debug.WriteLine(""); Debug.WriteLine("Map predicted:"); Debug.WriteLine(mapPredicted); // Then Assert.AreEqual(mapReal, mapPredicted); }
public void TestRenderMatchResultPlayerOneWinOnTies() { // Given var game = Match.GetInstance(); game.StartNewGame(); // When game.Update(); var p1 = game.GetPlayer(1); p1.Lives = 0; p1.Kills = 10; p1.Ship.Destroy(); var p2 = game.GetPlayer(2); p2.Lives = 0; p2.Kills = 10; p2.Ship.Destroy(); game.Update(); var summary = new SpaceInvadersRenderer().RenderSummary(game); // Then Assert.IsTrue(game.GameIsOver(), "Game did not end."); Assert.AreEqual(1, summary.Winner, "Winner was not set to 1."); Assert.AreEqual("Match was a tie, so player 1 wins by default.", summary.WinReason, "Win reason was incorrect."); }
public void TestMissilesOneDoesNotKillTwo() { // Given var renderer = new SpaceInvadersRenderer(); var game = Match.GetInstance(); game.StartNewGame(); var map = game.Map; var player = game.GetPlayer(1); var ship = player.Ship; var aliens = game.GetPlayer(2).AlienManager; var player2 = game.GetPlayer(2); var killsBefore = player2.Kills; // When //add them in the order the harness would add them var missile1 = new Missile(1) { X = ship.X, Y = ship.Y - 3 }; map.AddEntity(missile1); var missile3 = new Missile(2) { X = ship.X, Y = ship.Y - 4 }; map.AddEntity(missile3); var missile4 = new Missile(2) { X = ship.X, Y = ship.Y - 5 }; map.AddEntity(missile4); // Then Console.WriteLine(renderer.Render(game).Map); game.Update(); Console.WriteLine(renderer.Render(game).Map); Assert.IsFalse(missile1.Alive, "Missile 1 wasn't destroyed."); Assert.IsFalse(missile3.Alive, "Missile 3 wasn't destroyed."); Assert.IsTrue(missile4.Alive, "Missile 4 was destroyed."); }