public void GivenMapWithShipPlaced_WhenPlacingShipOverlappingOtherShip_DoesNotAddShipToCells() { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); map.Place(ship, coordinate, Direction.East); var overLappingShip = ShipStub.FullStub(this.player); try { map.Place(overLappingShip, coordinate, Direction.East); } catch (Exception) { //No-Op } var cellsWithOccupants = map.Cells.Where(x => x.Occupied); foreach (var cellsWithOccupant in cellsWithOccupants) { Assert.That(!overLappingShip.Cells.Contains(cellsWithOccupant)); } }
public void GivenShip_WhenConstructing_AddsCorrectAmountOfShipSegments() { const int segmentCount = 4; Ship ship = new ShipStub(player, segmentCount); Assert.AreEqual(segmentCount, ship.Cells.Count()); }
public void GivenShip_WhenConstructing_AssociatesThePlayerToShip() { const int segmentCount = 4; Ship ship = new ShipStub(player, segmentCount); Assert.AreEqual(player, ship.Owner); }
public void GivenShip_WhenConstructing_AssociatesThePlayerToShip() { const int segmentCount = 4; Ship ship = new ShipStub(player, segmentCount, new WeaponStub(player, 1, WeaponType.SingleShot)); Assert.AreEqual(player, ship.Owner); }
public void GivenMap_WhenPlacingShipWithInvalidDirection_ThrowsException(Direction direction) { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); Assert.Throws <InvalidOperationException>(() => map.Place(ship, coordinate, direction)); }
public void GivenMap_WhenPlacingShipWithDirectionLeadingToOutOfBounds_ThrowsException(Direction direction) { const int width = 1; const int height = 1; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player, new WeaponStub(player, 1, WeaponType.SingleShot)); Assert.Throws <InvalidOperationException>(() => map.Place(ship, coordinate, direction)); }
public void GivenMap_WhenPlacingShipOfOtherPlayer_ThrowsException() { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var otherPlayer = new BattleshipPlayer("OtherPlayer", 'A', PlayerType.One); var ship = ShipStub.FullStub(otherPlayer); Assert.Throws <InvalidOperationException>(() => map.Place(ship, coordinate, Direction.East)); }
public void GivenMapWithShipPlaced_WhenPlacingShipOverlappingOtherShip_ThrowsException() { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); map.Place(ship, coordinate, Direction.West); var overLappingShip = ShipStub.FullStub(this.player); Assert.Throws <InvalidOperationException>(() => map.Place(overLappingShip, coordinate, Direction.East)); }
public void GivenShip_WhenConstruting_SetsDestroyedToFalse() { const int segmentCount = 4; Ship ship = new ShipStub(player, segmentCount); const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(0, 0); ship.Place(coordinate, Direction.East, map); Assert.False(ship.Destroyed); }
public void GivenShipWithAllSegmentsUnDamaged_WhenDamagingSegment_DoesNotMarkShipAsDestroyed() { var ship = new ShipStub(player, 2); const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(0, 0); ship.Place(coordinate, Direction.East, map); var segmentToDamage = ship.Cells.First(); segmentToDamage.LandShot(); Assert.False(ship.Destroyed); }
public void GivenShipWithOneSegment_WhenDamagingSegment_MarksCellsAsDestroyed() { var ship = new ShipStub(player, 1, new WeaponStub(player, 1, WeaponType.SingleShot)); const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(0, 0); ship.Place(coordinate, Direction.East, map); var segmentToDamage = ship.Cells.First(); segmentToDamage.LandShot(); Assert.True(ship.Cells.All(x => x != null && x.Hit)); }
public void GivenMap_WhenPlacingShip_PlacesShip(Direction direction) { const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); map.Place(ship, coordinate, direction); var cellOccupants = map.Cells.Where(x => x.Occupied).Select(x => x.OccupiedBy).ToList(); foreach (var segment in ship.Cells) { Assert.Contains(segment, map.Cells.ToList()); } }
public void GivenShipWithAllButOneSegmentDamaged_WhenDamagingSegment_MarksShipAsDestroyed() { var ship = new ShipStub(player, 4); const int width = 5; const int height = 5; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(0, 0); ship.Place(coordinate, Direction.East, map); var segmentToDamage = ship.Cells.First(); foreach (var segments in ship.Cells.Where(x => x != segmentToDamage)) { segments.LandShot(); } segmentToDamage.LandShot(); Assert.True(ship.Destroyed); }
public void GivenMap_WhenPlacingShipWithDirectionLeadingToOutOfBounds_DoesAddShipToCells(Direction direction) { const int width = 1; const int height = 1; var map = new PlayerMap(width, height, this.player); var coordinate = new Point(width / 2, height / 2); var ship = ShipStub.FullStub(this.player); try { map.Place(ship, coordinate, direction); } catch (Exception) { //No-Op } var cellsWithOccupants = map.Cells.Where(x => x.Occupied); Assert.IsEmpty(cellsWithOccupants); }