0

Hi, Im new to c++ and this site but I have been reading it for the last few weeks to month. I have a problem with a battleship game im trying to finish. Basically I have the random and custom boards working, the function to prevent overlapping and placement off of the grid is also working. The only thing I can't seem to work is the bool function that breaks out of the game loop. Ill post the code that im having the issue with and if more is needed I can add that later. Thanks for any help or direction!

while(true)
{
     _PlayGame(cCompGrid, cHiddenCompGrid);
                     
     _isGameOverForPlayer(cPlayerGrid);
                     
     _compGame(cHiddenPlayerGrid, cPlayerGrid);

     _isGameOverForCpu(cCompGrid); 
}
     cout << "test end" << endl;


bool _isGameOverForPlayer(char cPlayerGrid[10][10])
{
    for(int i = 0; i < 10; ++i)
    {
	for(int j = 0; j < 10; ++j)
	{
	     if (cPlayerGrid[i][j] == 'C' ||   
		cPlayerGrid[i][j] == 'B' ||	
		cPlayerGrid[i][j] == 'S' ||
		cPlayerGrid[i][j] == 'P' ||
		cPlayerGrid[i][j] == 'D' )
		{
		     return true;    
		}    
	}
    }
    return false;
}
       
bool _isGameOverForCpu(char cCompGrid[10][10])
{
     for(int i = 0; i < 10; ++i)
     {
	 for(int j = 0; j < 10; ++j)
	 {
	     if(cCompGrid[i][j] == 'C' ||   
	        cCompGrid[i][j] == 'B' ||	
	        cCompGrid[i][j] == 'S' ||
	        cCompGrid[i][j] == 'P' ||
	        cCompGrid[i][j] == 'D' )    
	        {        
		    return true;       
	        }
          }
      }
	return false;
}

B, C, D, S and P are the characters that represent the ships once they are placed on the grid, * represents a miss and H represents a hit. So far as I can tell I thought this would have worked.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Pascode
0

In lines 3 through 11, I see no 'break' statement. You want something like

if(_isGameOverForXxx(...)) {
  break;
}

don't you?

0

Thanks man, I can't believe I didn't get that. Well it's done now, I owe you one !!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.