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]); }
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]); }
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; }
// 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); }