public void FireShotAtBoard(Player target) { do { Console.WriteLine($"It's time to shoot, {_name}."); int row = ConsoleInput.GetRowCoordinateFromUser(); int column = ConsoleInput.ColumnCoordinateFromUser(); var coordinate = new Coordinate(row, column); var response = target.board.FireShot(coordinate); switch (response.ShotStatus) { case ShotStatus.Invalid: Console.WriteLine("That's not a valid coordinate. Please try again."); notDuplicate = false; break; case ShotStatus.Duplicate: Console.WriteLine("You already shot there, try a different space."); notDuplicate = false; break; case ShotStatus.Miss: Console.WriteLine($"Sorry, {_name} you missed."); notDuplicate = true; break; case ShotStatus.Hit: Console.WriteLine($"You hit a ship!"); notDuplicate = true; break; case ShotStatus.HitAndSunk: Console.WriteLine($"You hit and sunk {response.ShipImpacted}"); notDuplicate = true; break; case ShotStatus.Victory: Console.WriteLine($"Congratulations {_name} have sunk all the ships and won the game!!!"); _wonGame = true; break; } } while (!notDuplicate); }
public void PlaceShipOnBoard() { int row; int column; ShipDirection direction; for (int i = 0; i < 5; i++) { do { ShipType currentShip = (ShipType)i; Console.WriteLine($"{_name} let's place the " + currentShip); row = ConsoleInput.GetRowCoordinateFromUser(); column = ConsoleInput.ColumnCoordinateFromUser(); direction = ConsoleInput.GetDirectionFromUser(); PlaceShipRequest request = new PlaceShipRequest() { Coordinate = new Coordinate(row, column), Direction = direction, ShipType = currentShip, }; var response = board.PlaceShip(request); if (response == ShipPlacement.NotEnoughSpace) { Console.WriteLine("There was not enough space to place the ship."); } if (response == ShipPlacement.Overlap) { Console.WriteLine("That overlaps with another ship."); } if (response == ShipPlacement.Ok) { break; } } while (true); } }