public static void PrintBoard(bool isActivePlayer, List <List <Square> > board) { int rowNumber = 1; string rowToPrint; UI.PrintMessage(UI.topLine); UI.PrintMessage(UI.separatorLine); foreach (List <Square> element in board) { if (rowNumber < 10) { rowToPrint = rowNumber.ToString() + UI.longSeparator; } else { rowToPrint = rowNumber.ToString() + UI.shortSeparator; } foreach (Square square in element) { square.updateVisualRepresentation(); if (!isActivePlayer && square.visualRepresentation == UI.notHitShipMark) { rowToPrint += UI.notHitEmptyMark; } else { rowToPrint += square.visualRepresentation; } } UI.PrintMessage(rowToPrint); UI.PrintMessage(UI.separatorLine); rowNumber++; } }
public static int[] GetPairCoordinates() { int[] coordinates = { -1, -1 }; bool correctAnswer = false; while (!correctAnswer) { string userPlacement = Console.ReadLine(); try { coordinates[0] = int.Parse(userPlacement.Substring(1)) - 1; coordinates[1] = Validation.TranslateCoordinates(userPlacement[0]); } catch (FormatException) { UI.PrintMessage("Wrong coordinates format. First enter column letter, than row number. For example \"a1\"."); continue; } catch (ArgumentException error) { UI.PrintMessage(error.Message); continue; } if (Validation.IsAnswerValid(coordinates)) { correctAnswer = true; } else { UI.PrintMessage("You are out of range!"); } } return(coordinates); }