Hi,
I was about to create a 8x8 battleship program.
there should be 8 ships in total with 1x1 size.
However, I do not know how to place the ships randomly.
Below are some of the codes that I started after doing some research
[code=cpp]#include <iostream>
#include <windows.h>
using namespace std;
// create the boards as global arrays (accessible to ALL functions!)
char PlayerBoard[8][8] = { { 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' }
};
char ComputerBoard[8][8] = { { 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' }
};
// 'w' == water
// 'S' == ship
// 'x' == missed, hit water
// 'o' == hit, hit sunk ship
void placeShipsRando mly();
void printBoards();
void placeShipsRando mly()
{
}
void printBoards()
{
}[/code]
Any help will be so appreciated...T hank you so much
Olivia
I was about to create a 8x8 battleship program.
there should be 8 ships in total with 1x1 size.
However, I do not know how to place the ships randomly.
Below are some of the codes that I started after doing some research
[code=cpp]#include <iostream>
#include <windows.h>
using namespace std;
// create the boards as global arrays (accessible to ALL functions!)
char PlayerBoard[8][8] = { { 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' }
};
char ComputerBoard[8][8] = { { 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' },
{ 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w' }
};
// 'w' == water
// 'S' == ship
// 'x' == missed, hit water
// 'o' == hit, hit sunk ship
void placeShipsRando mly();
void printBoards();
void placeShipsRando mly()
{
}
void printBoards()
{
}[/code]
Any help will be so appreciated...T hank you so much
Olivia
Comment