I have an assignment due tommorrow (out of 4 others) that I just haven't been able to grasp.
The aim is to write a C++ program to play a simplified version of battleships. This involves using a single dimensional array length of 30 for the playing board of 0s and 1s. And two sizes of ship, 1 (6of) and 2 (3of), placed randomly on the board. Then just a 'Hit' and 'Miss' system. Once the games over it should tell the player how many guesses it took them.
If there is anyone who could lend a hand I would be extreamly greatful!
int main(int argc, char ** argv)
{
bool board[30];
int count = 0;
int x;
bool gameEnd = false;
int guess;
for (int i=0; i<30; i++) { board[i]=false; }
for(int i=0;i<=6;i++)
{
board[rand()%30+1]=true;
}
for(int i=0;i<=2;i++)
{
x=rand()%29+1;board[x]=1; board[x+1]=1; //then make it 29 so you don't go over, faggot
board[31] and crash.. needs to be fixed.
}
do
{
cout<<"pick a number between 1 and 30: ";
cin >> guess;
if(board[guess])
{
cout<<"HIT!\n";
board[guess] = false;
cout << "You have been trolled " << count << " times.":
}
else
{
cout<<"MISS!\n";
cout << "You have been trolled " << count << " times.":
}
count ++;
}
int checker;
for (int count =0; count < 30; count++)
{
if (board[count])
checker++;
if (checker == 30)
gameEnd = true;
}
while(count<100 && gameEnd == False);
}
cout << " It took you "<< count << "tries [spoiler]IHBT[/spoiler]";
return yourAFaggot;
I didn't even try to compile it, if yo can't get it to work using this skeleton, you're a faggot.