签到

05月06日
尚未签到

共有回帖数 0

    愤怒的鸟

    等级:
    请高手指点,拜谢!!!!!  

    改动方向:蛇的速度应该设置难度进行控制,得分达到一定程度后提升难度。
     
     
    #include assert.h  
    #include time.h  
    #include stdio.h  
    #include conio.h  
    #include graphics.h  
    #include stdlib.h  
    #include math.h  
    #include process.h  
    #include dos.h  
    #define initnum 1  
    #define P 0x1970  
    #define ESC 0x011b  
    #define UP 0x4800  
    #define DOWN 0x5000  
    #define LEFT 0x4b00  
    #define RIGHT 0x4d00  
    int direc=1;  
    int foodnum=0;  
    struct body  
    {  
    int x;  
    int y;  
    struct body *next;  
    };  
    struct body *head,*rear,*p;  
    int inbody(struct body *c)  
    {  
    int k;  
    for(k=1;kfoodnum+initnum;k++)  
    {  
    if(c-x==head-x&&c-y==head-y)  
    return 1;  
    else  
    head=head-next;  
    }  
    head=head-next;  
    return 0;  
    }  


    void drawfood()  
    {  
    p=(struct body *)malloc(sizeof(struct body));  
    p-x=(rand()%42+2)*10;  
    p-y=(rand()%42+4)*10;  
    while(inbody(p))  
    {  
    p-x=(rand()%42+2)*10;  
    p-y=(rand()%42+4)*10;  
    }  
    bar(p-x+1,p-y+1,p-x+9,p-y+9);  
    }  

    void initbody()  
    {  
    int k;  
    p=(struct body *)malloc(sizeof(struct body));  
    p-x=20; p-y=40;  
    rear=p; head=p;  
    bar(head-x+1,head-y+1,head-x+9,head-y+9);  
    for(k=1;kinitnum;k++)  
    {  
    p=(struct body *)malloc(sizeof(struct body));  
    p-x=rear-x+10; p-y=40;  
    rear-next=p;  
    rear=p;  
    bar(rear-x+1,rear-y+1,rear-x+9,rear-y+9);  
    }  
    rear-next=head;  
    }  

    void movebody(int direc)  
    {  
    int i,j;  
    i=head-x; j=head-y;  

    switch(direc)  
    {  
    case 1:  
    {head-x=rear-x+10;  
    head-y=rear-y;  
    break;}  
    case 2:  
    {head-x=rear-x;  
    head-y=rear-y+10;  
    break;}  
    case 3:  
    {head-x=rear-x-10;  
    head-y=rear-y;  
    break;}  
    case 4:  
    {head-x=rear-x;  
    head-y=rear-y-10;  
    break;}  
    }  
    rear=head;  
    head=rear-next;  
    if(rear-x430||rear-x20||rear-y450||rear-y40)  
    { exit (0); }  
    if(inbody(rear))  
    { exit (0); }  
    bar(rear-x+1,rear-y+1,rear-x+9,rear-y+9);  
    if(rear-x==p-x&&rear-y==p-y)  
    { p-x=i;p-y=j;  
    rear-next=p; p-next=head;head=p;foodnum++;drawfood();  
    }  
    else  
    {  
    setfillstyle(SOLID_FILL,BLACK);  
    bar(i+1,j+1,i+9,j+9);  
    setfillstyle(SOLID_FILL,GREEN);  
    }  
    }  



    main()  
    {  
    int gd=VGA,gm=VGAHI;  
    int i,key;  
    initgraph(&gd,&gm,"");  
    setbkcolor(BLACK);  
    setcolor(RED);  
    setfillstyle(SOLID_FILL,GREEN);  
    cleardevice();  
    rectangle(20,40,440,460);  
    setcolor(GREEN);  
    randomize();  
    initbody();  
    drawfood();  
    while(1)  
    {  
    while(!kbhit())  
    {  
    movebody(direc);  
    delay(20000);  
    }  

    key=bioskey(0);  
    if(key==UP&&direc!=2)  
    direc=4;  

    if(key==RIGHT&&direc!=3)  
    direc=1;  

    if(key==DOWN&&direc!=4)  
    direc=2;  

    if(key==LEFT&&direc!=1)  
    direc=3;  

    if(key==ESC)  
    exit(0);  

    if(key==P)  
    getch();  

    }  
    }

    楼主 2016-04-28 11:32 回复

共有回帖数 0
  • 回 帖
  • 表情 图片 视频
  • 发表

登录直线网账号

Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号 意见反馈 | 关于直线 | 版权声明 | 会员须知