/// <summary> /// Generates a <see cref="ShipList"/> of <see cref="Ship"/>s that conflict with one another. /// </summary> /// <returns>A <see cref="ShipList"/> of conflicting <see cref="Ship"/>s.</returns> public ShipList GetConflictingShips() { ShipList conflictingShips = new ShipList(); foreach (var ship in shipList) { foreach (var shipCompare in shipList) { if (ship != shipCompare && ship.ConflictsWith(shipCompare)) { conflictingShips.Add(ship); } } } return(conflictingShips); }
/// <summary> /// Generates a <see cref="ShipList"/> containing <see cref="Ship"/>s that have been sunk according /// to the <paramref name="shots"/>. /// </summary> /// <param name="shots">The <see cref="ShotList"/> containing <see cref="Shot"/>s made against /// the containing <see cref="Ship"/>s.</param> /// <returns>A <see cref="ShipList"/> of <see cref="Ship"/>s that completely occupy the spaces /// given by the <paramref name="shots"/>.</returns> public ShipList GetSunkShips(ShotList shots) { var newList = new ShipList(); int shotCount; foreach (var ship in shipList) { shotCount = 0; foreach (var coord in ship.GetAllLocations()) { if (shots.Contains(coord)) { shotCount++; } } if (shotCount == ship.Length) { newList.Add(ship); } } return(newList); }