hur.cn - 华软网

 热门搜索

小球碰撞游戏程序代码,求注释,越详细越好》》》

  作者:未知    来源:网络    更新时间:2011/5/27
#include "GRAPHICS.H"
#include "MATH.H"
#include "stdio.h"
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ESC 0x011b
int x,y,x1,y1,key,t1,t2,keyx,keylong,keymove,over=0,i,tt=0,fast;
int ballx[9]={53,183,263,120,86,390,40,350,600};
int bally[9]={158,139,160,113,30,213,120,263,281};
int ballz[9]={0};
float ls;
win()
{
    float lx,ly,l1;
    for(i=0;i<9;i++)
    {
        if(ballz[i]==1)
            continue;
        lx=(float)(ballx[i]-x);
        ly=(float)(bally[i]-y);
        l1=lx*lx+ly*ly;
        ls=sqrt(l1);
        if((int)ls<17)
        {
            tt++;
            fast-=50;
            if(i%2==0)
                keymove+=5;
            else
            {
                setcolor(0);
                rectangle(keyx,460,key+keylong,470);
                keylong-=10;
                setcolor(YELLOW);
                rectangle(keyx,460,keyx+keylong,470);
            }
            ballz[i]=1;
            setcolor(0);
            circle(ballx[i],bally[i],10);
            if(y<bally[i])
                if(x<ballx[i])
                {
                    t1=-1;
                    t2=-1;
                }
                else
                {
                    t1=1;
                    t2=-1;
                }
            else
                if(x<ballx[i])
                {
                    t1=1;
                    t2=1;
                }
                else
                    if(x<ballx[i])
                    {
                        t1=-1;
                        t2=1;
                    }
                    else
                    {
                        t1=1;
                        t2=1;
                    }
        }
    }
}
fungo()
{
    x=100,y=50,keyx=200,keylong=100,keymove=15,fast=5000;
    for(i=0;i<9;i++)
    {
        setcolor(i+1);
        circle(ballx[i],bally[i],10);
    }
    sleep(1);
    t1=t2=1;
    while(1)
    {
        while(!kbhit())
        {
            setcolor(YELLOW);
            rectangle(keyx,460,keyx+keylong,470);
            x1=x;
            y1=y;
            x+=t1;
            y+=t2;
            setcolor(4);
            circle(x,y,6);
            delay(fast);
            setcolor(0);
            circle(x,y,6);
            win();
            if(tt==9)
            {
                cleardevice();
                over=1;
                setcolor(RED);
                settextstyle(0,0,4);
                setusercharsize(3,1,3,1);
                outtextxy(200,200,"YOU WIN!");
                break;
            }
            if(y>480)
            {
                cleardevice();
                over=1;
                setcolor(RED);
                settextstyle(0,0,4);
                setusercharsize(3,1,3,1);
                outtextxy(200,200,"GAME OVER");
                break;
            }
            else if(x==6&&y==6)
            {
                t1=1;
                t2=1;
            }
            else if(x==633&&y==6)
            {
                t1=-1;
                t2=1;
            }
            else if(x==6)
            {
                if(y<y1)
                {
                    t1=1;
                    t2=-1;
                }
                else
                {
                    t1=1;
                    t2=1;
                }
            }
            else if(y==6)
            {
                if(x<x1)
                {
                    t1=-1;
                    t2=1;
                }
                else
                {
                    t1=1;
                    t2=1;
                }
            }
            else if(x==633)
            {
                if(y1>y)
                {
                    t1=-1;
                    t2=-1;
                }
                else
                {
                    t1=-1;
                    t2=1;
                }
            }
            else if(y==454)
            {
                if(x>=keyx&&x<=keyx+keylong)
                {
                    if(x<(keyx+keylong/4))
                    {
                        t1=-1;
                        t2=-1;
                    }
                    else if(x>=(keyx+keylong/4)&&x<(keyx+keylong/2))
                    {
                        t1=-1;
                        t2=-2;
                    }
                    else if(x>=(keyx+keylong/2)&&x<(keyx+keylong/4*3))
                    {
                        t1=1;
                        t2=-2;
                    }
                    else
                    {
                        t1=1;
                        t2=-1;
                    }
                }
            }
        }
        if (over)  break;
        key=bioskey(0);
        setcolor(0);
        rectangle(keyx,460,keyx+keylong,470);
        if(key==ESC)
             {cleardevice();break;}
        else if(key==LEFT)
              keyx-=keymove;
        else if(key==RIGHT)
              keyx+=keymove;
    }
}

main()
{
    int gd=DETECT,gr;
    initgraph(&gd,&gr,"C:\\TC\\BGI");
    setcolor(100);
    fungo();
    getch();
    sleep(1);
    closegraph();

---华软 网友回答---
楼主。。你的结贴率这么低。。      
华软声明:本内容来自网络,如有侵犯您版权请来信指出,本站立即删除。