ページ 11

お願いします。

Posted: 2011年1月25日(火) 12:35
by
学校の課題でこれをやっているんですが、間違えているとこがわからないので教えてください。

コード:

#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;

}
}
 }

Re: お願いします。

Posted: 2011年1月25日(火) 12:57
by さかまき
どういう風にまちがえているのかわからないので、教えて下さい。

Re: お願いします。

Posted: 2011年1月25日(火) 12:58
by 初級者
そもそも、どういう仕様のプログラムなんですか?

Re: お願いします。

Posted: 2011年1月26日(水) 15:40
by 先生
掲示板での質問は禁止と言ったはずですよ。