home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_10 / 8n10130a < prev    next >
Text File  |  1990-08-29  |  4KB  |  157 lines

  1. #include "csim.h"
  2. #include   <bios.h>
  3. #include   <conio.h>
  4. #include <graphics.h>
  5. #include   <stdio.h>
  6. #include   <stdlib.h>
  7. #include   <time.h>
  8.  
  9. void      mover(void);
  10. void      ender(void);
  11.  
  12. int      color = 1;
  13. int      maxx,maxy;
  14.  
  15. int      main(void)
  16.    {
  17.       int   loop;
  18.       int   gr_driver,gr_mode,gr_error;
  19.  
  20.       clrscr();
  21.       randomize();
  22.  
  23.       for(loop = 0;loop < 4;loop++)
  24.          if(start_process(mover,0x0080))
  25.             exit_processing(loop);
  26.  
  27.       if(start_kb_process(ender,0x0040))
  28.          exit_processing(3);
  29.  
  30.       gr_driver = DETECT;
  31.       gr_mode = VGAHI;
  32.  
  33.       initgraph(&gr_driver,&gr_mode,"");
  34.       gr_error = graphresult();
  35.       if (gr_error != 0)
  36.          {
  37.             printf("%s \n",grapherrormsg(gr_error));
  38.             exit(1);
  39.          }
  40.       maxx = getmaxx();
  41.       maxy = getmaxy();
  42.  
  43.       sim_start();
  44.       return(0);
  45.    }
  46.  
  47. void   mover(void)
  48.    {
  49.       int   mycolor;
  50.       int   x,y,oldx,oldy,dir;
  51.       if(color == 7)
  52.          color += 2;
  53.       mycolor = color++;
  54.       color %= 16;
  55.       if(color == 0)
  56.          color++;
  57.       x = oldx = (rand() % (maxx-10)) + 5;
  58.       y = oldy = (rand() % (maxy-10)) + 5;
  59.       dir = rand() % 4;
  60.       while(1)
  61.          {
  62.             switch(rand()%6)
  63.                {
  64.                   case   0:
  65.                      dir+=7;
  66.                      dir = dir % 8;
  67.                      break;
  68.                   case  1:
  69.                      dir++;
  70.                      dir = dir % 8;
  71.                      break;
  72.                   case  2:
  73.                      dir+=2;
  74.                      dir = dir % 8;
  75.                      break;
  76.                   case  3:
  77.                      dir+=6;
  78.                      dir = dir % 8;
  79.                      break;
  80.                   default:
  81.                      break;
  82.  
  83.                }
  84.             switch(dir)
  85.                {
  86.                   case 0:
  87.                      x += 4;
  88.                      if(x>(maxx-5))
  89.                         dir = 4;
  90.                      break;
  91.                   case 1:
  92.                      y += 3;
  93.                      if(y>(maxy-5))
  94.                         dir = 6;
  95.                      x += 3;
  96.                      if(x>(maxx-5))
  97.                         dir = 5;
  98.                      break;
  99.                   case 2:
  100.                      y += 4;
  101.                      if(y>(maxy-5))
  102.                         dir = 6;
  103.                      break;
  104.                   case 3:
  105.                      x -= 3;
  106.                      if(x<5)
  107.                         dir = 0;
  108.                      y += 3;
  109.                      if(y>(maxy-5))
  110.                         dir = 7;
  111.                      break;
  112.                   case 4:
  113.                      x -= 4;
  114.                      if(x<5)
  115.                         dir = 0;
  116.                      break;
  117.                   case 5:
  118.                      y -= 3;
  119.                      if(y<5)
  120.                         dir = 2;
  121.                      x -= 3;
  122.                      if(x<5)
  123.                         dir = 3;
  124.                      break;
  125.                   case 6:
  126.                      y -= 4;
  127.                      if(y<5)
  128.                         dir = 2;
  129.                      break;
  130.                   case 7:
  131.                      x += 3;
  132.                      if(x>maxx-5)
  133.                         dir = 4;
  134.                      y -= 3;
  135.                      if(y<5)
  136.                         dir = 3;
  137.                      break;
  138.                }
  139.             setlinestyle(SOLID_LINE,0,3);
  140.             setcolor(BLACK);
  141.             line(oldx,oldy,x,y);
  142.             setlinestyle(SOLID_LINE,0,1);
  143.             setcolor(mycolor);
  144.             line(oldx,oldy,x,y);
  145.             oldx = x;
  146.             oldy = y;
  147.             wait_for_time(0);
  148.          }
  149.    }
  150. void   ender(void)
  151.    {
  152.       while(!bioskey(1))
  153.          wait_for_time(100);
  154.       closegraph();
  155.       exit_processing(0);
  156.    }
  157.