我正在用 C++ 编写战舰游戏。我已将值设置如下。
//const int empty = 0; // contains water
//const int occupied = 1; // contains a ship
//const int missed = 2; // shot into ocean W
//const int shot = 3; // ship is shot down H
//const int shipdown = 4; // whole ship is shot down S
当用户击中船时,该值从 1 变为 3。我面临的问题是如何指示整艘船都倒下了。
int Grid[64];
int currentSquareValue = Grid[(row-1)*8+(column-1)];
switch(currentSquareValue)
{
case 0:
Grid[(row-1)*8+(column-1)] = 2;
break;
case 1:
Grid[(row-1)*8+(column-1)] = 3;
break;
default:
break;
}
//Printing out the Grid
for(int i = 0 ; i <=8; i++)
{
//Print Row Header
if(i != 0) cout << i << char(179);
for(int j = 0; j <= 8; j++)
{
if(i == 0)
{
//Print Column Header
cout << j << char(179);
}
else
{
//Avoid the first row and column header
if(j > 0 && i > 0)
{
int currentSquareValue = Grid[(i-1)*8+(j-1)];
switch(currentSquareValue)
{
case 0:
cout << " " << char(179);
break;
case 1:
cout << " " << char(179);
break;
case 2:
cout << "W" << char(179);
break;
case 3:
cout << "H" << char(179);
break;
case 4:
cout << "S" << char(179);
break;
default:
break;
}
}
}
}
我已经完成了被击中的船,但我不确定如何表明在第三次射击后整艘船被击落,如下所示:
需要一些指导......不知道如何开始......