Generation

generate functionWed, 14 Dec 2022

randomly place battleship ships on a 8 by 8 grid using a list<t>

public void placeShip(int[,] gameboard) { // Randomly place ships on the gameboard Random rnd = new Random(); int max = 7; int min = 0; bool placed = false; int i = 0; while (i < 5) { int row = rnd.Next(min, max); int col = rnd.Next(min, max); if (gameboard[row, col] == 0) { gameboard[row, col] = 1; i++; } } }

Questions about programming?Chat with your personal AI assistant