private Coordinates RandomShot() { var availablePanels = FiringBoard.GetOpenRandomPanels(); var rand = new Random(Guid.NewGuid().GetHashCode()); var panelID = rand.Next(availablePanels.Count); return(availablePanels[panelID]); }
private Coordinates SearchingShot() { var rand = new Random(Guid.NewGuid().GetHashCode()); var hitNeighbors = FiringBoard.GetHitNeighbors(); var neighborID = rand.Next(hitNeighbors.Count); return(hitNeighbors[neighborID]); }
public Coordinates FireShot() { //If there are hits on the board with neighbors which don't have shots, we should fire at those first. var hitNeighbors = FiringBoard.GetHitNeighbors(); Coordinates coords; if (hitNeighbors.Any()) { coords = SearchingShot(); } else { coords = RandomShot(); } Console.WriteLine(Name + " says: \"Firing shot at " + coords.Row.ToString() + ", " + coords.Column.ToString() + "\""); return(coords); }
public Player(string name) { Id = Guid.NewGuid().ToString(); Name = name; Ships = new List <Ship>() { new Destroyer(), new Submarine(), new Cruiser(), new Battleship(), new Carrier() }; GameBoard = new GameBoard(); FiringBoard = new FiringBoard(); if (!string.IsNullOrEmpty(name)) { PlaceShips(); } }