float min=30000.0;
float *length; /*board[i]到bub的距离的平方*/
while(1)
{
clearbub();
for(i=0;i<114;i++)
{length[i]=(board[i].x-x)*(board[i].x-x)+(board[i].y-y)*(board[i].y-y);
if(length[i]<400.0&&board[i].color!=0){flag1=1;break;}
}
if(flag1==1)break;
if(x<12){x=12;moveangle=PI-moveangle;}
if(x>188){x=188;moveangle=PI-moveangle;}
if(y<10)break;
x=x+2*cos(moveangle);
y=y-2*sin(moveangle);
printbub();
}
for(i=0;i<114;i++)
{length[i]=(board[i].x-x)*(board[i].x-x)+(board[i].y-y)*(board[i].y-y);
if(length[i]<min&&board[i].color==0){min=length[i];flag=i;}
}
board[flag].color=color;
x=100;
y=20*10*y1+10;
color=0;
return flag;
}
startbub::ChangeAngle() /************************************************************/
{int key;
int flag_1=0;
bioskey(1);
key=bioskey(0);
switch(key)
{
case VK_RIGHT:
if(angle>PI/36.0)angle=angle-PI/72.0;moveangle=angle;ShowAngle();break;
case VK_LEFT:
if(angle<PI-PI/36.0)angle=angle+PI/72.0;moveangle=angle;ShowAngle();break;
case VK_SPACE:
MoveBubble();ShowAngle();moveangle=angle;flag_1=1;break;
case VK_ESC:
exit(1);
}
return flag_1;
}
startbub::ClearBubble() /*******************************************************/
{return 0;}
startbub::DropBubble() /********************************************************/
{return 0;}
void clearboard()
{int quit=FALSE;
int i,j;
int sum=0;
int color=board[flag].color;
float m,n;
board[flag].samecolor=TRUE;
for(;;)
{ for(i=0;i<114;i++)
{
if(board[i].color==color&&board[i].samecolor==TRUE&&board[i].clear_init==FALSE)
break;
if(i==113){quit=TRUE;break;}
}
if(quit==TRUE)break;
for(j=0;j<114;j++)
{
m=board[j].x-board[i].x;
n=board[j].y-board[i].y;
if(m*m+n*n<450.0&&board[j].color==color)
{board[j].samecolor=TRUE;
board[i].clear_init=TRUE;
}
}
}
for(i=0;i<114;i++)
if(board[i].samecolor==TRUE)
{sum++;
}
if(sum>=3)
for(i=0;i<114;i++)
if(board[i].samecolor==TRUE)
board[i].color=0;
}
void dropboard()
{int quit=FALSE;
int i,j;
int m,n;
for(i=0;i<114;i++)
{board[i].notdrop=FALSE;
board[i].drop_init=FALSE;
}
for(i=0;i<10;i++)
{ if(board[i].color!=0)board[i].notdrop=TRUE;}
for(;;)
{
for(i=0;i<114;i++)
{if(board[i].notdrop==TRUE&&board[i].drop_init==FALSE)break;
if(i==113){quit=TRUE;break;}
}
if(quit==TRUE)break;
if(board[i].notdrop==TRUE&&board[i].drop_init==FALSE)
for(j=0;j<114;j++)
{
m=board[i].x-board[j].x;
n=board[i].y-board[j].y;
if(m*m+n*n<450.0&&board[j].color!=0)
{board[j].notdrop=TRUE;
board[i].drop_init=TRUE;
}
}
}
for(i=0;i<114;i++)
{if(board[i].notdrop==FALSE)
board[i].color=0;
}
}
void main()
{int i;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"g:\\bc31\\bgi"); /*用bc31编的,大小自己改下路径吧*/
randomize();
initboard();
for(;;)
{bub.MakeBubble();
printboard();
bub.ShowAngle();printboard();
for(;bub.ChangeAngle()==0;){bub.ShowAngle();printboard();}
clearboard();
dropboard();
dropboard();
initboard();
initbub();
}
}
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<bios.h>
#include<stdlib.h>
#include<math.h>
#define VK_LEFT 0x4b00 /*上下左右键的值*/
#define VK_RIGHT 0x4d00
#define VK_DOWN 0x5000
#define VK_UP 0x4800
#define VK_ESC 0x011b
#define VK_SPACE 0x3920
#define TRUE 1
#define FALSE 0
#define PI 3.141593
#define sqrt2 1.41421
#define y1 17.32051
int flag;
circle1(int x,int y,float r)
{int i;
for(i=1;i<r;i++)
{circle(x,y,i);
}
return 0;
}
class bubble{
public:
float x,y;
int color;
float radius;
int samecolor;
int clear_init;
int notdrop;
int drop_init;
}board[114];
void initboard() /*******************************************************************/
{int i,j,k;
for(i=0;i<114;i++)
{board[i].y=i/19*2*y1+10+(i%19)/10*y1;
if((i%19)/10==0)board[i].x=(i%19)*20+10;
if((i%19)/10==1)board[i].x=(i%19)%10*20+20;
board[i].samecolor=FALSE;
board[i].clear_init=FALSE;
board[i].notdrop=FALSE;
board[i].drop_init=FALSE;
}
}
class startbub{
public:
float x,y;
float x2,y2;
int color;
float v; /*bubble运动的速度*/
float radius;
float angle;
float moveangle;
startbub()
{x=100.0;y=10.0+12*y1;angle=PI/2.0;moveangle=PI/2.0;v=1.0;}
MakeBubble();
ShowAngle();
MoveBubble();
ChangeAngle();
ClearBubble();
DropBubble();
}bub;
initbub()
{
bub.x=100;
bub.y=10+12*y1;
return 0;
}
printboard() /********************************************************/
{int i;
for(i=0;i<114;i++)
{if(board[i].color!=0)
{setcolor(board[i].color);
circle1(board[i].x,board[i].y,10);
setfillstyle(SOLID_FILL,board[i].color);
bar(board[i].x-sqrt2*4.4,board[i].y-sqrt2*4.4,board[i].x+sqrt2*4.4,board[i].y+sqrt2*4.4);
}
else {setcolor(BLACK);
circle1(board[i].x,board[i].y,10);
setfillstyle(SOLID_FILL,BLACK);
bar(board[i].x-sqrt2*4.4,board[i].y-sqrt2*4.4,board[i].x+sqrt2*4.4,board[i].y+sqrt2*4.4);
}
}
return 0;
}
startbub::MakeBubble() /***************************************************************/
{
color=random(6)+1;
return 0;
}
startbub::ShowAngle() /****************************************************************/
{setcolor(BLACK);
setlinestyle(SOLID_LINE,10,10);
line(100.0,10+12*y1,x2,y2);
x2=100.0+30.0*cos(angle);
y2=10+12*y1-30.0*sin(angle);
setcolor(8);
line(100.0,10+12*y1,x2,y2);
setcolor(color);
circle1(100.0,10+12*y1,10);
return 0;
}
printbub()
{
setcolor(bub.color);
circle1(bub.x,bub.y,10);
bar(bub.x-sqrt2*5.0,bub.y-sqrt2*5.0,bub.x+sqrt2*5.0,bub.y+sqrt2*5.0);
bub.ShowAngle();
return 0;
}
clearbub()
{
setcolor(BLACK);
circle1(bub.x,bub.y,10);
bar(bub.x-sqrt2*5.0,bub.y-sqrt2*5.0,bub.x+sqrt2*5.0,bub.y+sqrt2*5.0);
bub.ShowAngle();
return 0;
}
int startbub::MoveBubble() /****************************************************************/
{int i,j;
int flag1;
flag=0;
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |