主题:谁能帮我解释这个程序
绿步甲
[专家分:1610] 发布于 2005-08-13 19:12:00
谁能帮我解释这个程序,我就佩服死他了.....
事先申明,此程序可运行的.
PASCAL程序 打飞机
program StarWars;
uses crt, graph;
type rec=record
abs: integer;
ord: integer;
typ: integer;
dir: integer;
pts: integer;
end;
rec2=record
abs: integer;
ord: integer;
typ: integer;
end;
var a, i, j, k, o, x, size, vies, pilote, mode, vd: integer;
v, m, tfm, n, blank, tie, tie2, tie3, tie4, exp1, exp2, exp3, bv, plasma,
bonus1: pointer;
tabm: array [1..40] of integer;
tabtfm: array[1..80] of rec2;
ttf: array [1..4] of rec;
bonus: rec2;
test, fin: boolean;
points: longint;
s: string;
begin
randomize;
pilote:=detect;
InitGraph(pilote,mode,'c:\tp\bgi');
clearviewport;
size:=imagesize(1,1,6,11);
new(blank);
getmem(blank,size);
getimage(1,1,6,11,blank^);
size:=imagesize(1,1,31,30);
new(bv);
getmem(bv,size);
getimage(1,1,31,30,bv^);
{Bonus}
setcolor(14);
circle(20,20,7);
setfillstyle(1,14);
floodfill(20,20,14);
setcolor(3);
outtextxy(17,17,'E');
size:=imagesize(10,10,30,30);
new(bonus1);
getmem(bonus1,size);
getimage(10,10,30,30,bonus1^);
{Explosions}
for i:=10 to 30 do begin
for j:=10 to 30 do begin
k:=10*random(2)+4;
putpixel(i,j,k);
end;
end;
setcolor(0);
circle(20,20,8);
setfillstyle(1,0);
floodfill(10,10,0);
size:=imagesize(10,10,30,30);
new(exp1);
getmem(exp1,size);
getimage(10,10,30,30,exp1^);
size:=imagesize(5,5,36,35);
new(exp3);
getmem(exp3,size);
getimage(5,5,36,35,exp3^);
for i:=10 to 40 do begin
for j:=10 to 40 do begin
k:=10*random(2)+4;
putpixel(i,j,k);
end;
end;
setcolor(0);
circle(25,25,14);
setfillstyle(1,0);
floodfill(10,10,0);
size:=imagesize(10,10,42,40);
new(exp2);
getmem(exp2,size);
getimage(10,10,42,40,exp2^);
{Tie-fighter}
for i:=1 to 4 do begin
case i of
1: a:=7;
2: a:=5;
3: a:=2;
4: a:=1;
end;
setcolor(a);
rectangle(100,100,130,130);
setfillstyle(1,a);
floodfill(115,115,a);
沙发
绿步甲 [专家分:1610] 发布于 2005-08-13 19:14:00
setcolor(0);
line(100,100,130,130);
line(130,100,100,130);
setfillstyle(1,0);
floodfill(115,120,0);
floodfill(115,110,0);
setcolor(a);
if odd(i) then
circle(115,115,7)
else
circle(115,115,5);
setfillstyle(1,a);
floodfill(115,115,a);
setcolor(0);
line(102,100,102,130);
line(105,100,105,130);
line(108,100,108,130);
line(122,100,122,130);
line(125,100,125,130);
line(128,100,128,130);
line(100,121,108,115);
line(100,108,108,115);
line(130,121,122,115);
line(130,108,122,115);
circle(115,115,4);
size:=imagesize(99,99,131,131);
case i of
1: begin
new(tie);
getmem(tie,size);
getimage(99,99,131,131,tie^)
end;
2: begin
new(tie2);
getmem(tie2,size);
getimage(99,99,131,131,tie2^);
end;
3: begin
new(tie3);
getmem(tie3,size);
getimage(99,99,131,131,tie3^);
end;
4: begin
new(tie4);
getmem(tie4,size);
getimage(99,99,131,131,tie4^);
end;
end;
end;
clearviewport;
{X-wing}
setcolor(10);
line(100,100,110,120);
line(100,100,90,120);
line(110,120,90,120);
setfillstyle(1,10);
floodfill(100,110,10);
setcolor(14);
line(112,112,117,120);
line(112,112,107,120);
line(107,120,117,120);
setcolor(14);
line(89,112,94,120);
line(89,112,84,120);
line(84,120,94,120);
setfillstyle(1,14);
floodfill(112,115,14);
floodfill(89,115,14);
size:=imagesize(83,99,118,122);
new(v);
getmem(v,size);
getimage(83,99,118,122,v^);
{Missiles}
for i:=1 to 3 do begin
case i of
1: a:=4;
2: a:=2;
3: a:=9;
end;
setcolor(a);
rectangle(2,3,5,11);
rectangle(3,4,4,10);
size:=imagesize(1,1,6,12);
case i of
1: begin new(m); getmem(m,size); getimage(1,1,6,13,m^); end;
2: begin new(tfm); getmem(tfm,size); getimage(1,1,6,13,tfm^); end;
3: begin new(plasma); getmem(plasma,size); getimage(1,1,6,13,plasma^); end;
end;
end;
{Presentation}
clearviewport;
settextstyle(3,0,9);
for i:=500 downto 150 do begin
setcolor(1);
outtextxy(100,i,'Star Wars');
delay(100);
if i<>150 then begin
setcolor(0);
outtextxy(100,i,'Star Wars');
end;
end;
settextstyle(10,0,1);
outtextxy(260,370,'Press Enter');
outtextxy(270,400,'Infos: I.');
if upcase(readkey)='I' then begin
clearviewport;
settextstyle(10,0,1);
setcolor(1);
outtextxy(40,20,'Left: 1');
outtextxy(40,50,'Right: 3');
outtextxy(40,80,'Stop: 2');
outtextxy(40,110,'Fire: Space');
outtextxy(40,140,'Quit: Q');
outtextxy(230,20,'Dark forces');
outtextxy(230,110,'Type: Escort T-fighter Assault Admiral');
outtextxy(230,140,'Shield: 5 10 15 20');
outtextxy(230,170,'Missile class: Laser Laser Plasma Plasma');
outtextxy(230,200,'Load: - - Munitions Energy');
outtextxy(230,231,'Award: 5000 10000 15000 20000');
putimage(380,50,tie^, normalput);
putimage(450,50,tie2^, normalput);
putimage(520,50,tie3^, normalput);
putimage(580,50,tie4^, normalput);
outtextxy(230,300,'Rebel forces');
outtextxy(230,330,'Type: X-wing');
outtextxy(230,360,'Shield: 10');
outtextxy(230,390,'Missile class: Laser');
putimage(500,360,v^, normalput);
outtextxy(200,450,'Programming');
repeat
for j:=1 to 20 do begin
for k:=1 to 2 do begin
if k=1 then setcolor(4) else setcolor(0);
outtextxy(320+1*j,450,'F');
outtextxy(330+2*j,450,'r');
outtextxy(340+3*j,450,'e');
outtextxy(350+4*j,450,'d');
if k=1 then delay(600);
end;
end;
for j:=20 downto 1 do begin
for k:=1 to 2 do begin
if k=1 then setcolor(4) else setcolor(0);
outtextxy(320+1*j,450,'F');
outtextxy(330+2*j,450,'r');
outtextxy(340+3*j,450,'e');
outtextxy(350+4*j,450,'d');
if k=1 then delay(600);
end;
end;
until keypressed;
end;
Clearviewport;
{Initialisations}
x:=300;
k:=0;
vies:=10;
fin:=false;
randomize;
points:=0;
vd:=0;
bonus.typ:=0;
for i:=1 to 80 do begin
tabtfm[i].abs:=0;
tabtfm[i].ord:=0;
if i<21 then tabm[2*i]:=0;
if i<5 then begin
ttf[i].abs:=0;
ttf[i].dir:=2*random(2)+1;
ttf[i].pts:=5;
ttf[i].ord:=1;
ttf[i].typ:=1;
end;
end;
setcolor(3);
line(550,1,550,460);
settextstyle(10,0,1);
outtextxy(560,80,'points:');
outtextxy(560,100,'0');
outtextxy(560,130,'Victories:');
outtextxy(560,150,'0');
outtextxy(560,180,'Energy:');
setcolor(4);
rectangle(560,200,620,203);
rectangle(560,201,620,202);
{Main repeat}
repeat
{Tie fighters appear}
test:=true;
for i:=1 to 4 do
if (ttf[i].abs>0)and(ttf[i].abs<50) then test:=false;
if test=true then begin
j:=1;
while(j<5)and(ttf[j].abs<>0) do
j:=j+1;
if j<5 then begin
ttf[j].abs:=10;
ttf[j].dir:=1;
ttf[j].ord:=1;
if random(2)=1 then begin
ttf[j].pts:=10;
ttf[j].typ:=2;
if random(3)=2 then begin
ttf[j].pts:=15;
ttf[j].typ:=3;
if random(3)=2 then begin
ttf[j].pts:=20;
ttf[j].typ:=4;
end;
end;
end else begin
ttf[j].pts:=5;
ttf[j].typ:=1;
end;
end;
end;
test:=true;
for i:=1 to 4 do
if (ttf[i].abs>0)and(ttf[i].abs>470) then test:=false;
if test=true then begin
j:=1;
while(j<5)and(ttf[j].abs<>0) do
j:=j+1;
if j<5 then begin
ttf[j].abs:=510;
ttf[j].dir:=1;
ttf[j].ord:=1;
if random(4)=3 then begin
ttf[j].pts:=10;
ttf[j].typ:=2;
if random(3)=2 then begin
ttf[j].pts:=15;
ttf[j].typ:=3;
if random(3)=2 then begin
ttf[j].pts:=20;
ttf[j].typ:=4;
end;
end;
end else begin
ttf[j].pts:=5;
ttf[j].typ:=1;
end;
end;
end;
{Get instructions}
if keypressed then k:=ord(readkey);
if k=ord('p') then repeat until keypressed;
if k=ord(' ') then begin
i:=2;
while (tabm[i]<>0)and(i<40) do i:=i+2;
tabm[i-1]:=x;
tabm[i]:=420;
k:=o;
end else o:=k;
if (o=ord('3'))and(x<510) then x:=x+1;
if (o=ord('1'))and(x>5) then x:=x-1;
{Bonus}
if bonus.typ<>0 then begin
if bonus.ord<440 then begin
bonus.ord:=bonus.ord+1;
putimage(bonus.abs,bonus.ord,bonus1^, normalput);
if (bonus.ord>420)and(bonus.abs>x-30)and(bonus.abs<x+30) then begin
sound(2000);
bonus.typ:=0;
vies:=vies+1;
setcolor(4);
rectangle(560,200,560+vies*6,203);
rectangle(560,201,560+vies*6,202);
delay(500);
nosound;
putimage(bonus.abs,bonus.ord-10,bv^, normalput);
end;
end else begin
bonus.typ:=0;
putimage(bonus.abs,440,bv^, normalput);
end;
end;
{Missiles X-wing}
i:=1;
while i<20 do begin
if tabm[2*i]>10 then begin
tabm[2*i]:=tabm[2*i]-2;
putimage(tabm[2*i-1]+15,tabm[2*i],m^, normalput);
end else begin
if tabm[2*i]>0 then begin
putimage(tabm[2*i-1]+15,tabm[2*i],blank^, normalput);
tabm[2*i]:=0;
end;
end;
i:=i+1;
end;
{Impact missile X-wing?}
i:=0;
while i<20 do begin
i:=i+1;
if tabm[2*i]<>0 then begin
for j:=1 to 4 do begin
if ttf[j].abs<>0 then begin
if (ttf[j].abs>tabm[2*i-1]-15)and(ttf[j].abs<tabm[2*i-1]+15)and(tabm[2*i]<53) then begin
putimage(tabm[2*i-1]+15,tabm[2*i],blank^, normalput);
tabm[2*i]:=0;
ttf[j].pts:=ttf[j].pts-1;
sound(1000);
setcolor(0);
str(points,s);
outtextxy(560,100,s);
points:=points+100;
setcolor(3);
str(points,s);
outtextxy(560,100,s);
delay(400);
nosound;
end;
end;
end;
end;
end;
{Missiles Tie fighter}
i:=1;
while i<80 do begin
i:=i+1;
if (tabtfm[i].ord>10)and(tabtfm[i].ord<440) then begin
tabtfm[i].ord:=tabtfm[i].ord+2;
if tabtfm[i].typ<3 then
putimage(tabtfm[i].abs+14,tabtfm[i].ord,tfm^, normalput)
else putimage(tabtfm[i].abs+14,tabtfm[i].ord,plasma^, normalput);
{Impact missile Tie fighter}
if (tabtfm[i].ord>420)and(x>tabtfm[i].abs-15)and(x<tabtfm[i].abs+15) then begin
putimage(tabtfm[i].abs+14,422,blank^, normalput);
tabtfm[i].ord:=0;
if tabtfm[i].typ<3
then vies:=vies-1
else vies:=vies-2;
sound(50);
putimage(x+5,425,exp1^, xorput);
delay(2000);
putimage(x,420,exp2^, xorput);
delay(1500);
putimage(x,410,bv^, normalput);
putimage(560+(vies-1)*6,190,bv^, normalput);
nosound;
if vies<=0 then fin:=true;
end;
end else begin
if tabtfm[i].ord>0 then begin
putimage(tabtfm[i].abs+14,440,blank^, normalput);
tabtfm[i].ord:=0;
end;
end;
end;
{Launch missiles Tie fighter}
for i:=1 to 4 do begin
if (random(100)>95)and(ttf[i].abs<>0) then begin
j:=1;
while (tabtfm[j].ord<>0)and(j<80) do
j:=j+1;
if j<81 then begin
tabtfm[j].abs:=ttf[i].abs;
tabtfm[j].ord:=ttf[i].ord+30;
tabtfm[j].typ:=ttf[i].typ;
end;
end;
end;
{Display X wing}
putimage(x,430,v^, normalput);
{Display Tie fighters}
for i:=1 to 4 do begin
if ttf[i].pts>0 then begin
if ttf[i].abs<>0 then begin
if random(100)>97 then begin
if ttf[i].dir=3 then ttf[i].dir:=1
else ttf[i].dir:=3;
if random(100)<10 then ttf[i].dir:=2;
end;
if (ttf[i].dir=1)and(ttf[i].abs>3)
then ttf[i].abs:=ttf[i].abs-1 else
if ttf[i].abs<10 then ttf[i].dir:=3;
if (ttf[i].dir=3)and(ttf[i].abs<510)
then ttf[i].abs:=ttf[i].abs+1 else
if ttf[i].abs>570 then ttf[i].dir:=1;
if (ttf[i].dir=1)and(getpixel(ttf[i].abs-5,25)<>0)and(getpixel(ttf[i].abs+35,25)=0)
then ttf[i].dir:=3;
if (ttf[i].dir=3)and(getpixel(ttf[i].abs-5,25)=0)and(getpixel(ttf[i].abs+35,25)<>0)
then ttf[i].dir:=1;
case ttf[i].typ of
1: putimage(ttf[i].abs,ttf[i].ord,tie^, normalput);
2: putimage(ttf[i].abs,ttf[i].ord,tie2^, normalput);
3: putimage(ttf[i].abs,ttf[i].ord,tie3^, normalput);
4: putimage(ttf[i].abs,ttf[i].ord,tie4^, normalput);
end;
{Descent new comers}
if ttf[i].ord<20 then ttf[i].ord:=ttf[i].ord+1;
end;
end else begin
{Explosion Tie fighter}
if ttf[i].abs<>0 then begin
sound(50);
ttf[i].pts:=ttf[i].pts-1;
if ttf[i].pts>-15 then
putimage(ttf[i].abs+5,25,exp1^, normalput);
if (ttf[i].pts<-14)and(ttf[i].pts>-30) then
putimage(ttf[i].abs,20,exp2^, normalput);
if (ttf[i].pts<-29)and(ttf[i].pts>-45) then
putimage(ttf[i].abs+1,20,exp3^, normalput);
if ttf[i].pts<-44 then begin
putimage(ttf[i].abs+1,20,bv^, normalput);
if ttf[i].typ=4 then begin
bonus.typ:=1;
bonus.abs:=ttf[i].abs;
bonus.ord:=50;
end;
setcolor(0);
str(points,s);
outtextxy(560,100,s);
points:=points+5000*ttf[i].typ;
setcolor(3);
str(points,s);
outtextxy(560,100,s);
setcolor(0);
str(vd,s);
outtextxy(560,150,s);
vd:=vd+1;
setcolor(3);
str(vd,s);
outtextxy(560,150,s);
nosound;
ttf[i].abs:=0;
end;
end;
end;
end;
until (o=ord('q'))or(fin=true);
dispose(v);
dispose(m);
dispose(tfm);
dispose(n);
dispose(tie);
dispose(bv);
{Destruction X-wing}
if fin=true then begin
clearviewport;
delay(10000);
setcolor(10);
line(300,50,100,430);
line(300,50,500,430);
line(100,430,500,430);
setfillstyle(1,10);
floodfill(300,130,10);
setcolor(14);
line(80,330,130,430);
line(80,330,30,430);
line(130,430,30,430);
setcolor(14);
line(510,330,560,430);
line(510,330,460,430);
line(560,430,460,430);
setfillstyle(1,14);
floodfill(80,380,14);
floodfill(510,380,14);
delay(10000);
setcolor(1);
rectangle(295,1,305,300);
setfillstyle(1,1);
floodfill(300,100,1);
for i:=2000 downto 20 do begin
sound(i);
delay(5);
end;
nosound;
setcolor(0);
rectangle(295,1,310,150);
setfillstyle(1,0);
floodfill(300,100,0);
setcolor(10);
line(300,50,100,430);
line(300,50,500,430);
line(100,430,500,430);
setfillstyle(1,10);
floodfill(300,130,10);
sound(50);
for i:=1 to 30 do begin
j:=random(200)+200;
k:=random(300)+100;
putimage(j,k,exp2^,xorput);
if odd(i) then begin
setcolor(4);
settextstyle(1,0,4);
outtextxy(150,430,'Critical shield failure');
end else begin
setcolor(0);
outtextxy(150,430,'Critical shield failure');
end;
delay(2000);
end;
nosound;
delay(5000);
sound(20);
setcolor(4);
outtextxy(110,430,'Emergency exit exploded');
delay(50000);
clearviewport;
nosound;
repeat
putpixel(random(650),random(450),random(10));
delay(2000);
until keypressed;
end;
closegraph;
dispose(v);
dispose(m);
dispose(tfm);
dispose(n);
dispose(blank);
dispose(tie);
dispose(tie2);
dispose(tie3);
dispose(tie4);
dispose(exp1);
dispose(exp2);
dispose(exp3);
dispose(bv);
dispose(plasma);
dispose(bonus1);
end.