#include <stdio.h>
#include <stdlib.h>
#define XSIZE 16
#define YSIZE 12
int x, y; //x,yを定義
struct masu {
int p; //pを定義
int right; //rightを定義
int bottom; //bottomを定義
};
struct masu board[XSIZE][YSIZE];
void print_board()
{
int i, j;
system("cls"); /* windowsではsystem("cls");、macではsystem("clear"); */
for (j=0; j<YSIZE; j++){
printf("+---");
printf("+\n");
for (i=0; i<XSIZE; i++) {
printf("|");
for (j=0; j<YSIZE; j++) {
if (i == x && j == y) printf("you");
else if (board[i][j].p == 1) printf(" o ");
else printf(" ");
if (j==YSIZE-1 || board[i][j].right == 1) printf("|");
else printf(" ");
}
printf("\n");
for (j=0; j<YSIZE; j++) {
printf("+");
if (i==XSIZE-1 || board[i][j].bottom == 1) printf("---");
else printf(" ");
}
printf("+\n");
}
printf("\n");
}
void initialize()
{
int i, j;
//srandom(time(NULL));
for (i=0; i<XSIZE; i++) {
for (j=0; j<YSIZE; j++) {
board[i][j].right = 0;
board[i][j].bottom = 0;
if (rand() % 3 == 0) board[i][j].right = 1;
if (rand() % 3 == 0) board[i][j].bottom = 1;
board[i][j].p = 1;
}
}
}
int main()
{
char input;
initialize();
x = 0;
y = 0;
board[x][y].p = 0;
while (1) {
print_board();
if (x == XSIZE && y == YSIZE);{ break;}
printf("input(2,3,4,5)> ");
scanf("%c", &input);
printf("\n");
if (input == '2'){
x=x-1;
}
else if (input == '3'){
y=y-1;
}
else if (input == '4'){
x=x+1;
}
else if (input == '5'){
y=y+1;
}
else{
}
board[x][y].p = 0;
}
printf("goal!!\n");
return 0;
}
}
}
お願いします。
お願いします。
学校の課題でこれをやっているんですが、間違えているとこがわからないので教えてください。