Hi, so far iv been able to create an 2d array, and I also have a random number generator. I think I have been able to place a ship of 1 length by using my random generator on my 2d array.
I would like to know how would I make the ships bigger, I need a ship of length 2,3,4 and 5 for my game. I would like to use the starting coordinate from my random number generator to place the first part of the ship, I would like to know how I can place the rest of the ship.
Thank you =)
First choose the size and orientation of the ship by defining variables width, height (one of them will be 1)
Then generate coordinates x and y that are in range 10-width and 10-height (so that your ship doesn't go out of the array). Then for i from 0 to length of your ship, fill board[x+i][y] if the ship is horizontal or board[x][y+i] if it is vertical.