感谢上外静中任淳同学提供
uses crt;
var x,y:byte;
zb:array[1..15,1..2] of byte;
i,p,q:byte;
f:array[1..30] of boolean;
l:boolean;
c:char;
procedure start;
begin
clrscr;
textcolor(lightgreen);
writeln('Controling Keys:');
textcolor(white);
writeln('a: left');
writeln('d: right');
writeln('s: down');
writeln('w: up');
textcolor(lightred);
writeln('Mission:');
textcolor(lightblue);
writeln('Collecting + signs');
writeln('* You must let the + sign get into your chest!!!');
textcolor(7);
end;
procedure init;
begin
randomize;
p:=random(6)+10;
for i:=1 to p do
begin
zb[i,1]:=random(78)+2;
zb[i,2]:=random(23)+2;
f[i]:=true;
end;
end;
procedure targets;
begin
for i:=1 to p do
if f[i] then begin
gotoxy(zb[i,1],zb[i,2]);
write('+');
end;
end;
procedure move;
begin
clrscr;
gotoxy(x,y-1);
write('*');
gotoxy(x-1,y);
write('/|\');
gotoxy(x,y+1);
write('^');
targets;
end;
procedure still;
begin
clrscr;
gotoxy(x,y-1);
write('*');
gotoxy(x,y);
write('|');
gotoxy(x,y+1);
write('^');
targets;
end;
procedure finish;
begin
clrscr;
gotoxy(36,10);
textcolor(random(8)+8);
write('YOU WIN!!!');
delay(3000);
l:=false;
end;
procedure a;
begin
if x>2 then x:=x-1;
move;
for i:=1 to p do begin
if (x=zb[i,1]) and (y=zb[i,2]) and f[i] then begin
sound(500);
delay(100);
nosound;
f[i]:=false;
q:=q+1;
if q=p then finish;
end;
end;
delay(50);
if l then still;
end;
procedure d;
begin
if x<79 then x:=x+1;
move;
for i:=1 to p do begin
if (x=zb[i,1]) and (y=zb[i,2]) and f[i] then begin
sound(500);
delay(100);
nosound;
f[i]:=false;
q:=q+1;
if q=p then finish;
end;
end;
delay(50);
if l then still;
end;
procedure s;
begin
if y<24 then y:=y+1;
move;
for i:=1 to p do begin
if (x=zb[i,1]) and (y=zb[i,2]) and f[i] then begin
sound(500);
delay(100);
nosound;
f[i]:=false;
q:=q+1;
if q=p then finish;
end;
end;
delay(50);
if l then still;
end;
procedure w;
begin
if y>2 then y:=y-1;
move;
for i:=1 to p do begin
if (x=zb[i,1]) and (y=zb[i,2]) and f[i] then begin
sound(500);
delay(100);
nosound;
f[i]:=false;
q:=q+1;
if q=p then finish;
end;
end;
delay(50);
if l then still;
end;
begin
x:=2;
y:=2;
start;
while not keypressed do q:=0;
l:=true;
init;
still;
while true 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 not l then exit;
end;
end;
end.