我在一个正在编程宾果游戏的项目(在C中)的中间,并且需要做的最后一个功能是检查是否有宾果游戏的功能。我有一个5 x 5生成的随机数数组,我通过用户输入生成一个随机数。如何使数组将该数字(如果实际上在数组中)更改为0,然后通过用户输入检查是否有宾果游戏?
这是生成数组的代码
for (int row = 0; row < 5; row++) {
for(int column = 0; column < 5; column++) {
if(row == 2 && column == 2) {
board[row][column] = 0;
} else {
int num = rand() %15 + 1 +(column * 15);
for(int i = 0; i < 75; i++) {
if(num == used[i]) {
num = rand() %15 + 1 +(column * 15);
}
}
board[row][column] = num;
used[used_counter] = num;
used_counter++;
}
}
}
int generate_number(int boneyard[75], int *boneyard_counter) {
int num = rand() %75 + 1;
for (int i = 0; i <75; i++){
if(num == boneyard[i]);
num = rand() %75 + 1;
}
boneyard[*boneyard_counter] = num;
boneyard_counter++;
return num;
}
这是生成随机数的代码。
答案 0 :(得分:0)
您将执行以下操作:
int found_match = 0;
for(int row = 0; row < 5; ++row){
for(int column = 0; column < 5; ++column){
if(board[row][column] == num){
board[row][column] = 0;
found_match = 1;
goto loop_end;
}
}
}
loop_end:
if(found_match){
/*
Check all diagonals, rows, and columns to see if any one of them contains only zeroes,
stopping if you find that a diagonal/row/column that does in fact contain only zeroes
and informing the player that they've won.
*/
}