示例#1
0
        public Coordinates SearchingShot()   // returns Coordinates the Player wants to fire
        {
            Random random         = new Random(Guid.NewGuid().GetHashCode());
            var    hitNeighbours  = FiringBoard.GetHitNeighbours();
            var    neighbourIndex = random.Next(hitNeighbours.Count);

            return(hitNeighbours[neighbourIndex]);
        }
示例#2
0
        public Coordinates RandomShot()
        {
            var    availableCells  = FiringBoard.GetOpenRandomCells();
            Random random          = new Random(Guid.NewGuid().GetHashCode());
            var    cellToFireIndex = random.Next(availableCells.Count);

            Console.WriteLine(" CUR IND: " + cellToFireIndex + "\t" + " CUR COUNT: " + availableCells.Count);

            return(availableCells[cellToFireIndex]);
        }
示例#3
0
 public Player(string name)
 {
     this.Name = name;
     Ships     = new List <Ship>()
     {
         new Destroyer(),
         new Submarine(),
         new Cruiser(),
         new Battleship(),
         new Carrier()
     };
     GameBoard   = new GameBoard();
     FiringBoard = new FiringBoard();
     shipsLost   = 0;
 }
示例#4
0
        // FIRING
        public virtual Coordinates FireShot()
        {
            var         hitNeighbours = FiringBoard.GetHitNeighbours();
            Coordinates coordinatesToShotAt;

            if (hitNeighbours.Any())
            {
                coordinatesToShotAt = SearchingShot();
            }
            else
            {
                coordinatesToShotAt = RandomShot();
            }

            Console.WriteLine(Name + " says: \"Firing shot at "
                              + coordinatesToShotAt.row.ToString() + ":"
                              + coordinatesToShotAt.column.ToString()
                              + "\"");

            return(coordinatesToShotAt);
        }