public void CanNotOverlapShips() { Board board = new Board(); // let's put a carrier at (10,10), (9,10), (8,10), (7,10), (6,10) var carrierRequest = new PlaceShipRequest() { Coordinate = new Coordinate(10, 10), Direction = ShipDirection.Left, ShipType = ShipType.Carrier }; var carrierResponse = board.PlaceShip(carrierRequest); Assert.AreEqual(ShipPlacement.Ok, carrierResponse); // now let's put a destroyer overlapping the y coordinate var destroyerRequest = new PlaceShipRequest() { Coordinate = new Coordinate(9, 9), Direction = ShipDirection.Down, ShipType = ShipType.Destroyer }; var destroyerResponse = board.PlaceShip(destroyerRequest); Assert.AreEqual(ShipPlacement.Overlap, destroyerResponse); }
private Board BoardCreated(String playerName) { Board gameBoard = new Board(); //ShipType placeship = new ShipType(); for (ShipType s = ShipType.Carrier; s >= ShipType.Destroyer; s--) { PlaceShipRequest request = new PlaceShipRequest(); request.Coordinate = ConsoleInput.GetCoordinate(); request.Direction = ConsoleInput.GetDirection(); request.ShipType = s; var placement = gameBoard.PlaceShip(request); if (placement == ShipPlacement.Overlap) { ConsoleOut.OverLapping(); s++; } else if (placement == ShipPlacement.NotEnoughSpace) { ConsoleOut.NotEnoughSpace(); s++; } // else // ConsoleOut.EnoughSpace(); } return(gameBoard); }
public void CanNotPlaceShipPartiallyOnBoard() { Board board = new Board(); PlaceShipRequest request = new PlaceShipRequest() { Coordinate = new Coordinate(10, 10), Direction = ShipDirection.Right, ShipType = ShipType.Carrier }; var response = board.PlaceShip(request); Assert.AreEqual(ShipPlacement.NotEnoughSpace, response); }
public void CanNotPlaceShipOffBoard() { Board board = new Board(); PlaceShipRequest request = new PlaceShipRequest() { Coordinate = new Coordinate(15, 10), Direction = ShipDirection.Up, ShipType = ShipType.Destroyer }; var response = board.PlaceShip(request); Assert.AreEqual(ShipPlacement.NotEnoughSpace, response); }
// 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(); } }
private void SetUp() { for (var i = 0; i < 5; i++) { do { Coordinate coord = AskCoordinate(); ShipDirection direction = AskDirection(); ShipType type = AskShipType(); PlaceShipRequest req = new PlaceShipRequest(); req.Coordinate = coord; req.Direction = direction; req.ShipType = type; ShipPlacement sp = p1board.PlaceShip(req); if (sp == ShipPlacement.NotEnoughSpace) { Console.WriteLine("Not enough space to put a ship there! Try again!\n"); nextShip = false; } else if (sp == ShipPlacement.Overlap) { Console.WriteLine("That ship would overlap one you already placed! Try again!\n"); nextShip = false; } else // shipplacement.ok { nextShip = true; } } while (!nextShip); } Console.Clear(); Console.WriteLine("{0}'s turn!!", player2name); for (int i = 0; i < 5; i++) { do { Coordinate coord = AskCoordinate(); ShipDirection direction = AskDirection(); ShipType type = AskShipType(); PlaceShipRequest req = new PlaceShipRequest(); req.Coordinate = coord; req.Direction = direction; req.ShipType = type; ShipPlacement sp = p2board.PlaceShip(req); if (sp == ShipPlacement.NotEnoughSpace) { Console.WriteLine("Not enough space to put a ship there! Try again!"); nextShip = false; } if (sp == ShipPlacement.Overlap) { Console.WriteLine("That ship would overlap one you already placed! Try again!"); nextShip = false; } else // shipplacement.ok { nextShip = true; } } while (!nextShip); } Console.Clear(); }
private void PlaceSubmarine(Board board) { var request = new PlaceShipRequest() { Coordinate = new Coordinate(3, 5), Direction = ShipDirection.Left, ShipType = ShipType.Submarine }; board.PlaceShip(request); }
private void PlaceDestroyer(Board board) { var request = new PlaceShipRequest() { Coordinate = new Coordinate(1,8), Direction = ShipDirection.Right, ShipType = ShipType.Destroyer }; board.PlaceShip(request); }
private void PlaceCruiser(Board board) { var request = new PlaceShipRequest() { Coordinate = new Coordinate(3, 3), Direction = ShipDirection.Up, ShipType = ShipType.Cruiser }; board.PlaceShip(request); }
private void PlaceCarrier(Board board) { var request = new PlaceShipRequest() { Coordinate = new Coordinate(4,4), Direction = ShipDirection.Right, ShipType = ShipType.Carrier }; board.PlaceShip(request); }
private void PlaceBattleship(Board board) { var request = new PlaceShipRequest() { Coordinate = new Coordinate(10, 6), Direction = ShipDirection.Down, ShipType = ShipType.Battleship }; board.PlaceShip(request); }
// 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 }