/// <summary>
 /// Removes all Shot objects that are in a given ShotList.
 /// </summary>
 /// <param name="shots">The ShotList of Shots to remove.</param>
 public void Remove(ShotList shots)
 {
     foreach (var shot in shots.allShots)
     {
         Remove(shot);
     }
 }
        /// <summary>
        /// Creates a new ShotList with Shot objects in both list1 and list2.
        /// </summary>
        /// <returns>A new ShotList object with the Coordinatess of both ShotList objects.</returns>
        public static ShotList operator +(ShotList list1, ShotList list2)
        {
            ShotList newList = new ShotList(list1);

            newList.Add(list2);
            return(newList);
        }
        /// <summary>
        /// Creates a new ShotList with the Shot objects in list2 removed from list1.
        /// </summary>
        /// <param name="list1">The ShotList to remove Shot objects from.</param>
        /// <param name="list2">The ShotList containing the Shot objects to remove from list1</param>
        /// <returns>A new ShotList object.</returns>
        public static ShotList operator -(ShotList list1, ShotList list2)
        {
            ShotList newList = new ShotList(list1);

            newList.Remove(list2);
            return(newList);
        }
Exemple #4
0
 public FieldInfo()
 {
     Ships        = new ShipList();
     Shots        = new ShotList();
     ShipsLeft    = new ShipList();
     ShotsAgainst = new ShotList();
 }
        /// <summary>
        /// Generates and returns a ShotList of Shot objects that have been received by a specific ControllerID
        /// </summary>
        public ShotList ShotsToReceiver(IDNumber idx)
        {
            ShotList newList = new ShotList();

            newList.allShots             = allShots;
            newList.shotsByReceiver[idx] = shotsByReceiver[idx];
            return(newList);
        }
 /// <summary>
 /// Appends the contents of a ShotList to this ShotList.
 /// </summary>
 /// <param name="shots">The ShotList to add.</param>
 public void Add(ShotList shots)
 {
     foreach (var shot in shots.allShots)
     {
         allShots.Add(shot);
         shotsByReceiver[shot.Receiver].Add(shot);
     }
 }
Exemple #7
0
 public FieldInfo(FieldInfo copy)
 {
     if (copy != null)
     {
         Ships        = new ShipList(copy.Ships);
         Shots        = new ShotList(copy.Shots);
         ShipsLeft    = new ShipList(copy.ShipsLeft);
         ShotsAgainst = new ShotList(copy.ShotsAgainst);
     }
 }
        /// <summary>
        /// Generates a ShotList of Shot objects whose Coordinates are equal to the given Coordinates.
        /// </summary>
        /// <param name="coords">The Coordinates to get a ShotList for.</param>
        /// <returns>A ShotList of Shot objects whose Coordinates are equal to that given.</returns>
        public ShotList ShotsFromCoordinates(Coordinates coords)
        {
            ShotList newList = new ShotList();

            foreach (var shot in allShots)
            {
                if (shot.Coordinates == coords)
                {
                    newList.Add(shot);
                }
            }
            return(newList);
        }
        /// <summary>
        /// Contructs a new ShotList copying the contents of an existing ShotList.
        /// </summary>
        /// <param name="copyList">The ShotList to copy.</param>
        public ShotList(ShotList copyList)
        {
            shotsByReceiver = new Dictionary <IDNumber, List <Shot> >();
            allShots        = new List <Shot>();

            if (copyList != null)
            {
                foreach (var shot in copyList.allShots)
                {
                    Add(new Shot(shot));
                }
            }
        }
Exemple #10
0
        /// <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);
        }
 public ShotListEnumerator(ShotList shots)
 {
     collection = shots;
     currentIdx = -1;
 }