public Battleship(int length, Coordinate coords, BattleshipOrientation orientation) { this.Coords = coords; this.Length = length; this.Orientation = orientation; this.SectionHit = new List <bool>(new bool[this.Length]); }
public void AddBattleship(Battleship battleship, BattleshipOrientation orientation, System.Drawing.Point startPosition) { if (battleship == null || startPosition == null) { throw new ValidationException("Battleship and start position is required"); } List <Point> pointsOccupiedByShip = new List <Point>(); for (int index = 0; index < battleship.Size; index++) { var nextPosition = new Point(); if (orientation == BattleshipOrientation.Horizontal) { nextPosition.X = startPosition.X + index; nextPosition.Y = startPosition.Y; } else { nextPosition.X = startPosition.X; nextPosition.Y = startPosition.Y + index; } if (OccupiedCells.Contains(nextPosition) == true) { throw new PositionConflictException("Battleship cannot be placed here as position is already occupied"); } pointsOccupiedByShip.Add(nextPosition); } this.battleships.Add(battleship); this.OccupiedCells.AddRange(pointsOccupiedByShip); this.BattleshipPositions.Add(battleship, pointsOccupiedByShip); }