Esempio n. 1
0
 public Player(string name)
 {
     Name  = name;
     Ships = new List <Ship>
     {
         new Submarine(),
         new Cruiser(),
         new AircraftCarrier(),
         new Battleship(),
         new Destroyer()
     };
     GameBoard    = new GameBoard(false);
     TrackerBoard = new TrackerBoard(true);
 }
Esempio n. 2
0
        /// <summary>
        /// Automatic Fire method
        /// </summary>
        /// <returns></returns>
        public Location Fire()
        {
            TotalShots++;
            Random rand = new Random(Guid.NewGuid().GetHashCode());
            // TODO - Check for calculated shot
            List <Location> affectedNeighbours = TrackerBoard.GetAffectedNeighbours();

            if (affectedNeighbours.Any())
            {
                int neighbourKey = rand.Next(affectedNeighbours.Count);
                //Console.WriteLine($"{Name}: Calculated Shot!");
                CalculatedShots++;
                return(affectedNeighbours[neighbourKey]);
            }
            else // If calculate shot is not available create a random shot at a panel not hit before
            {
                List <Location> notHitLocations = TrackerBoard.GetRandomLocations();
                int             locationKey     = rand.Next(notHitLocations.Count);
                //Console.WriteLine($"{Name}: Random Shot");
                RandomShots++;
                return(notHitLocations[locationKey]);
            }
        }