Moving characters (Mini Project) in C
#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <stdlib.h>
char far *v=(char far*)0xb8000000;int r,c,i,j,k;
char ch;
void main()
{
//clrscr();
char *a;
//cout<<"write few characters";
clrscr();
puts("Write few characters");
gets(a);
getch();
clrscr();
puts(a);
while(!kbhit())
{
r=random(25);
c=random(80);
ch=*(v+r*160+c*2);
if(ch==' ')
{}
else
{
if(r<23)
{
for(i=r;i<=23;i++)
{
if(k>=16)
k=0;
*(v+i*160+c*2)=' ';
*(v+(i+1)*160+c*2)=ch;
j=*(v+(i+1)*160+c*2+1);
*(v+(i+1)*160+c*2+1)=k;
delay(30);
*(v+(i+1)*160+c*2+1)=j; //to restore screen attribute
k++;
}
}//end of if
else
{
for(i=r;i>=1;i--)
{
if(k>=16)
k=0;
*(v+i*160+c*2)=' ';
*(v+(i-1)*160+c*2)=ch;
j=*(v+(i-1)*160+c*2+1);
*(v+(i-1)*160+c*2+1)=k;
delay(30);
*(v+(i-1)*160+c*2+1)=j; //to restore screen attribute
k++;
}
}//end of inner else
}//end of outer else
}
getch();
}
output:
#include <bios.h>
#include <dos.h>
#include <stdlib.h>
char far *v=(char far*)0xb8000000;int r,c,i,j,k;
char ch;
void main()
{
//clrscr();
char *a;
//cout<<"write few characters";
clrscr();
puts("Write few characters");
gets(a);
getch();
clrscr();
puts(a);
while(!kbhit())
{
r=random(25);
c=random(80);
ch=*(v+r*160+c*2);
if(ch==' ')
{}
else
{
if(r<23)
{
for(i=r;i<=23;i++)
{
if(k>=16)
k=0;
*(v+i*160+c*2)=' ';
*(v+(i+1)*160+c*2)=ch;
j=*(v+(i+1)*160+c*2+1);
*(v+(i+1)*160+c*2+1)=k;
delay(30);
*(v+(i+1)*160+c*2+1)=j; //to restore screen attribute
k++;
}
}//end of if
else
{
for(i=r;i>=1;i--)
{
if(k>=16)
k=0;
*(v+i*160+c*2)=' ';
*(v+(i-1)*160+c*2)=ch;
j=*(v+(i-1)*160+c*2+1);
*(v+(i-1)*160+c*2+1)=k;
delay(30);
*(v+(i-1)*160+c*2+1)=j; //to restore screen attribute
k++;
}
}//end of inner else
}//end of outer else
}
getch();
}
output:
Comments
Post a Comment