home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Lion Share
/
lionsharecd.iso
/
dos_misc
/
drop.zip
/
DROP.C
next >
Wrap
C/C++ Source or Header
|
1992-07-26
|
2KB
|
98 lines
/*
Demo: DROP.C
Desc: Makes every letter fall to the bottom of the screen, piling up on each
other.
*/
#include <dos.h>
#include <conio.h>
/* Variables */
char scr1[80][24],scr2[80][24];
/* Functions */
void save_screen(void);
void char_drop(void);
void redraw_screen(void);
char grabch(int x,int y);
/* Level 0: main */
main()
{
int a,b;
char ch;
save_screen();
char_drop();
redraw_screen();
if (kbhit) ch = getch(); /* eat buffer */
return(0);
}
/* Level 1: save_screen, char_drop, redraw_screen */
void save_screen(void)
{
int x,y;
for(y=1; y <= 24; y++) /* load each char into */
for(x=1; x <= 80; x++) { /* the arrays */
scr1[x][y] = grabch(x,y);
scr2[x][y] = scr1[x][y];
}
return;
}
void char_drop(void)
{
int x,y;
do
{
x = rand() % 80 + 1;
y = rand() % 23 + 1;
/* check for space below, and printable char above */
if((scr1[x][y+1] == ' ') && (scr1[x][y] != ' '))
{
scr1[x][y+1] = scr1[x][y]; /* move the falling char down 1 col */
scr1[x][y] = ' '; /* and replace old pos with a space */
gotoxy(x,y); /* relocate, */
printf(" "); /* and print a black space */
gotoxy(x,y+1); /* move to 'fallen' pos, */
printf("%c",scr1[x][y+1]); /* and print 'fallen' char */
}
} while (!kbhit()); /* drop chars until a key is pressed */
}
void redraw_screen(void)
{
int x,y;
for(y=1; y <= 24; y++)
for(x=1; x <= 80; x++) {
gotoxy(x,y);
printf("%c",scr2[x][y]);
}
return;
}
/* Level 2: grabch */
char grabch(int x,int y)
{
union REGS r;
/* int xt,yt;
xt = wherex();
yt = wherey(); */
gotoxy(x,y);
ri.h.ah = 0x08;
ri.h.bh = 0x00;
int86(0x10,&r,&r);
/* gotoxy(xt,yt); */
return(r.h.al);
}