// this was used for testing purposes public static void AutoPlaceShips(Board board) { int i = 1; foreach (ShipType ship in Enum.GetValues(typeof(ShipType))) { PlaceShipRequest request = new PlaceShipRequest() { Coordinate = new Coordinate(1, i), Direction = ShipDirection.Right, ShipType = ship, }; i++; board.PlaceShip(request); board.UpdateBoardImg(); } }
// Prompt user to place a ship on their board. public static void Place(Board board, string playerName, ShipType ship) { BoardImage.Present(board, playerName + "'s setup turn"); ShipPlacement placementResult; do { // prompt for coord and direction while listing ship and ship size int[] coords = Prompt.Coord($"{ship} ({_shipDict[ship]})\t"); ShipDirection direction = DirectionPrompt(); // create ship request var request = new PlaceShipRequest() { Coordinate = new Coordinate(coords[0], coords[1]), Direction = direction, ShipType = ship, }; // request a ship placement placementResult = board.PlaceShip(request); Console.Clear(); if (placementResult == ShipPlacement.NotEnoughSpace) { BoardImage.Present(board, playerName + "'s setup turn"); ConsoleWriter.Write("\t\t\t*** Not enough space. Try again. ***", 10, ConsoleColor.Red); } else if (placementResult == ShipPlacement.Overlap) { BoardImage.Present(board, playerName + "'s setup turn"); ConsoleWriter.Write("\t\t*** Another ship is already there. Try again. ***", 10, ConsoleColor.Red); } } while (placementResult != ShipPlacement.Ok); // loop until ship placement is valid board.UpdateBoardImg(); // update board image to reflect placed ships }