gpt4 book ai didi

C中连接四个游戏板

转载 作者:太空宇宙 更新时间:2023-11-04 08:44:16 27 4
gpt4 key购买 nike

我正在编写一个程序,允许用户在计算机上玩四人连线游戏。我无法打印出电路板的正确尺寸。我尝试使用嵌套的 for 循环,但输出有点偏差。这是我的代码的一部分:

#include <stdio.h>

#define BOARD_SIZE_VERT 6
#define BOARD_SIZE_HORIZ 7

void display_board(int board[] [BOARD_SIZE_VERT]);

int main ()
{
int board[BOARD_SIZE_HORIZ][BOARD_SIZE_VERT] = {{0}};
display_board(board);
return 0;

}


void display_board(int board[] [BOARD_SIZE_VERT])
{
int i,j;

for (i=0; i<BOARD_SIZE_HORIZ; i++) {
printf ("+---+---+---+---+---+---+---+");
printf ("\n");
for (j=0; j<BOARD_SIZE_VERT; j++)
printf ("| ");
printf("\n");
}
}

这是我的输出:

+---+---+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+---+---+
| | | | | |

这就是我想要的样子:

+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+

最佳答案

void display_board(int board[] [BOARD_SIZE_VERT]){
int i,j;

for (i=0; i<BOARD_SIZE_VERT; i++) {
printf ("+");
for (j=0; j<BOARD_SIZE_HORIZ; j++)
printf("---+");
printf ("\n");
printf ("|");
for (j=0; j<BOARD_SIZE_HORIZ; j++)
printf(" |");
printf ("\n");
}

printf ("+");
for (j=0; j<BOARD_SIZE_HORIZ; j++)
printf("---+");
printf ("\n");
}

关于C中连接四个游戏板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290174/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com