//Bo mon nhay xa...........
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <dos.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
class nguoi{
int x,y;
int a,b;
int r;
public:
nguoi(int x,int y,int r,int a,int b);
void nguoichay(int x,int y,int r,int a,int b,int t);
void nhay(int x,int y,int r,int a,int b,int z);
void giam1(int x,int y,int r,int a,int b,int u);
void cochan(int x,int y,int r,int a,int b,int u);
void trenkhong(int x,int y,int r,int a,int b,int u);
void xuong(int x,int y,int r,int a,int b,int u);
void Line();
};
//**************************************************************
void nguoi::Line()
{
setcolor(11);
line(0,220,240,220);
setcolor(9);
line(240,220,getmaxx(),220);
}
//**************************************************************
nguoi::nguoi(int x,int y,int r,int a,int b)
{
circle (x,y,r);
line (x,y+r,a,b); //than
line (x,y+r,x-r,y+2*r); //tay trai 1
line (x-r,y+2*r,x,y+3*r); //tay trai 2
line (x,y+r,x+r,y+2*r); //tay phai 1
line (x+r,y+2*r,x+2*r,y+r); //tay phai 2
line (a,b,a-r,b+r); //chan trai 1
line (a-r,b+r,a-2*r,b+2*r); //chan trai 2
line (a,b,a+r,b+r); //chan phai 1
line (a+r,b+r,a,b+2*r); //chan phai 2
}
//**************************************************************
void nguoi::nguoichay(int x,int y,int r,int a,int b,int t)
{
int t1=x-r,t2=x+r,
t3=x+2*r,t4=y+3*r,
t5=y+r,t6=a-r,
t7=a+r,t8=a-2*r,
t9=x,t10=a;
for (int i=0;i<t;i++)
{
delay(10);
cleardevice();
Line();
circle (x,y,r);
line (x,y+r,a,b);
line (x,y+r,t1=t1+1,y+2*r);
line (t1,y+2*r,t9=t9+1,t4=t4-1);
line (x,y+r,t2=t2-1,y+2*r);
line (t2,y+2*r,t3=t3-1,t5=t5+1);
line (a,b,t6=t6+1,b+r);
line (t6,b+r,t8=t8+1,b+2*r);
line (a,b,t7=t7-1,b+r);
line (t7,b+r,t10=t10-1,b+2*r);
a=a+1;
x=x+1;
t1=t1+1;
t2=t2+1;
t3=t3+1;
t6=t6+1;
t7=t7+1;
t8=t8+1;
t9=t9+1;
t10=t10+1;
}
}
//***************************************************************
void nguoi::nhay(int x,int y,int r,int a,int b,int z)
{
int t1=x+r,
t2=x+2*r,
t3=a-r,
t4=a-2*r,
t5=y+r;
for (int i=0;i<z;i++)
{
delay(20);
cleardevice();
Line();
circle (x,y,r);
line (x,y+r,a,b); //than
line (x,y+r,x-r,y+2*r); //tay trai 1
line (x-r,y+2*r,x,y+3*r); //tay trai 2
line (x,y+r,t1=t1-1,y+2*r); //tay phai 1
line (t1,y+2*r,t2=t2-1,t5=t5+1); //tay phai 2
line (a,b,t3=t3+1,b+r); //chan trai 1
line (t3,b+r,t4=t4+1,b+2*r); //chan trai 2
line (a,b,a+r,b+r); //chan phai 1
line (a+r,b+r,a,b+2*r); //chan phai 2
}
}
//***************************************************************
void nguoi::giam1(int x,int y,int r,int a,int b,int u)
{
int t1=b, //chan
t2=b+r,
t3=y, //bo phan con lai
t4=y+r,
t5=y+2*r,
t6=y+3*r;
for (int i=0;i<u;i++)
{
delay(20);
cleardevice();
Line();
circle (x,t3=t3+1,r);
line (x,t4=t4+1,a,t1=t1+1); //than
line (x,t4,x-r,t5=t5+1); //tay trai 1
line (x-r,t5,x,t6=t6+1); //tay trai 2
line (a,t1,a+r,t2=t2+1); //chan trai 1
line (a+r,t2,a,b+2*r); //chan trai 2
}
}
//***************************************************************
void nguoi::trenkhong(int x,int y,int r,int a,int b,int u)
{
int t3=a+r,
t4=b+r,
t5=a,
t6=b+2*r;
for (int i=0;i<u;i++)
{
delay(20);
cleardevice();
Line();
circle (x=x+1,y=y-1,r);
line (x,y+r,a=a+1,b=b-1); //than
line (x,y+r,x-r,y+2*r); //tay trai 1
line (x-r,y+2*r,x,y+3*r); //tay trai 2
line (a,b,t3=t3+1,t4=t4-1); //chan trai 1
line (t3,t4,t5=t5+1,t6=t6-1); //chan trai 2
}
}
//**************************************************************
void nguoi::cochan(int x,int y,int r,int a,int b,int u)
{
int t1=b, //chan
t2=b+r,
t3=y, //bo phan con lai
t4=y+r,
t5=y+2*r,
t6=y+3*r,
t7=a+r,
t8=a,
t9=b+2*r;
for (int i=0;i<u;i++)
{
delay(10);
cleardevice();
Line();
circle (x,t3,r);
line (x,t4,a,t1); //than
line (x,t4,x-r,t5); //tay trai 1
line (x-r,t5,x,t6); //tay trai 2
line (a,t1,t7,t2=t2-1); //chan trai 1
line (t7,t2,t8,t9=t9-1); //chan trai 2
}
}
//************************************************************
void nguoi::xuong(int x,int y,int r,int a,int b,int u)
{
for (int i=0;i<u;i++)
{
delay(20);
cleardevice();
Line();
circle (x,y,r);
line (x,y+r,a,b); //than
line (x,y+r,x-r,y+2*r); //tay trai 1
line (x-r,y+2*r,x,y+3*r); //tay trai 2
line (a,b,a+r,b); //chan trai 1
line (a+r,b,a,b+r); //chan trai 2
x=x+1;
a=a+1;
y=y+1;
b=b+1;
}
}
//************************************************************************
void nhom()
{
for (int i=0;i<getmaxy()/2;i++)
{
delay(10);
cleardevice();
setcolor(3);
line (120,40,510,40);
line (100,42,480,42);
line (150,30,110,100);
line (145,35,105,105);
line (100,85,500,85);
line (80,87,480,87);
line (450,35,425,105);
line (448,33,423,103);
setcolor(YELLOW);
outtextxy(getmaxx()/4,50,"ho va ten :");
outtextxy(getmaxx()/3,60," &");
setcolor(9);
outtextxy(getmaxx()/5,70," Giao Vien Phu Trach : Mai Xuan Lan");
setcolor(2);
outtextxy(getmaxx()/4,getmaxy()-i,"* * * MON : DO HOA MAY TINH * * *");
}
}
//***************************************************************************
void gioithieu()
{
delay(100);
for (int i=0;i<getmaxx()/2;i++)
{
setcolor(5);
outtextxy(i,getmaxy()/2,"CHAO MUNG CAC BAN DEN OLYMPIC BEIJING!!!");
delay(20);
cleardevice();
}
}
//**************************************************************************
void main()
{
int mh=0,mode=0;
initgraph(&mh,&mode,"g:\\borlandc\\bgi");
int x,y;
randomize();
x=random(160);
y=random(160);
nhom();
delay(2000);
gioithieu();
setcolor(10);
delay(2000);
outtextxy(getmaxx()/3,20,"BAI THI VAN DONG VIEN A");
delay(2000);
nguoi A(10,160,10,20,200);
for (int i=10;i<270;i=i+30)
A.nguoichay(i,160,10,i-10,200,20);
A.nhay(250,160,10,240,200,20);
A.giam1(250,160,10,240,200,10);
A.trenkhong(250,160,10,240,200,x);
A.cochan(250+x,160-x,10,240+x,200-x,10);
A.xuong(250+x,160-x,10,240+x,200-x,x+10);
delay(1000);
cleardevice();
cout<<"\nthanh tich VDV A:\n "<<x
*sqrt
(2)/16<<" m";
setcolor(YELLOW);
delay(1000);
setcolor(WHITE);
delay(2000);
cleardevice();
outtextxy(getmaxx()/3,20,"BAI THI VAN DONG VIEN B");
delay(1000);
nguoi B(10,160,10,20,200);
for (int j=10;j<270;j=j+30)
B.nguoichay(j,160,10,j-10,200,20);
B.nhay(250,160,10,240,200,20);
B.giam1(250,160,10,240,200,10);
B.trenkhong(250,160,10,240,200,y);
B.cochan(250+y,160-y,10,240+y,200-y,10);
B.xuong(250+y,160-y,10,240+y,200-y,10+y);
setcolor(YELLOW);
delay(1000);
cleardevice();
cout<<"\nthanh tich VDV B:\n "<<y
*sqrt
(2)/16<<" m";
delay(2000);
setcolor(11);
outtextxy(getmaxx()/3,20,"Ket qua :");
setcolor(12);
if(x>y)
{
outtextxy(getmaxx()/3,30,"Van dong vien A thang");
}
else if (x<y) outtextxy(getmaxx()/3,30,"Van dong vien B thang");
else outtextxy(getmaxx()/3,30,"2 van dong vien");
delay(5000);
getch();
closegraph();
}