我正在使用5x5二维数组进行简化的扫雷游戏。我的部分教学是制作这样的功能:创建扫雷游戏
该函数的取值介于1到25之间,并将该值转换为行列位置。您将需要使用参考参数来完成此操作。
我该如何做到这一点?
这是到目前为止我的代码:
int main()
{
int input;
char array[5][5];
initBoard(array, 5);
populateBombs(array, 5);
cout << "Enter a value between 1 and 25 to check a space " << endl;
cin >> input;
printBoard(array, 5);
cout << endl;
return 0;
}
void initBoard(char ar[][5], int size)
{
for (int row = 0; row < 5; row++)
{
for (int col = 0; col < size; col++)
{
ar[row][col] = 'O';
}
}
}
void printBoard(const char ar[][5], int size)
{
for (int row = 0; row < size; row++)
{
for (int col = 0; col < 5; col++)
{
cout << ar[row][col] << "\t";
}
cout << endl;
}
}
问题的第二部分是创建一个“populateBomb”功能,我需要随机填充5位有炸弹。我必须用'*'字来表示炸弹。我可以利用任何技术来解决这些问题?