//粗制一个
#include<graphics.h>
#include<conio.h>
#include<time.h>
const short S=10;const short SPEED=10;
class Digit
{
private:
char dgt[2];
/*位置*/
short x;
short y;
IMAGE img;//保存被遮的背景
public:
short spd;
Digit(char num,short xx,short yy):x(xx),y(yy)
{
dgt[0]=num;dgt[1]='\0';
getimage(&img,x,y,S*2,S*2);//保存背景
spd=SPEED+rand()%12;
}
Digit()
{
dgt[0]='0'+rand()%10;dgt[1]='\0';
x=50+rand()%350;
y=rand()%100;//根据需要自行设计坐标
getimage(&img,x,y,S*2,S*2);//保存背景
spd=SPEED+rand()%12;
}
void Repos(short xx,short yy){x=xx;y=yy;}
void Print()
{
settextstyle(S*2,S,"Times New Roman");
outtextxy(x,y,dgt);
}
void GetImg()
{
getimage(&img,x,y,S*2,S*2);//保存背景
}
void Erase()
{
putimage(x,y,&img);//恢复背景
}
short GetX(){return x;}
short GetY(){return y;}
void SetX(short xx){x=xx;}
void SetY(short yy){y=yy;}
};
int main()
{
int i;
initgraph(600,400);
getch();
srand((unsigned short)time(0));
Digit d[10];
while(!kbhit())
{
for(i=0;i<10;i++)
if(d[i].GetY()>400)
d[i].SetY(1);
for(i=0;i<10;i++)
d[i].Erase();
for(i=0;i<10;i++)
d[i].SetY(d[i].GetY()+d[i].spd);
for(i=0;i<10;i++)
d[i].GetImg();
for(i=0;i<10;i++)
d[i].Print();
Sleep(150);
}
closegraph();
return 0;
}