回覆列表
  • 1 # 使用者4691955236311

    #include<time.h>

    #include<stdlib.h>

    #include<graphics.h>

    #include<conio.h>

    #include<dos.h>

    #include<math.h>

    #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<dalta)

    angle-=dalta;

    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<dalta)

    angle-=dalta;

    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;

    }

  • 中秋節和大豐收的關聯?
  • 炒薄千張做法?