感谢上外静中任淳同学提供
uses crt;
label b;
var
x,y:byte; //飞机坐标
x2,y2:array[1..30] of byte; //星星坐标
f:array[1..30] of boolean; //星星是否移出屏幕或撞上飞机
sp,ss:byte; //游戏速度调节
g,wi:boolean; //游戏继续和输赢标志
yes:boolean; //是否要restart
bl:integer; //飞过的星星数量
ys:byte; //飞机颜色
i:byte; //循环控制变量
p:byte; //星星数量记数器
l:byte; //生命值
sec,sec1:byte; //随机星星出现的时间间隔
c:char; //按键读入
procedure start;
begin
clrscr;
textcolor(lightblue);
writeln('CONTROLING KEYS:');
textcolor(white);
writeln('a: left');
writeln('d: right');
writeln('s: down');
writeln('w: up');
writeln('Space: pause');
textcolor(yellow);
writeln('If you want to resume, you can press Space.');
writeln('You have only 8 lives!!!');
writeln('You will be damaged if you crashed into bricks!!!');
while not keypressed do x:=2;
end;
procedure pause;
begin
while true do
if keypressed then begin
c:=readkey;
if c=' ' then break;
end;
end;
procedure aim;
begin
for i:=1 to 30 do if (not f[i]) and (p<30) then begin
p:=p+1;
x2[i]:=80;
y2[i]:=random(22)+3;
f[i]:=true;
break;
end;
end;
procedure me;
begin
clrscr;
textcolor(yellow);
gotoxy(1,1);
write('score: ',bl);
textcolor(lightmagenta);
write(' life: ',l);
textcolor(ys);
gotoxy(x,y-1);
write('\');
gotoxy(x-1,y);
write('>---');
gotoxy(x,y+1);
write('/');
textcolor(7);
for i:=1 to 30 do if f[i] then begin
gotoxy(x2[i],y2[i]);
write('*');
end;
end;
procedure a;
begin
if x>2 then x:=x-1;
end;
procedure d;
begin
if x<78 then x:=x+1;
end;
procedure w;
begin
if y>3 then y:=y-1;
end;
procedure s;
begin
if y<24 then y:=y+1;
end;
procedure h;
begin
textcolor(lightred);
gotoxy(x,y-1);
write('\');
gotoxy(x-1,y);
write('>---');
gotoxy(x,y+1);
write('/');
sound(1000);
delay(50);
nosound;
end;
procedure gameover;
begin
clrscr;
textcolor(lightred);
gotoxy(36,10);
if not wi then write('GAME OVER')
else write('YOU WIN!!!');
textcolor(white);
gotoxy(36,13);
write('score: ',bl);
sound(1000);
nosound;
delay(2000);
end;
procedure restart;
begin
clrscr;
yes:=true;
textcolor(yellow);
gotoxy(37,11);
write('RESTART?');
gotoxy(24,12);
textcolor(white);
write('(a: left d: right Space: done)');
gotoxy(34,14);
if yes then begin
textbackground(white);
textcolor(black);
write('Yes');
textbackground(black);
textcolor(white);
write(' No');
end else begin
textbackground(black);
textcolor(white);
write('Yes ');
textbackground(white);
textcolor(black);
write('No');
end;
while true do begin
if keypressed then begin
c:=readkey;
if c='a' then begin
yes:=true;
end;
if c='d' then begin
yes:=false;
end;
if c=' ' then break;
gotoxy(34,14);
if yes then begin
textbackground(white);
textcolor(black);
write('Yes');
textbackground(black);
textcolor(white);
write(' No');
end else begin
textbackground(black);
textcolor(white);
write('Yes ');
textbackground(white);
textcolor(black);
write('No');
end;
end;
end;
textbackground(black);
end;
begin
cursoroff;
b:start;
randomize;
wi:=false;
sp:=30;
x:=2;y:=12;
l:=8;
p:=0;
ys:=10;
bl:=0;
g:=true;
sec:=random(2)*100+100;
sec1:=0;
for i:=1 to 30 do f[i]:=false;
ss:=0;
aim;
me;
while g do begin
if keypressed then begin
c:=readkey;
if c='a' then a;
if c='s' then s;
if c='d' then d;
if c='w' then w;
if c=' ' then pause;
end;
delay(sp);
sec1:=sec1+20;
if sec1=sec then begin
sec:=random(2)*20+60;
sec1:=0;
aim;
end;
for i:=1 to 30 do if f[i] then
if x2[i]>1 then x2[i]:=x2[i]-1
else begin
f[i]:=false;
p:=p-1;
bl:=bl+1;
end;
for i:=1 to 30 do
if (x2[i]>=x-1) and (x2[i]<=x+2) and (y2[i]=y) and f[i] then begin
f[i]:=false;
p:=p-1;
bl:=bl-1;
h;
l:=l-1;
if l=0 then g:=false
else if l<=2 then ys:=12
else if l<=4 then ys:=14;
end;
if (bl div 300>ss) and (sp>10) then begin ss:=bl div 300;sp:=sp-10; end;
if bl>=888 then
begin
g:=false;
wi:=true;
end;
me;
end;
gameover;
restart;
if yes then goto b;
end.