有图形界面就麻烦的很,你才给5分,太少了
给你个.因分少就不改动了,
这个是给别的朋友定过的.
只有练习数字和字母.而且可以调速度,并配着简单的动画哦.如觉得好要加功能, 加我百度好友,再加分.哈哈.
#include
#include
#include
#include
#include
#include
#define R 10
#define ESC 0x011b
#define LOW 0x5000
#define FAST 0x4800
int draw_car(int x,int y,char *ch);
double dalta=20,angle;
void *image;
int step=20;
main()
{
int gdriver=DETECT,gmode;
static int startx=60;
static int starty=20;
int maxy,maxx,l=1,n=1;
char ch,play, str[2];
int size,temch;
int ok,y=50;
clrscr();
printf("\n\n\n\n\n*****************************************\n");
printf(" 1.play only number 0-9 .\n");
printf(" 2.play only char a-z .\n");
printf(" 3.exit\n");
printf("*****************************************\n");
while(1){
printf("\nPls enter choice:");
play=getche();
if((play=='1')||(play=='2'))
break;
if(play=='3')
return;
}
registerbgidriver( EGAVGA_driver ); /*注册vga驱动*/
initgraph(&gdriver,&gmode,"d:\\tc3\\bgi"); /*初始化图形界面*/
cleardevice(); /*清除屏幕*/
setbkcolor(BLUE); /*将背景色设置成蓝色*/
size=imagesize(startx,starty,startx+60,starty+60); /*计算生成60×60个象素的图需要的字节数*/
image=(unsigned char *)malloc(size); /*分配内存*/
maxx=getmaxx();
maxy=getmaxy();
randomize();
printf("Press ESC to exit game! ");
printf(" %c to fast speed,%c to low speed!",24,25);
do{
ok=0;
if(play=='1')
ch=random(9)+48;
if(play=='2')
ch=random(26)+65;
str[0]=ch;
do{
while(bioskey(1)==0) /*如果没有按键就不停的循环*/
{
if(l==1) /*从左到右*/
{
n++;
angle=-1*(n*step)/M_PI*180/R;
if((int)(-1*angle)%360
if(n>(maxx-180)/step){
if(starty>maxy-100)
starty=20;
else
starty+=y;
l=0;
}
}
if(l==0) /*从右到左*/
{
--n;
angle=-1*(n*step)/R/M_PI*180;
if((int)(-1*angle)%360
if(n==1){
if(starty>maxy-100)
starty=20;
else
starty+=y;
l=1;
}
}
draw_car(startx+n*step,starty,str);
}
temch=bioskey(0);
if(temch==FAST){
step+=10;
y+=10;
}
if(temch==LOW){
step-=10;
y-=10;
}
ok=temch&0x00ff;
if((ok==ch)||(ok==ch+32)){
ok=1;
starty=20;
break;
}
}while(temch!=ESC);
if(ok!=1)
break;
}while(1);
free(image);
closegraph();
return;
}
int draw_car(int x,int y,char *ch){
setcolor(YELLOW); /*设置前景色为黄色*/
rectangle(x,y,x+60,y+40); /*画车厢*/
pieslice(x+15,y+50,angle,angle-dalta,10); /*画轮上的小片扇形部分*/
pieslice(x+45,y+50,angle,angle-dalta,10);
setfillstyle(SOLID_FILL, YELLOW); /*设置填充模式为实填充,颜色为黄色*/
circle(x+15,y+50,10); /*画车轮*/
circle(x+45,y+50,10);
circle(x+15,y+50,3);
circle(x+45,y+50,3);
setcolor(WHITE);
settextstyle(1,0,4);
outtextxy(x+25,y,ch);
getimage(x,y,x+60,y+60,image); /*获取当前的图片*/
delay(200);
putimage(x,y,image,XOR_PUT); /*使用异或模式将图片显示上去*/
return;
}
我也求!!!还有没有!!!