This is what I have so far but with only one battleship now I have to do the following:
Add a second boat to the board. You must make sure that the two boats are not in the same location before the game starts. Write a function called place_boats to find locations for the two boats. The player must now find both boats in order to win the game.
Ps the 'B' is for debugging.
and can someone give me ideas on what to do next I am really stuck... I would appreciate your help
Thanks
Well we could use more information then just help ;p. What are you stuck on exactly? The assignment tells you exactly what to do next so you shouldn't be stuck on that.
Basically you need to write the place_boats() function. In this function you are going to place 2 boats onto the board randomly I am guessing (Didn't give much info on this). You will need to make sure that you don't place a boat on a location that already has a boat so you will need to check that.
Basically select a random location within your multi demesional array to place the first boat on.
After you have placed the first boat do the same with the second boat (Select a random location within your array) but this time before you place it do a check to make sure there is not already a boat on that space, if there is generate another random location if there isn't place the boat on that location.
Example for the check.
1 2 3 4 5 6 7 8 9 10 11
// [i][j] represents the randomly selected element in the array where you want
// to place the boat.
if (array[i][j] == 'B')
{
// Generate a new element randomly and do the check again
}
else
{
// Place the boat on that element if there isn't a boat on there already
array[i][j] = 'B';
}
That should give you what you need to do.
Also Catfish its in a single letter like this is his board.
Decided to be nice to ya and give you most of the function. You will still need to make it work and get the rest of the program to work with it though ;p.
void place_boats(char boat[][S], constint boatsToPlace)
{
// This will keep track of how many boats have been placed
int boatsPlaced = 0;
while (boatsPlaced != boatsToPlace) // Determines how many boats to place
{
// Something here. Hint: It getting a random number for the multi array
// Something here. Hint: Same as the above comment
if (boat[i][j] == 'B')
continue;
else
{
boat[i][j] = 'B';
++boatsPlaced;
}
}
}
Added another parameter so in the future you can make it easier to place more then 2 boats.