Professional Documents
Culture Documents
LI NI U
Trong bi cnh cng ngh thng tin ngy cng pht trin, vic s
dng rng ri my tnh khng ch b hp trong vin nghin cu, cc
trng i hc, cc trung tm my tnh m cn m rng ra c quan, x
nghip, nh my. Song song vi qu trnh pht trin trn, vic ging
dy tin hc trong cc trng i hc, trung hc v mt bc trong cc trng ph thng cng c y mnh i i vi vic tng cng trang
thit b my vi tnh.
Cng vi vic sng to ra cng c mi l my tnh in t, con ngi cng tp trung tr tu tng bc xy dng ngnh khoa hc tng ng
p ng nhng yu cu khai thc ti nguyn thng tin.
m bo c vic hc tp tt. Mi hc sinh, sinh vin u
phi n lc hc tp v rn luyn. Khng nhng hc tp ti lp do thy c
gio hng dn ging dy, v truyn t nhng g cn thit cho vic
hc tp. Chng ta cn tm hiu thm v cc bi tp lin quan n
kin thc c hc, hiu r hn v kin thc m mnh hc
c trn lp cng nh l ngoi x hi. Do vic t hc ca hc sinh
sinh vin l mt iu rt quan trng bi v trn lp cc thy c s
khng c thi gian ging dy, truyn t ht tt c cc kin
thc cho chng ta. Nu chng ta ch hc cc kin thc trn lp m
khng tm hiu thm bn ngoi th s khng cho vic hc tp
ca chng ta ngay lc cng nh hc tp sau ny. c th t
c kt qu tt trong hc tp th chng ta phi lm bi tp tht
nhiu, c phn no cha hiu c th hi cc thy c, khi ta s c
thm mt s kin thc mi m ta vn cn cha bit.
Em rt chn thnh cm n cc thy c giao cho em ti
ny. N gip em hiu thm rt nhiu v phn lp trnh ho trong
MC LC
LI NI U.......................................................................................................................................2
Ni dung................................................................................................................................................4
Tng quan v bi ton.....................................................................................................................4
Chng I : Tng quan v bi ton.....................................................................................................4
1. Bi ton : M phng tr chi bn my bay............................................................................4
2. Yu cu ca bi ton :..............................................................................................................4
3. Phm vi gii quyt ..................................................................................................................5
4. Kh khn....................................................................................................................................5
Chng II : Phn tch v gii thut.................................................................................................6
1. Hng gii quyt :.......................................................................................................................6
2. Gii thut ca cc chc nng chnh trong chng trnh :........................................................6
Chng III : Cu trc chng trnh...................................................................................................10
1. Cu trc chng trnh theo s khi :.................................................................................10
2. Mt s hm, th tc v bin quan trng................................................................................12
3. Cc unit chnh........................................................................................................................12
4. M chng trnh : ....................................................................................................................12
5. Hng gii quyt ......................................................................................................................21
6.Kt lun....................................................................................................................................22
Ni dung
Tng quan v bi ton
Bi ton gm ba chng :
Chng I : Tng quan v bi ton.
Chng II : Phn tch v gii thut.
Chng III : Cu trc chng trnh.
initgraph(&mh,&mode,"D:\\TC\\BGI");
if(graphresult()!=0)
{
printf("\n KHONG THAY TRINH DIEU KHIEN DO HOA!");
moveto(x,y);
linerel(-3,-3); linerel(0,-6); linerel(2,-6); linerel(-2,-3);
linerel(3,1); linerel(3,-1);
linerel(-2,3); linerel(2,6); linerel(0,6); linerel(-3,3);
}
void drawAmmo(int x, int y)
{
setcolor(WHITE);
pieslice(x,y,0,360,1);
}
void drawBlockhouse()
{
setcolor(WHITE);
line(xmax/2-30,ymax,xmax/2-30,ymax-30);
line(xmax/2+30,ymax,xmax/2+30,ymax-30);
arc(xmax/2,ymax+10,52,128,50);
}
void drawGun(int x, int y)
{
setcolor(WHITE);
setlinestyle(SOLID_LINE,0,3);
line(xmax/2,ymax-40,x,y);
setlinestyle(SOLID_LINE,0,1);
}
void drawSky()
{
int i;
for(i=1; i<=200; i++)
SVTH: L Quc Duyt Lp 61CT2
{
putpixel(xStar[i],yStar[i],colorStar[i]);
}
}
void destroy()
{
int i;
float r;
setcolor(RED);
setfillstyle(SOLID_FILL,YELLOW);
setlinestyle(SOLID_LINE,0,3);
for(i=1; i<=10; i++)
{
if(rate[i]!=0)
{
r=rate[i]/10.0;
moveto(xdestroy[i],ydestroy[i]-r*12);
linerel(4*r,8*r);
linerel(8*r,4*r);
linerel(-
8*r,4*r); linerel(-4*r,8*r);
linerel(-4*r,-8*r);
linerel(-8*r,-4*r);
linerel(8*r,-4*r); linerel(4*r,-8*r);
if(rate[i]>2)
floodfill(xdestroy[i],ydestroy[i],RED);
rate[i]--;
}
}
setlinestyle(SOLID_LINE,0,1);
}
-Cc hm iu khin chuyn ng
SVTH: L Quc Duyt Lp 61CT2
10
Start Game
Thc Tp C Bn - M phng tr chi bn my bay
n = My
Bay
False
n = Bom
True
Bay
im
Quit Game
11
- Khi to ch ho.
- V nng sng, b sng
- V my bay,bom
- To cc v n
- V nn tri y sao
- iu kin
- ng ch ho.
4. M chng trnh :
#include <iostream.h>
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
int xmax,ymax,HP=100,SCORE=0;
int xFighter[5],yFighter[5],bombFighter1[5],bombFighter2[5];
SVTH: L Quc Duyt Lp 61CT2
12
int booleanBomb[9],xBomb[9],yBomb[9];
int booleanAmmo[11],xAmmo[11],yAmmo[11];
int xdestroy[21],ydestroy[21],rate[21];
int xGun,yGun,angleGun=90;
int xStar[201],yStar[201],colorStar[201];
float tangBomb[9],tangAmmo[6];
//__________________________KIEM
TRA
VA
KHOI
TAO
CHUONG
TRINH__________________________
int initGame()
{
//_____________________________KIEM
TRA__________________________________________
int mh=0,mode=0;
int i,j;
initgraph(&mh,&mode,"D:\\TC\\BGI");
if(graphresult()!=0)
{
printf("\n KHONG THAY TRINH DIEU KHIEN DO
HOA!");
printf("\n CHUONG TRINH KHONG THE THUC
HIEN! ...");
getch();
return 1;
}
else
{
closegraph();
13
\t\t____________________HUONG
DAN
CHOI___________________");
printf("\n \t\tSu dung phim mui ten de di chuyen
nong sung.\n");
printf("\n \t\tSu dung phim SPACE de ban.\n");
printf("\n \t\tThoat game nhan ESC.\n\n\n");
printf("\n \t\tNhan phim bat ky de bat dau
choi ...");
getch();
//____________________________KHOI
TAO____________________________________________
initgraph(&mh,&mode,"D:\\TC\\BGI");
settextstyle(0,0,1);
xmax=getmaxx();
ymax=getmaxy();
xGun=xmax/2; yGun=ymax-70;
for(i=1; i<=4; i++)
{
xFighter[i]=-50*i; yFighter[i]=20*i;
14
bombFighter1[i]=random(xmax/2);
bombFighter2[i]=random(xmax/2);
}
for(i=1; i<=8; i++) booleanBomb[i]=0;
for(i=1; i<=10; i++) booleanAmmo[i]=0;
for(i=1; i<=20; i++) rate[i]=0;
for(i=1; i<=200; i++)
{
xStar[i]=random(xmax);
yStar[i]=random(ymax);
colorStar[i]=random(getmaxcolor());
}
return 0;
}
}
//______________________________NHOM
HAM
DIEU
KHIEN
DO
HOA_______________________________
void drawFighter(int x, int y)
{
setcolor(WHITE);
moveto(x,y);
linerel(-36,0); linerel(0,-7); linerel(-6,-7); linerel(6,0);
linerel(12,7); linerel(12,0); linerel(12,7);
moveto(x-24,y-7);
linerel(-12,0);
moveto(x-12,y);
linerel(0,3); linerel(-18,0); linerel(0,-3);
}
15
16
{
int i;
for(i=1; i<=200; i++)
{
putpixel(xStar[i],yStar[i],colorStar[i]);
}
}
}
}
void controlBomb()
{
int i,j;
for(i=1; i<=8; i++)
if(booleanBomb[i])
{
yBomb[i]+=1;
xBomb[i]=xmax/2-(ymax-
yBomb[i])*tangBomb[i];
if(yBomb[i]>ymax-35)
{
if(xBomb[i]>xmax/2-30)
{
for(j=1; j<=20; j++)
if(rate[j]==0)
{
rate[j]=10;
xdestroy[j]=xBomb[i];
ydestroy[j]=yBomb[i];
17
HP=10;
break;
}
booleanBomb[i]=0;
}
}
}
}
void controlAmmo()
{
int i,j,k;
for(i=1; i<=10; i++)
{
if(booleanAmmo[i])
{
yAmmo[i]-=3;
xAmmo[i]=xmax/2-
((ymax-40-yAmmo[i])*tangAmmo[i]);
for(j=1; j<=4; j++)
{
if((yAmmo[i]<=yFighter[j])&&(yAmmo[i]>=yFighter[j]14))
if((xFighter[j]42<xAmmo[i])&&(xFighter[j]>xAmmo[i]))
{
for(k=1;
k<=20; k++)
18
if(rate[k]==0)
{
rate[k]=10;
xdestroy[k]=xFighter[j]-20; ydestroy[k]=yFighter[j]-7;
xFighter[j]=-40;
bombFighter1[j]=random(xmax/2);
bombFighter2[j]=random(xmax/2);
if(HP<100) HP+=5;
SCORE+=10;
break;
}
booleanAmmo[i]=0;
break;
}
}
for(j=1; j<=8; j++)
if(booleanBomb[j])
if((yAmmo[i]<=yBomb[j])&&(yAmmo[i]>=yBomb[j]-18))
if((xAmmo[i]<=xBomb[j]
+3)&&(xAmmo[i]>=xBomb[i]-3))
{
for(k=1; k<=20; k++)
if(rate[k]==0)
{
rate[k]=10;
xdestroy[k]=xBomb[j]; ydestroy[k]=yBomb[j]-9;
19
SCORE=SCORE+5;
booleanBomb[j]=0;
break;
}
booleanAmmo[i]=0;
break;
}
if((xAmmo[i]<0)||(xAmmo[i]>640)||(yAmmo[i]<0))
booleanAmmo[i]=0;
}
}
}
void controlGun()
{
int i;
char key;
if(kbhit())
controlAmmo();
cleardevice();
drawSky();
drawBlockhouse();
for(i=1;
i<=4;
i++)
drawFighter(xFighter[i],yFighter[i]);
for(i=1; i<=8; i++)
if(booleanBomb[i])
drawBomb(xBomb[i],yBomb[i]);
drawGun(xGun,yGun);
for(i=1; i<=5; i++)
20
if(booleanAmmo[i])
drawAmmo(xAmmo[i],yAmmo[i]);
if(HP<=0)
{
}
}
//______________________________________HAM
MAIN()____________________________________
void main()
{
if(initGame()) exit(1);
runGame();
getch();
closegraph();
}
21
6.Kt lun
22