please look at this code for battleship, look at the 'u' and 'd' part. something goes wrong there, if a ship would, under correct circumstances, block you from putting a ship in a certain direction it will just overwrite whats there. the 'l' and 'r' work fine, but not the 'u' and 'd'. left, right, up, down, you get it.
Code:
do
{
if(test==0) cout<<"Invalid direction, please re-enter the info."<<endl<<endl;
test=1;
cout<<"Now choose which direction to finish the ship in (l,r,u,d): ";
cin>>dir;
switch(dir)
{
case 'l':
if(col-size>=1)
{
for(int i=0;i<=size-1;i++)
{
if(board[row][col-i]!='~')
{
test=0;
continue;
}
}
}
else
{
test=0;
continue;
}
if(test=1)
{
for(int x=0;x<=size-1;x++)
{
board[row][col-x]=ship[0];
}
}
break;
case 'r':
if(col+size<=10)
{
for(int i=0;i<=size-1;i++)
{
if(board[row][col+i]!='~')
{
test=0;
continue;
}
}
}
else
{
test=0;
continue;
}
if(test=1)
{
for(int x=0;x<=size-1;x++)
{
board[row][col+x]=ship[0];
}
}
break;
case 'u':
if(row-size<=1)
{
for(int i=0;i<=size-1;i++) //error here, i think
{
if(board[row-i][col]!='~')
{
test=0;
continue;
}
}
}
else
{
test=0;
continue;
}
if(test=1)
{
for(int x=0;x<=size-1;x++)
{
board[row-x][col]=ship[0];
}
}
break;
case 'd':
if(row+size<=10)
{
for(int i=0;i<=size-1;i++) //error here, i think
{
if(board[row+i][col]!='~')
{
test=0;
continue;
}
}
}
else
{
test=0;
continue;
}
if(test=1)
{
for(int x=0;x<=size-1;x++)
{
board[row+x][col]=ship[0];
}
}
}
}while(test==0);