public static void showPosibleDirection(int row, int col, int boatLen, String[]direction)
if (row >= (boatLen - 1))
Console.WriteLine("\n- Top");
Console.WriteLine("\n- Bottom");
direction[i++] = "Bottom";
if (col >= (boatLen - 1))
Console.WriteLine("\n- Left");
Console.WriteLine("\n- Right");
direction[i++] = "Right";
public static bool checkDirectionValidity(String[]allOptions, String directionChose)
foreach (String elem in allOptions)
if (string.Compare(elem, directionChose) == 0)
public static bool checkValidityPlacement(int row, int col, int boatLen, String Direction, int[,]Table)
int lockX, lockY, checkValiditySpaceX, checkValiditySpaceY, moveX;
checkValiditySpaceY = boatLen + 2;
while (checkValiditySpaceY > 0 || lockY >= 0)
while (checkValiditySpaceX > 0 || moveX <= 9 || moveX <= col + 1)
if (Table[moveX,lockY] != 0)
public static void placeBoat(int boatLen, int[,]Table, int numOfBoat)
String[]directionPosibility = new String[4];
Console.WriteLine("Position the " + boatLen + " place boat :");
Console.Write("Row coordinate:");
row = int.Parse(Console.ReadLine());
Console.Write("Col coordinate:");
col = int.Parse(Console.ReadLine());
while ((row < 0 || row > 9) || (col < 0 || col > 9))
Console.WriteLine("Sorry one of the coordinate is not correct..");
Console.WriteLine("Please enter coordinate between 0 and 9 include :");
Console.Write("Row coordinate:");
row = int.Parse(Console.ReadLine());
Console.Write("Col coordinate:");
col = int.Parse(Console.ReadLine());
showPosibleDirection(row, col, 5, directionPosibility);
Console.Write("Choose the direction :");
answerDirection = Console.ReadLine();
while (checkDirectionValidity(directionPosibility, answerDirection) == false)
Console.WriteLine("Sorry the direction you selected is not valid..");
Console.WriteLine("Please choose between the proposed direction!!");
showPosibleDirection(row, col, 5, directionPosibility);
Console.Write("Choose the direction :");
answerDirection = Console.ReadLine();
}while (checkValidityPlacement(row, col, boatLen, answerDirection, Table) == false);
if (answerDirection == "Top")
while (numPlaceBoat < boatLen)
Table[row,col] = numOfBoat;
else if (answerDirection == "Bottom")
while (numPlaceBoat < boatLen)
Table[row,col] = numOfBoat;
else if (answerDirection == "Left")
while (numPlaceBoat < boatLen)
Table[row,col] = numOfBoat;
else if (answerDirection == "Right")
while (numPlaceBoat < boatLen)
Table[row,col] = numOfBoat;
showTable(Table, 10, 10);
public static void createTablePlayer(int[,]Table, int maxRow, int maxCol, String name)
public static void createTableComputer(int[,]Table, int maxRow, int maxCol, String name)
public static void showTable(int[,]Table, int maxRow, int maxCol)
Console.Write("\n " + count++);
Console.Write(" " + count++);
Console.Write(" " + row);
Console.Write(" " + Table[row, col]);
Console.WriteLine(" \n");
public static void showTitle()
Console.WriteLine(" ---------------");
Console.WriteLine(" | BATTLESHIPS |");
Console.WriteLine(" ---------------\n\n");
public static void gameManager()
Console.WriteLine("Do you want to start a run (Y/N)??");
answer = Char.Parse(Console.ReadLine());
if ('Y' == answer || 'y' == answer)
Console.WriteLine("Who is your ennemi ??");
Console.WriteLine("1. Player");
Console.WriteLine("2. Computer");
Console.WriteLine("0. Exit");
Console.Write("Choice :");
mode = int.Parse(Console.ReadLine());
int[,] Player1 = new int[10, 10];
int[,] Player2 = new int[10, 10];
createTablePlayer(Player1, 10, 10, "Player1");
createTablePlayer(Player2, 10, 10, "Player2");
int[,] Player1 = new int[10, 10];
int[,] Bot = new int[10, 10];
createTablePlayer(Player1, 10, 10, "Player1");
createTableComputer(Bot, 10, 10, "Player2");
Console.WriteLine(" BYE !!!");
Console.WriteLine("Not valid answer ");
Console.WriteLine("Please try again ");
mode = int.Parse(Console.ReadLine());
public static void Main()