#include
#include
#include
#include
#include
#define xstart 50
#define ytop 50
#define ybut 150
#define lednum 21
#define offnum 2
#define midnum (lednum+1)/2
#define xpos(i) xstart+25*i
void Init(void);
void GameMsg(void);
void Gameplay(void);
void GameOver(void);
void Close(void);
void delay5(void);
main()
{
Init();
Gameplay();
GameOver();
Close();
}
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"d://tc");
cleardevice();
}
void Clr(int x) /*画红色霓虹灯函数*/
{
setfillstyle(SOLID_FILL,RED);
bar(xpos(x)-5,ytop,xpos(x)+5,ybut);
}
void Clbar(int x) /*擦除红色霓虹灯函数*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(xpos(x)-5,ytop,xpos(x)+5,ybut);
}
void delay5(void)
{
int a,b,c;
for(a=0;a<1500;a++)
for(b=0;b<255;b++)
for(c=0;c<255;c++)
;
}
void GameMsg()
{
settextstyle(1,0,4);
setcolor(2);
outtextxy(350,350,"Made: Y.Z.X");
outtextxy(350,400,"Date: 2006.1");
outtextxy(100,ybut+50,"Press any key to Start/End. . .");
}
void Gameplay()
{
int i,j;
GameMsg();
randomize();
for(i=1;i<=lednum;i++)
Clbar(i); /*画蓝色霓虹灯*/
getch();
while(!kbhit())
{
for(j=1;j<=lednum;j++) /*顺序擦除*/
{
Clr(j);
delay5();
Clbar(j);
}
for(j=lednum;j>=1;j--) /*逆序擦除*/
{
Clr(j);
delay5();
Clbar(j);
}
for(i=0;i<=midnum-1;i++)/*中间向两边擦除*/
{
Clr(midnum-i);
Clr(midnum+i);
delay5();
Clbar(midnum-i);
Clbar(midnum+i);
}
for(i=midnum-1;i>=0;i--) /*两边向中间擦除*/
{
Clr(midnum-i);
Clr(midnum+i);
delay5();
Clbar(midnum-i);
Clbar(midnum+i);
}
for(i=1;i<=lednum;i++)
{
for(j=i;j<=i+offnum;j++)
if(j<=lednum)
Clr(j);
else Clr(j-lednum);
delay5();
Clbar(i);
}
putch('/a');
}
}
void GameOver(void)
{
cleardevice();
settextstyle(0,0,7);
setcolor(RED);
outtextxy(50,200,"GAME OVER");
sleep(2);
}
void Close(void)
{
closegraph();
}