// method for turn, use player as input public static ShotStatus PlayerTurn(Player player, Board board) { Console.WriteLine($"Press any key to begin {player.Name}'s turn"); Console.ReadKey(true); //display opponent's board UserIO.DisplayBoard(board); FireShotResponse response; do { //get coord for shot Coordinate coord = UserIO.GetCoordinates(); //check result response = board.FireShot(coord); DisplayShotStatus(player, response); } while (response.ShotStatus == ShotStatus.Invalid || response.ShotStatus == ShotStatus.Duplicate); return(response.ShotStatus); }
public static void PlaceAllShips(Board board) { foreach (var item in Enum.GetValues(typeof(ShipType))) { while (true) { Console.WriteLine($"Place your {item}"); PlaceShipRequest request = new PlaceShipRequest { Coordinate = UserIO.GetCoordinates(), Direction = PlayerShipDirection(), ShipType = (ShipType)item, }; ShipPlacement response = new ShipPlacement(); response = board.PlaceShip(request); switch (response) { case ShipPlacement.NotEnoughSpace: Console.Clear(); Console.WriteLine($"Could not place {item}: Not enough space.\nPlease try again."); continue; case ShipPlacement.Overlap: Console.Clear(); Console.WriteLine($"Could not place {item}: Ship overlap.\nPlease try again"); continue; case ShipPlacement.Ok: break; } break; } Console.Clear(); } }