public void HandleActions() { while (!Player.IsLost && !AIOpponent.IsLost) { UI.PrintTwoBoards(Player, AIOpponent); UI.PrintComments(); UI.PrintMessage("\nWhich field do you want to shoot?"); bool correctCoordinates = false; bool isShip = true; int[] coordinates; char charRepresentation; while (!correctCoordinates && isShip && !AIOpponent.IsLost) { coordinates = UI.GetPairCoordinates(); correctCoordinates = AIOpponent.IsAlreadyUsed(coordinates); if (correctCoordinates) { AIOpponent.HandleShooting(coordinates); isShip = AIOpponent.Board.CheckIfShip(coordinates); correctCoordinates = false; AIOpponent.CheckIfLost(); if (isShip) { UI.PrintTwoBoards(AIOpponent, AIOpponent); UI.PrintComments(); } } } isShip = true; correctCoordinates = false; while (!correctCoordinates && isShip && !AIOpponent.IsLost && !Player.IsLost) { coordinates = Handler.GetRandomCoordinates(); while (Player.alreadySelected.Any(x => x[0] == coordinates[0] && x[1] == coordinates[1])) { coordinates = Handler.GetRandomCoordinates(); } charRepresentation = Convert.ToChar(('A' + coordinates[1])); UI.AddComment($"\nAI shoots at: {charRepresentation}{coordinates[0] + 1}\n"); Player.alreadySelected.Add(coordinates); correctCoordinates = Player.IsAlreadyUsed(coordinates); if (correctCoordinates) { Player.HandleShooting(coordinates); isShip = Player.Board.CheckIfShip(coordinates); correctCoordinates = false; Player.CheckIfLost(); } } } }
public static List <int[]> GetFullCoordinatesFromShipHead(Ship ship, Space space, int i) { int[] coordinates = { -1, -1 }; bool correctAnswer = false; while (!correctAnswer) { UI.AskForPlacement(ship, i); coordinates = UI.GetPairCoordinates(); if (Validation.IsAnswerValid(coordinates) && !Validation.IsThereAShip(space, ship, coordinates)) { correctAnswer = true; } else { UI.PrintMessage("Please enter valid coordinates. You are too close!"); } } return(Handler.GetFullShipCoordinates(ship, coordinates)); }