Code:
/*ban tau la*/
#include"graphics.h"
#include"stdio.h"
#include"conio.h"
#include<alloc.h>
#include<stdlib.h>
#include<math.h>
#include"time.h"
#include<dos.h>
#define CK_TAU 6
#define CK_DAN 4
#define BUOC_CD 10
char*ptau,*pdan,*pbe;
int xmax,ymax;
int diem=0;
static char s_diem[5];
unsigned long int tg_giay_100(void);
void kt_va_cham(int x,int y,int*xd,int*yd,int*ban);
void ve_bt(void);
void tao_tau(void);
void tao_dan(void);
void tao_be(void);
void tau_cd(int*x,int*y,int*ch_cd);
void dan_cd(int*x,int*y,int*ban);
unsigned long int tg_giay_100(void)
{
static struct time ti;
unsigned long int t;
gettime(&ti);
/*doi ra do vi thoi gian 1/100 giay*/
t=((ti.ti_hour*60+ti.ti_min)*60+ti.ti_sec)*100+ti.ti_hund;
return t;
}
void kt_va_cham(int x,int y,int*xd,int*yd,int*ban)
{
if(abs((*xd+5)-(x+20)),20&&abs((*yd+5)-(y+12))<12)
{
sound(100);delay(100);
setcolor(0);
outtextxy(500,50,s_diem);
setcolor(YELLOW);
diem++;
itoa(diem,s_diem,10);
outtextxy(500,50,s_diem);
*ban=1;
putimage(*xd,*yd,pdan,XOR_PUT);
*xd=*yd=0;nosound();
}
}
void tau_cd(int*x,int*y,int*ch_cd)
{
int xx,yy,s;int b;
xx=*x;yy=*y;
b=random(BUOC_CD)+1;
/*xoa*/
putimage(xx,yy,ptau,XOR_PUT);
s=xx+(*ch_cd)*b;
if(s+40>xmax||s<0)*ch_cd=-(*ch_cd);
xx+=(*ch_cd)*b;
putimage(xx,yy,ptau,XOR_PUT);
*x=xx;*y=yy;
}
void dan_cd(int*x,int*y,int*ban)
{
int b,xx,yy,s;
b=random(BUOC_CD)+1;
xx=*x;yy=*y;
/*xoa*/
putimage(xx,yy,pdan,XOR_PUT);
s=yy-b;
if(s<ymax/2)*ban=1;/*cho phep ban tiep*/
else
{
yy=s;
putimage(xx,yy,pdan,XOR_PUT);
*x=xx;*y=yy;
}
}
void ve_bt(void)
{
int i,x,y;
/*ve bau troi day sao*/
cleardevice();
for(i=1;i<=1000;++i)
{
x=random(getmaxx());
y=random(getmaxy());
putpixel(x,y,random(getmaxcolor()));
}
}
void tao_dan(void)
{
unsigned n;
setcolor(YELLOW);
cleardevice();circle(5,5,5);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(5,5,YELLOW);
n=imagesize(0,0,10,10);
pdan=(char*)malloc(n);
getimage(0,0,10,10,pdan);
}
void tao_be(void)
{
unsigned n;
setcolor(BLUE);
cleardevice();
setfillstyle(SOLID_FILL,BLUE);
bar(0,0,30,20);
n=imagesize(0,0,30,20);
pbe=(char*)malloc(n);
getimage(0,0,30,20,pbe);
}
void tao_tau(void)
{
unsigned n;
setcolor(RED);
/*ve tau vu tru*/
ellipse(100,50,0,360,20,8);
ellipse(100,46,190,357,20,6);
line(107,44,110,38);
circle(90,38,2);
setfillstyle(SOLID_FILL,BLUE);
floodfill(101,54,RED);
setfillstyle(SOLID_FILL,MAGENTA);
floodfill(94,45,RED);
/*luu anh tau vu tru vao bien*/
n=imagesize(79,36,121,59);
ptau=(char*)malloc(n);
getimage(79,36,121,59,ptau);
cleardevice();
}
}