title: Displaying a fruit in snake game
body: <p>I'm trying to make a snake game in which if the snake eats the first fruit and in 2 seconds eats the second fruit then it's score multiplied by 2. If the snake eats the second fruit in 1 second then the score is multiplied by 3. If the snake eats the second fruit in 3 seconds then the score is increased just by 1 and so on ... But i can't display the fruit. I declared the fruit in this function</p>
  <pre><code>void make_stage() {
      for (int i = 1; i &lt;= 17; i++) {
          gotoxy(i, 1);
          printf(&quot;#&quot;);
          gotoxy(1, i);
          printf(&quot;#&quot;);
          gotoxy(17, i);
          printf(&quot;#&quot;);
          gotoxy(i, 17);
          printf(&quot;#&quot;);
      }
      x = height / 2;
      y = width / 2;
  label1:
      fruitx = rand() % 20;
      if (fruitx == 0)
          goto label1;
  label2:
      fruity = rand() % 20;
      if (fruity == 0)
          goto label2;
      score = 0;
      if (i == fruitx)
          printf(&quot;*&quot;);
  }
  </code></pre>
  <p>Does anybody know why the fruit is not visible? Thanks!</p>
  <p>This is my whole code:</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;windows.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;time.h&gt;
  #include&lt;stdlib.h&gt;
  
  int i, j, height = 17, width = 17;
  int score;
  int x, y, fruitx, fruity, flag;
  
  typedef struct RECORD {
      char name[100];
      int score;
      int time;
  }record; //Name, Points,Time
  
  record nowrec;
  
  void gotoxy(int x, int y);          //Input location
  void make_stage();                  //stage
  int getCommand();                   // Keyboard input
  void gameover();                    //Gameover screen
  void startscr();                    //Start screen
  void snake_move();                  //Snake movements
  void rank_call();                   //Displaying rank
  void rankrecord();                  //personal records
  void cursor(int i);             //커서 상태 변경
  void time_show();
  
  int main(void) {
      startscr();
      return 0;
  }
  void gotoxy(int x, int y) {
      COORD pos = { 30 + x * 2, 10 + y };
      SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  }
  
  void make_stage() {
      for (int i = 1; i &lt;= 17; i++) {
          gotoxy(i, 1);
          printf(&quot;#&quot;);
          gotoxy(1, i);
          printf(&quot;#&quot;);
          gotoxy(17, i);
          printf(&quot;#&quot;);
          gotoxy(i, 17);
          printf(&quot;#&quot;);
      }
      x = height / 2;
      y = width / 2;
  label1:
      fruitx = rand() % 20;
      if (fruitx == 0)
          goto label1;
  label2:
      fruity = rand() % 20;
      if (fruity == 0)
          goto label2;
      score = 0;
      if (i == fruitx)
          printf(&quot;*&quot;);
  }
  
  int getCommand() {
      if (_kbhit()) {
          return _getch();
      }
      return -1;
  }
  
  void cursor(int i) {
      CONSOLE_CURSOR_INFO cursorInfo = { 0, };
      cursorInfo.dwSize = 1;
      cursorInfo.bVisible = i;
      SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &amp;cursorInfo);
  }
  
  void rank_call() {
      FILE* rank;
      char reading[100];
      if (fopen_s(&amp;rank, &quot;rank.txt&quot;, &quot;r&quot;) != 0) printf(&quot;no record\n&quot;);
      else {
          printf(&quot;\n&quot;);
          while ((fgets(reading, 100, rank) != NULL)) printf(&quot;%s&quot;, reading);
          fclose(rank);
          printf(&quot;\n&quot;);
      }
  
  }
  
  void rankrecord() {
      printf(&quot;\npress enter to proceed...\n&quot;);
      while (getchar() != '\n');
      printf(&quot;press r to record your ranking...&quot;);
      char input = _getch();
      if (input == 'r') {
          FILE* rank;
          fopen_s(&amp;rank, &quot;rank.txt&quot;, &quot;a&quot;);
          while (getchar() != '\n');
          printf(&quot;enter your name: &quot;);
          gets_s(nowrec.name, sizeof(nowrec.name));
          fprintf(rank, &quot;%s %d %d\n&quot;, nowrec.name, nowrec.score, nowrec.time);
          fclose(rank);
      }
  }
  
  void startscr()
  {
      system(&quot;mode con cols=100 lines=40&quot;);
  start:
      system(&quot;cls&quot;);
      printf(&quot;   ******   **    *       *      *    *  ******           ******      *        **    **    ******   \n&quot;);
      printf(&quot;   *        * *   *      * *     *   *   *                *          * *      *  *  *  *   *        \n&quot;);
      printf(&quot;   ******   *  *  *     *****    ****    ******           *  ***    *****     *  *  *  *   ******   \n&quot;);
      printf(&quot;        *   *   * *    *     *   *   *   *                *    *   *     *   *    **    *  *        \n&quot;);
      printf(&quot;   ******   *    **   *       *  *    *  ******           ******  *       *  *    **    *  ******   \n&quot;);
      printf(&quot;\npress s to start game\n&quot;);
      printf(&quot;press r to see ranking\n&quot;);
      printf(&quot;press x to exit\n:&quot;);
      char input = _getch();
      if (input == 's') {
          system(&quot;cls&quot;);
          cursor(0);
          make_stage();
          snake_move();
      }
      else if (input == 'r') {
          rank_call();
          printf(&quot;press enter to continue...&quot;);
          while (getchar() != '\n');
          goto start;
      }
      else if (input == 'x') exit(0);
      else {
          printf(&quot;wrong input\n&quot;);
          printf(&quot;press enter to continue...&quot;);
          while (getchar() != '\n');
          goto start;
      }
  }
  
  void gameover() {
      system(&quot;cls&quot;);
      printf(&quot;\n\n\n\n\n\n\n\n\n\n&quot;);
      printf(&quot;        ******      *        **    **    ******            ****   *       *  ******   *****         \n&quot;);
      printf(&quot;        *          * *      *  *  *  *   *                *    *   *     *   *        *    *        \n&quot;);
      printf(&quot;        *  ***    *****     *  *  *  *   ******           *    *    *   *    ******   *****         \n&quot;);
      printf(&quot;        *    *   *     *   *    **    *  *                *    *     * *     *        *    *        \n&quot;);
      printf(&quot;        ******  *       *  *    **    *  ******            ****       *      ******   *     *      \n&quot;);
      cursor(1);
      rankrecord();
  }
  
  void snake_move() {
      int x = 9, y = 9;
      int x1 = 8, y1 = 9;
      int x2 = 7, y2 = 9;
      int x3 = 6, y3 = 9;
      int x4 = 5, y4 = 9;
      char dir = 'd';
      char input = 'e';
      gotoxy(x, y);
      printf(&quot;a&quot;);
      gotoxy(x1, y1);
      printf(&quot;*&quot;);
      gotoxy(x2, y2);
      printf(&quot;*&quot;);
      gotoxy(x3, y3);
      printf(&quot;*&quot;);
      gotoxy(x4, y4);
      printf(&quot;*&quot;);
      while (1) {
          input = _getch();
          if ((dir == 'w' &amp;&amp; input != 's') || (dir == 'a' &amp;&amp; input != 'd') || (dir == 's' &amp;&amp; input != 'w') || (dir == 'd' &amp;&amp; input != 'a')) {
              if (input == 'w') {
                  gotoxy(x4, y4);
                  printf(&quot; &quot;);
                  x4 = x3; x3 = x2; x2 = x1; x1 = x;
                  y4 = y3; y3 = y2; y2 = y1; y1 = y;
                  y = y - 1;
                  if (y == 1) {
                      gameover();
                      break;
                  }
                  if (x == x4 &amp;&amp; y == y4) {
                      gameover();
                      break;
                  }
                  gotoxy(x, y);
                  printf(&quot;a&quot;);
                  gotoxy(x1, y1);
                  printf(&quot;*&quot;);
                  gotoxy(x2, y2);
                  printf(&quot;*&quot;);
                  gotoxy(x3, y3);
                  printf(&quot;*&quot;);
                  gotoxy(x4, y4);
                  printf(&quot;*&quot;);
                  dir = 'w';
              }
              if (input == 'a') {
                  gotoxy(x4, y4);
                  printf(&quot; &quot;);
                  x4 = x3; x3 = x2; x2 = x1; x1 = x;
                  y4 = y3; y3 = y2; y2 = y1; y1 = y;
                  x = x - 1;
                  if (x == 1) {
                      gameover();
                      break;
                  }
                  if (x == x4 &amp;&amp; y == y4) {
                      gameover();
                      break;
                  }
                  gotoxy(x, y);
                  printf(&quot;a&quot;);
                  gotoxy(x1, y1);
                  printf(&quot;*&quot;);
                  gotoxy(x2, y2);
                  printf(&quot;*&quot;);
                  gotoxy(x3, y3);
                  printf(&quot;*&quot;);
                  gotoxy(x4, y4);
                  printf(&quot;*&quot;);
                  dir = 'a';
              }
              if (input == 's') {
                  gotoxy(x4, y4);
                  printf(&quot; &quot;);
                  x4 = x3; x3 = x2; x2 = x1; x1 = x;
                  y4 = y3; y3 = y2; y2 = y1; y1 = y;
                  y = y + 1;
                  if (y == 17) {
                      gameover();
                      break;
                  }
                  if (x == x4 &amp;&amp; y == y4) {
                      gameover();
                      break;
                  }
                  gotoxy(x, y);
                  printf(&quot;a&quot;);
                  gotoxy(x1, y1);
                  printf(&quot;*&quot;);
                  gotoxy(x2, y2);
                  printf(&quot;*&quot;);
                  gotoxy(x3, y3);
                  printf(&quot;*&quot;);
                  gotoxy(x4, y4);
                  printf(&quot;*&quot;);
                  dir = 's';
              }
              if (input == 'd') {
                  gotoxy(x4, y4);
                  printf(&quot; &quot;);
                  x4 = x3; x3 = x2; x2 = x1; x1 = x;
                  y4 = y3; y3 = y2; y2 = y1; y1 = y;
                  x = x + 1;
                  if (x == 17) {
                      gameover();
                      break;
                  }
                  if (x == x4 &amp;&amp; y == y4) {
                      gameover();
                      break;
                  }
                  gotoxy(x, y);
                  printf(&quot;a&quot;);
                  gotoxy(x1, y1);
                  printf(&quot;*&quot;);
                  gotoxy(x2, y2);
                  printf(&quot;*&quot;);
                  gotoxy(x3, y3);
                  printf(&quot;*&quot;);
                  gotoxy(x4, y4);
                  printf(&quot;*&quot;);
                  dir = 'd';
              }
          }
          if (input == 'p') {
              gameover();
              break;
          }
      }
  }
  void time_show() {   //아직 미완성(not completed) 
      clock_t s, n;
      s = clock();
  
      while (1) {
          while (1) {
              n = clock();
              printf(&quot;\r&quot;);               //커서 왼쪽 끝으로 이동(스테이지의 위치에 따라 수정할 예정)
              printf(&quot;Time-\t %d : %d : %d &quot;, ((n - s) / 1000) / 60, ((n - s) / 1000) % 60, (n - s) % 1000);
              if (_kbhit()) break; //키보드 입력이 들어오면 break;
          }
  
          if (_getch() == 'p') {          //만약 그것이 p이면
              printf(&quot;\rTime-\t %d : %d : %d &quot;, ((n - s) / 1000) / 60, ((n - s) / 1000) % 60, (n - s) % 1000);
              _getch();
          }
          else break;
  
          s = s + (clock() - n);
  
      }
  
      printf(&quot;\rTime-\t %d : %d : %d &quot;, ((n - s) / 1000) / 60, ((n - s) / 1000) % 60, (n - s) % 1000);
  
      _getch(); _getch();
      printf(&quot;\n\n\n&quot;);
  
      return;
  }
  </code></pre>