回复 10楼 我菜119
tc下自己做的字母游戏!不好不笑!#include <graphics.h>
#include <conio.h>
void welcome()
{
int c=1;
cleardevice();
while(!kbhit())
{
if(c%2!=0)
setcolor(RED);
else
setcolor(BLACK);
outtextxy(280, 400, "please enter to game");
sleep(1);
c++;
}
getch();
cleardevice();
}
void over(char * str)
{
cleardevice();
setcolor(RED);
outtextxy(300,250,"score:");
outtextxy(350,250,str);
outtextxy(300,300,"game over");
getch();
}
score(char * str)
{
str[4]=str[4]+1;
if(str[4]==('0'+10))
{
str[4]='0';
str[3]=str[3]+1;
}
if(str[3]==('0'+10))
{
str[3]='0';
str[1]=str[1]+1;
}
if(str[1]==('0'+10))
{
str[1]='0';
str[0]=str[0]+1;
}
if(str[0]==('0'+10))
{
str[4]='0';
}
}
void main()
{
int gdriver=DETECT,gmode;
int x,y,x1=200,i;
char * target = " ";
char * str="00:00";
char key;
initgraph(&gdriver,&gmode,"c:\\tc");
cleardevice();
welcome();
srand(time(0));
setcolor(8);
rectangle(1,410,640,460);
setfillstyle(1,BLUE);
floodfill(2,411,8);
setcolor(8);
rectangle(200,425,400,445);
setfillstyle(1,RED);
floodfill(201,426,8);
setcolor(RED);
outtextxy(150,420,"life:");
setcolor(15);
outtextxy(450,420,"score:");
rectangle(500,415,550,460);
setfillstyle(1,YELLOW);
floodfill(501,416,15);
setcolor(RED);
outtextxy(505,435,str);
while(x1<410)
{
setcolor(4);
rectangle(x1,425,x1+20,445);
setfillstyle(1,RED);
floodfill(x1+1,426,RED);
x1=x1+20;
}
while(1)
{
target[0] = 65 + rand() % 26;
x = rand()%630;
for (y=0; y<400; ++y)
{
setcolor(RED);
outtextxy(x, y, target);
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
setcolor(BLACK);
outtextxy(x, y, target);
break;
}
else if (key == 27)
{
goto EXIT;
}
}
delay(200);
setcolor(BLACK);
outtextxy(x, y, target);
}
if(y==400)
{
setcolor(BLACK);
rectangle(x1,425,x1-20,445);
setfillstyle(1,BLACK);
floodfill(x1-1,426,BLACK);
x1=x1-20;
}
else{
setcolor(YELLOW);
outtextxy(505,435,str);
score(str);
setcolor(RED);
outtextxy(505,435,str);
}
if(x1==200)
{
over(str);
goto EXIT;
}
}
EXIT:
closegraph();
}