感谢上外静中任淳同学提供
uses crt;
var
xr,yr,xd,yd,xm,ym,i,p:byte;
c:char;
f:boolean;
procedure intro;
begin
clrscr;
textcolor(lightcyan);
writeln('CONTROLING KEYS:');
textcolor(7);
writeln('a: left');
writeln('d: right');
writeln('s: down');
writeln('w: up');
textcolor(yellow);
writeln('k: SHOOTING');
textcolor(7);
end;
procedure ran;
begin
xm:=random(50)+30;
ym:=random(23)+2;
end;
procedure ren;
begin
clrscr;
gotoxy(xr,yr-1);
write('*');
gotoxy(xr,yr);
write('|');
gotoxy(xr,yr+1);
write('^');
gotoxy(xm-1,ym);
write('[ ]');
end;
procedure a;
begin
if xr>2 then xr:=xr-1;
ren;
end;
procedure d;
begin
if xr<79 then xr:=xr+1;
ren;
end;
procedure s;
begin
if yr<24 then yr:=yr+1;
ren;
end;
procedure w;
begin
if yr>2 then yr:=yr-1;
ren;
end;
procedure shoot;
begin
xd:=xr;
yd:=yr;
while (xd<=80) and (xd>=1) 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;
end;
ren;
if ((xr>xm) and (xd<=xm) and (yd=ym))
or ((xr<xm) and (xd>=xm) and (yd=ym)) then begin
sound(1000);
delay(50);
nosound;
ran;
ren;
p:=p+1;
if p=8 then f:=false;
break;
end
else begin
if xr<xm then if xd+5>80 then break
else xd:=xd+5;
if xr>xm then if xd-5<1 then break
else xd:=xd-5;
end;
gotoxy(xd,yd);
write('.');
delay(50);
end;
end;
procedure over;
begin
for i:=1 to 10 do begin
clrscr;
gotoxy(36,10);
textcolor(random(10)+5);
write('YOU WIN!!!');
delay(500);
end;
end;
begin
cursoroff;
randomize;
f:=true;
xr:=2;
yr:=2;
intro;
while not keypressed do p:=0;
ran;
ren;
while f 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='k' then shoot;
end;
end;
over;
end.