我一直在为 naughts and crosss 程序做一些编程,而电路板是一个 2D 数组。如果用户想要重播,我一直在尝试使程序重复,但是我注意到重复时所有值都保留在数组中。所以我想知道是否有办法清除我数组中的所有值。
我确实在论坛上尝试了一些以前的问题,但是我发现的一些解决方案似乎不起作用。
如果有人想查看代码,只需发表评论,我会在此处添加,我只是不确定是否有必要。
任何帮助将非常感激。
const int Rows = 4;
const int Columns = 4;
char Board[Rows][Columns] = { {' ', ' ', ' ', ' ' },
{' ', '_', '_', '_' },
{' ', '_', '_', '_' },
{' ', '_', '_', '_' } };
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
cout << endl << endl;
int row;
int column;
do
{
cout << "Please enter the value of the row you would like to take ";
cin >> row;
}while (row != 0 && row != 1 && row != 2 && row != 3);
do
{
cout << "Please enter the value of the column you would like to take ";
cin >> column;
}while (column != 0 && column != 1 && column != 2 && column != 3);
Board [row][column] = Player1.GetNorX();
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}