public void GetHitResult_HitsShipFourTimes_ReturnsSink() { int panelSize = 10; IShipManager shipManager = Substitute.For <IShipManager>(); var destroyerType = new ShipType("Destroyer", "D", 4); var shipsByType = new Dictionary <ShipType, int> { { destroyerType, 1 } }; var ship = new Ship(new Point(3, 2), new Point(3, 5), destroyerType); var shipList = new List <Ship> { ship }; shipManager.GetShipsByType().Returns(shipsByType); shipManager.GetShipList(shipsByType, panelSize).Returns(shipList); GameService target = new GameService(shipManager); target.InitializeGame(panelSize); target.Hit(new Point(3, 2)); target.Hit(new Point(3, 3)); target.Hit(new Point(3, 4)); var result = target.Hit(new Point(3, 5)); result.Should().Be(HitTypeEnum.Sink); }
public void GetHitList_WithFourHits_ReturnsListWithAllOfThem() { int panelSize = 10; IShipManager shipManager = Substitute.For <IShipManager>(); var destroyerType = new ShipType("Destroyer", "D", 4); var shipsByType = new Dictionary <ShipType, int> { { destroyerType, 1 } }; var ship = new Ship(new Point(3, 2), new Point(3, 5), destroyerType); var shipList = new List <Ship> { ship }; shipManager.GetShipsByType().Returns(shipsByType); shipManager.GetShipList(shipsByType, panelSize).Returns(shipList); GameService target = new GameService(shipManager); target.InitializeGame(panelSize); var missPoint = new Point(0, 0); var hitPoint1 = new Point(3, 2); var hitPoint2 = new Point(3, 3); var hitPoint3 = new Point(3, 4); var hitList = new List <Point> { missPoint, hitPoint1, hitPoint2, hitPoint3 }; target.Hit(missPoint); target.Hit(hitPoint1); target.Hit(hitPoint2); target.Hit(hitPoint3); target.GetHitList().Should().Contain(hitList); }
public void GameOver_WithOneShipSinked_ReturnsTrue() { int panelSize = 10; IShipManager shipManager = Substitute.For <IShipManager>(); var destroyerType = new ShipType("Destroyer", "D", 4); var shipsByType = new Dictionary <ShipType, int> { { destroyerType, 1 } }; var ship = new Ship(new Point(3, 2), new Point(3, 5), destroyerType); var shipList = new List <Ship> { ship }; shipManager.GetShipsByType().Returns(shipsByType); shipManager.GetShipList(shipsByType, panelSize).Returns(shipList); GameService target = new GameService(shipManager); target.InitializeGame(panelSize); target.Hit(new Point(3, 2)); target.Hit(new Point(3, 3)); target.Hit(new Point(3, 4)); target.Hit(new Point(3, 5)); target.GameOver().Should().BeTrue(); }
public void InitializeGame(int panelSize) { _enemyShipsByType = _shipManager.GetShipsByType(); var enemyShips = _shipManager.GetShipList(_enemyShipsByType, panelSize); InitializeHitsPerShip(enemyShips); }
public void InitializeGame_WithOneShip_ReturnsItCorrectly() { int panelSize = 10; IShipManager shipManager = Substitute.For <IShipManager>(); var destroyerType = new ShipType("Destroyer", "D", 4); var shipsByType = new Dictionary <ShipType, int> { { destroyerType, 1 } }; var ship = new Ship(new Point(3, 2), new Point(3, 5), destroyerType); var shipList = new List <Ship> { ship }; shipManager.GetShipsByType().Returns(shipsByType); shipManager.GetShipList(shipsByType, panelSize).Returns(shipList); GameService target = new GameService(shipManager); target.InitializeGame(panelSize); target.GetShipList().Should().Contain(shipList); }