home *** CD-ROM | disk | FTP | other *** search
/ Lion Share / lionsharecd.iso / dos_misc / drop.zip / DROP.C next >
C/C++ Source or Header  |  1992-07-26  |  2KB  |  98 lines

  1. /*
  2. Demo: DROP.C
  3. Desc: Makes every letter fall to the bottom of the screen, piling up on each
  4.       other.
  5. */
  6.  
  7. #include <dos.h>
  8. #include <conio.h>
  9.  
  10. /* Variables */
  11. char scr1[80][24],scr2[80][24];
  12.  
  13. /* Functions */
  14. void save_screen(void);
  15. void char_drop(void);
  16. void redraw_screen(void);
  17. char grabch(int x,int y);
  18.  
  19. /* Level 0: main */
  20. main()
  21. {
  22.     int a,b;
  23.     char ch;
  24.  
  25.     save_screen();
  26.     char_drop();
  27.     redraw_screen();
  28.     if (kbhit) ch = getch();                                 /* eat buffer */
  29.  
  30.     return(0);
  31. }
  32.  
  33. /* Level 1: save_screen, char_drop, redraw_screen */
  34.  
  35. void save_screen(void)
  36. {
  37.     int x,y;
  38.  
  39.     for(y=1; y <= 24; y++)                          /* load each char into */
  40.         for(x=1; x <= 80; x++) {                    /* the arrays */
  41.             scr1[x][y] = grabch(x,y);
  42.             scr2[x][y] = scr1[x][y];
  43.         }
  44.  
  45.      return;
  46. }
  47.  
  48. void char_drop(void)
  49. {
  50.     int x,y;
  51.  
  52.     do
  53.     {
  54.         x = rand() % 80 + 1;
  55.         y = rand() % 23 + 1;
  56.         /* check for space below, and printable char above */
  57.         if((scr1[x][y+1] == ' ') && (scr1[x][y] != ' '))
  58.         {
  59.             scr1[x][y+1] = scr1[x][y]; /* move the falling char down 1 col */
  60.             scr1[x][y] = ' ';          /* and replace old pos with a space */
  61.             gotoxy(x,y);                                      /* relocate, */
  62.             printf(" ");                        /* and print a black space */
  63.             gotoxy(x,y+1);                        /* move to 'fallen' pos, */
  64.             printf("%c",scr1[x][y+1]);          /* and print 'fallen' char */
  65.         }
  66.     } while (!kbhit());               /* drop chars until a key is pressed */
  67. }
  68.  
  69. void redraw_screen(void)
  70. {
  71.     int x,y;
  72.  
  73.     for(y=1; y <= 24; y++)
  74.         for(x=1; x <= 80; x++) {
  75.             gotoxy(x,y);
  76.             printf("%c",scr2[x][y]);
  77.         }
  78.      return;
  79. }
  80.  
  81. /* Level 2: grabch */
  82.  
  83. char grabch(int x,int y)
  84. {
  85.      union REGS r;
  86.      /* int xt,yt;
  87.  
  88.         xt = wherex();
  89.         yt = wherey(); */
  90.      gotoxy(x,y);
  91.      ri.h.ah = 0x08;
  92.      ri.h.bh = 0x00;
  93.      int86(0x10,&r,&r);
  94.      /* gotoxy(xt,yt); */
  95.  
  96.      return(r.h.al);
  97. }
  98.