我正在制作一个跳棋游戏,我想打印出角色' x'和' o'进入2d阵列。但是我的代码不起作用,而是打印出不同的字符。我需要帮助。
这是我的代码:
#include <stdio.h>
void message()
{
char name[20],name2[20];
printf("Please enter the name for the first player : ");
scanf("%s", &name);
printf("Please enter the name for the second player : ");
scanf("%s", &name2);
printf("\nGood day %s and %s, let's start the game....all the best!!!\n\n", name, name2);
}
int gameboard(char board[8][8])
{
int x, y;
for(x=0; x<8; x++)
{
for(y=0; y<8; y++)
{
printf("|%c ");
}
printf("|\n\n");
}
}
void character(char board[8][8])
{
int i,j;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
if(i<3){
if(i%2 == 0){
if(j%2 == 0){
board[i][j] = ' ';
}
if(j%2==1){
board[i][j]= 'O';
}
}
if(i%2 == 1){
if(j%2 == 0){
board[i][j] = 'O';
}
if(j%2 ==1){
board[i][j]= ' ';
}
}
}
if((i==3) || (i==4))
{board[i][j] = ' ';}
if(i>4)
{
if(i%2 == 0){
if(j%2 == 0){
board[i][j] = ' ';
}
if(j%2 ==1){
board[i][j]= 'X';
}
}
if(i%2 == 1){
if(j%2 == 0){
board[i][j] = 'X';
}
if(j%2 ==1){
board[i][j]= ' ';
}
}
}
}
}
}
int main()
{
int x, y;
char bx[8][8];
message();
gameboard(bx);
character(bx);
return 0;
}
答案 0 :(得分:0)
需要更改character(bx)
和gameboard(bx)
的顺序,以便在打印之前设置数组中的值。
按照以下步骤修改游戏板功能,以显示特定元素的值:
int gameboard(char board[8][8])
{
...
printf("|%c ",board[x][y]);
...
}