#include"stdlib.h"
#include"graphics.h"
#include"conio.h"
#include"time.h"
#include"dos.h"
#define BK_COLOR BLACK
#define C_COLOR BLUE
#define CHAR_COLOR WHITE
#define UpKey 72
#define DownKey 80
#define ESC 27
#define Enter 13
#define MenuX 200
#define MenuY 110
#define MenuWidth 200
#define MenuSinH 40
#define ChoiceX MenuX+15
#define ChoiceY MenuY+10
#define ChoiceWidth 170
#define ChoiceH 25
#define ViewLeft 20
#define ViewTop 15
#define ViewRight 520
#define ViewBottom 460
#define DataViewX ViewRight
#define DataViewY ViewTop+40
#define DataH 40
int nCount=10;
int speed=6000;
struct PlayData
{
int time;
int Hit;
int Lose;
double ratio;
}result;
void Interface()
{
int i,j;
setcolor(CYAN);
for(i=0;i<60;i++)
{
line(i,0,i,500);
line((getmaxx()-i),0,(getmaxx()-i),500);
}
setcolor(YELLOW);
for(i=60,j=0;i<85;i++,j++)
{
line(i,j,i,500);
line((getmaxx()-i),j,(getmaxx()-i),500);
}
setcolor(WHITE);
rectangle(MenuX,MenuY,MenuX+MenuWidth,MenuY+3*MenuSinH);
line(MenuX,MenuY+MenuSinH,MenuX+MenuWidth,MenuY+MenuSinH);
line(MenuX,MenuY+2*MenuSinH,MenuX+MenuWidth,MenuY+2*MenuSinH);
}
void Main_Menu()
{
settextstyle(0,0,2);
outtextxy(MenuX+20,MenuY+15,"START GAME");
outtextxy(MenuX+20,MenuY+MenuSinH+15,"GAME SETUP");
outtextxy(MenuX+20,MenuY+2*MenuSinH+15,"EXIT");
}
void Option_Menu()
{
settextstyle(0,0,2);
outtextxy(MenuX+20,MenuY+15,"beginner");
outtextxy(MenuX+20,MenuY+MenuSinH+15,"advancer");
outtextxy(MenuX+20,MenuY+2*MenuSinH+15,"senior");
}
int Choice(int c_x,int c_y,int color)
{
setfillstyle(1,color);
bar(c_x,c_y,c_x+ChoiceWidth,c_y+ChoiceH);
return c_y;
}
int ChooseMenu(int flag)
{
int x,y;
char C_Key;
x=ChoiceX;
y=ChoiceY;
do
{
kbhit();
C_Key=getch();
if(C_Key==ESC)
{
sound(5000);
delay(6000);
nosound();
return ESC;
}
else if(C_Key==Enter)
{
sound(300);
delay(6000);
nosound();
return y;
}
else
switch(C_Key)
{
case UpKey:
sound(1000);
delay(10000);
nosound();
if(y==ChoiceY)
break;
else
{
Choice(x,y,BK_COLOR);
y-=MenuSinH;
Choice(x,y,C_COLOR);
}
break;
case DownKey:
sound(1000);
delay(10000);
nosound();
if(y==(ChoiceY+2*MenuSinH))
break;
else
{
Choice(x,y,BK_COLOR);
y+=MenuSinH;
Choice(x,y,C_COLOR);
}
break;
default:
break;
}
if(flag==0)
Main_Menu();
else
if(flag==1)
Option_Menu();
}while(C_Key!=ESC);
}
void Setup()
{
int result;
result=ChooseMenu(1);
switch(result)
{
case ESC:
return 0;
case ChoiceY:
speed=6000; nCount=30;
break;
case ChoiceY+MenuSinH:
speed=3000; nCount=60;
break;
case ChoiceY+2*MenuSinH:
speed=1000; nCount=100;
break;
default:
break;
}
}
void Loading()
{
int i,j,l;
Interface();
setfillstyle(1,0);
bar(200,110,400,230);
settextstyle(0,0,1);
outtextxy(250,207,"Loading");
for(l=0;l<6;l++)
{
setcolor(15);
rectangle(237+l*15,225,244+l*15,235);
}
l=0;
j=1;
while(j!=480-j)
{
j++;
if(j%40==0)
{
setfillstyle(1,RED);
bar(237+15*l,225,244+15*l,235);
l++;
}
setfillstyle(1,0);
bar(0,0,getmaxx(),j);
bar(0,480,getmaxx(),480-j);
delay(1000);
}
delay(60000);
clearviewport();
}
void DrawChar(int i,int j,char c)
{
char ch[1];
ch[0]=c;
ch[1]='\0';
moveto(i-7,j-7);
settextstyle(0,0,2);
outtext(ch);
}
void AutoDraw_Down(int x,int y,char c,int n)
{
setcolor(BK_COLOR);
DrawChar(x,y,c);
setcolor(CHAR_COLOR);
DrawChar(x,y+1,c);
delay(n);
}
void AutoDraw_Up(int x,int y,char c,int n)
{
setcolor(BK_COLOR);
DrawChar(x,y,c);
setcolor(CHAR_COLOR);
DrawChar(x,y-1,c);
delay(n);
}
char GenerateChar()
{
int flag;
char c;
flag=random(3);
switch(flag)
{
case 0:
c='a'+random(26);
break;
case 1:
c='A'+random(26);
break;
case 2:
c='0'+random(10);
break;
default:
break;
}
return c;
}
/*----------游戏界面---------*/
void PlayViewPort()
{
int i;
cleardevice();
setcolor(CYAN);
for(i=0;i<3;i++)
rectangle(ViewLeft-10-i,ViewTop-10-i,ViewRight+110+i,ViewBottom+10+i);
rectangle(ViewLeft,ViewTop,ViewRight+100,ViewBottom);
setfillstyle(XHATCH_FILL,YELLOW);
floodfill(ViewLeft-1,ViewTop-1,CYAN);
setcolor(WHITE);
for(i=0;i<3;i++)
rectangle(ViewLeft-i,ViewTop-i,ViewRight+100+i,ViewBottom+i);
line(ViewRight,ViewTop,ViewRight,ViewBottom);
settextstyle(0,0,0);
rectangle(DataViewX,DataViewY,DataViewX+100,DataViewY+DataH);
rectangle(DataViewX,DataViewY+DataH,DataViewX+100,DataViewY+2*DataH);
rectangle(DataViewX,DataViewY+2*DataH,DataViewX+100,DataViewY+3*DataH);
outtextxy(DataViewX+10,DataViewY+10,"Hit:");
outtextxy(DataViewX+10,DataViewY+DataH+10,"Lose:");
outtextxy(DataViewX+10,DataViewY+2*DataH+10,"PreKey:");
}
/*----------画笑脸---------*/
void DrawLaugh(int x,int y,int r)
{
int c1=YELLOW,c2=BLACK,c3=WHITE;
int d=r/5;
setcolor(c1);
circle(x,y,r);
setfillstyle(1,c1);
floodfill(x,y,c1);
setcolor(c2);
line(x-d,y-d*3,x-2*d,y-4*d);
line(x-2*d,y-4*d,x-2.9*d,y-4*d);
line(x+d,y-d*3,x+2*d,y-4*d);
line(x+2*d,y-4*d,x+2.9*d,y-4*d);
/*-------------------------------------*/
line(x-3.5*d,y-2*d,x-2.5*d,y-2.6*d);
line(x-2.5*d,y-2.6*d,x-1.5*d,y-2*d);
line(x+3.5*d,y-2*d,x+2.5*d,y-2.6*d);
line(x+2.5*d,y-2.6*d,x+1.5*d,y-2*d);
/*-------------------------------------*/
pieslice(x,y,180,360,4*d);
setfillstyle(1,c3);
floodfill(x,y+d,c2);
/*-------------------------------------*/
line(x-2*d,y,x-2*d,y+3.5*d);
line(x+2*d,y,x+2*d,y+3.5*d);
line(x,y,x,y+4*d);
line(x+3.5*d,y,x+3.5*d,y+1.8*d);
}
/*----------大笑表情---------*/
void Laugh(int x,int y)
{
int i,d,r,flag=0;
d=6; i=0;
r=10;
while(!kbhit())
{
DrawLaugh(x,y+i,r);
delay(10000);
setfillstyle(1,BK_COLOR);
setcolor(BK_COLOR);
pieslice(x,y+i,0,360,r);
if(i==d)
flag=1;
if(i==0)
flag=0;
if(flag==0)
i++;
else
i--;
}
}
/*----------微笑表情---------*/
void Smile(int x,int y)
{
int r=10,c1=YELLOW,c2=BLACK;
int d=r/5,i;
setcolor(c1);
circle(x,y,r);
setfillstyle(1,c1);
floodfill(x,y,c1);
setcolor(c2);
setfillstyle(1,c2);
sector(x-2.5*d,y-2.5*d,0,360,1,1);
sector(x+2.5*d,y-2.5*d,0,360,1,1);
setcolor(c2);
arc(x,y,200,350,3.5*d);
}
/*----------哭丧表情---------*/
void Weep(x,y)
{
int r=10,c1=YELLOW,c2=BLACK;
int d=r/5,i=0;
while(!kbhit())
{
setcolor(c1);
circle(x,y,r);
setfillstyle(1,c1);
floodfi