新版:
uses graph,wincrt,winmouse;
var gd,gm:smallint;i,j,tx,ty,wx,wy:longint;a:array[1..14,1..20]of record d,x,y:longint;end;f:char;
procedure print;
var x1,x2,y1,y2:longint;
begin
setcolor(blue);
x1:=1;y1:=1;x2:=getmaxy;y2:=getmaxx;
repeat
rectangle(y1,x1,y2,x2);
inc(x1);inc(y1);dec(x2);dec(y2);
rectangle(y1,x1,y2,x2);
inc(x1);inc(y1);dec(x2);dec(y2);
delay(1);
until (x1>x2)or(y1>y2);
setcolor(yellow);
for i:=1 to 14 do
for j:=1 to 20 do
case a[i,j].d of
-1:
begin
setfillstyle(1,yellow);
bar((j-1)*50+1,(i-1)*50+1,j*50,i*50);
end;
1,2,3:begin setfillstyle(1,red);bar((j-1)*50+1,(i-1)*50+1,j*50,i*50);end;
-10:begin settextstyle(6,horizdir,6);outtextxy((j-1)*50+1,(i-1)*50+1,#1);end;
end;
end;
procedure run(ch:char);
var x,y:longint;
begin
f:=ch;
case ch of
'u':begin a[tx,ty].d:=2;a[tx,ty].x:=tx-1;a[tx,ty].y:=ty;tx:=tx-1;end;
'd':begin a[tx,ty].d:=2;a[tx,ty].x:=tx+1;a[tx,ty].y:=ty;tx:=tx+1;end;
'r':begin a[tx,ty].d:=2;a[tx,ty].x:=tx;a[tx,ty].y:=ty+1;ty:=ty+1;end;
'l':begin a[tx,ty].d:=2;a[tx,ty].x:=tx;a[tx,ty].y:=ty-1;ty:=ty-1;end;
end;
if a[tx,ty].d=-10 then begin a[tx,ty].d:=1;setfillstyle(1,red);bar((ty-1)*50+1,(tx-1)*50+1,ty*50,tx*50);end
else
begin
a[tx,ty].d:=1;a[wx,wy].d:=0;
x:=a[wx,wy].x;y:=a[wx,wy].y;
setfillstyle(1,blue);
bar((wy-1)*50+1,(wx-1)*50+1,wy*50,wx*50);
wx:=x;wy:=y;
setfillstyle(1,red);
bar((ty-1)*50+1,(tx-1)*50+1,ty*50,tx*50);
end;
end;
procedure failure;
begin
setcolor(yellow);
settextstyle(10,horizdir,10);
outtextxy(100,100,'YOU FAIL');
readkey;halt;
end;
procedure play;
var i,x,y:longint;ch:char;
begin
print;
repeat
ch:=' ';
delay(1000);
if keypressed then begin ch:=readkey;if ch=#0 then ch:=readkey;end;
if(tx=2)and(ch in ['w',#72])then failure;
if(tx=13)and(ch in ['s',#80])then failure;
if(ty=2)and(ch in [#75,'a'])then failure;
if(ty=19)and(ch in [#77,'d'])then failure;
if ch=' ' then
case f of
'u':if a[tx-1,ty].d=2 then failure else if(a[tx-1,ty].d<>-1)then run('u') else failure;
'd':if a[tx+1,ty].d=2 then failure else if(a[tx+1,ty].d<>-1)then run('d') else failure;
'l':if a[tx,ty-1].d=2 then failure else if(a[tx,ty-1].d<>-1)then run('l') else failure;
'r':if a[tx,ty+1].d=2 then failure else if(a[tx,ty+1].d<>-1)then run('r') else failure;
end;
case ch of
#72,'w':if a[tx-1,ty].d=2 then failure else if(a[tx-1,ty].d<>-1)then run('u') else failure;
#80,'s':if a[tx+1,ty].d=2 then failure else if(a[tx+1,ty].d<>-1)then run('d') else failure;
#75,'a':if a[tx,ty-1].d=2 then failure else if(a[tx,ty-1].d<>-1)then run('l') else failure;
#77,'d':if a[tx,ty+1].d=2 then failure else if(a[tx,ty+1].d<>-1)then run('r') else failure;
end;
x:=random(14)+1;y:=random(20)+1;
if a[x,y].d=0 then begin a[x,y].d:=-10;settextstyle(6,horizdir,6);outtextxy((y-1)*50+1,(x-1)*50+1,#1);end;
I
uses graph,wincrt,winmouse;
var gd,gm:smallint;i,j,tx,ty,wx,wy:longint;a:array[1..14,1..20]of record d,x,y:longint;end;f:char;
procedure print;
var x1,x2,y1,y2:longint;
begin
setcolor(blue);
x1:=1;y1:=1;x2:=getmaxy;y2:=getmaxx;
repeat
rectangle(y1,x1,y2,x2);
inc(x1);inc(y1);dec(x2);dec(y2);
rectangle(y1,x1,y2,x2);
inc(x1);inc(y1);dec(x2);dec(y2);
delay(1);
until (x1>x2)or(y1>y2);
setcolor(yellow);
for i:=1 to 14 do
for j:=1 to 20 do
case a[i,j].d of
-1:
begin
setfillstyle(1,yellow);
bar((j-1)*50+1,(i-1)*50+1,j*50,i*50);
end;
1,2,3:begin setfillstyle(1,red);bar((j-1)*50+1,(i-1)*50+1,j*50,i*50);end;
-10:begin settextstyle(6,horizdir,6);outtextxy((j-1)*50+1,(i-1)*50+1,#1);end;
end;
end;
procedure run(ch:char);
var x,y:longint;
begin
f:=ch;
case ch of
'u':begin a[tx,ty].d:=2;a[tx,ty].x:=tx-1;a[tx,ty].y:=ty;tx:=tx-1;end;
'd':begin a[tx,ty].d:=2;a[tx,ty].x:=tx+1;a[tx,ty].y:=ty;tx:=tx+1;end;
'r':begin a[tx,ty].d:=2;a[tx,ty].x:=tx;a[tx,ty].y:=ty+1;ty:=ty+1;end;
'l':begin a[tx,ty].d:=2;a[tx,ty].x:=tx;a[tx,ty].y:=ty-1;ty:=ty-1;end;
end;
if a[tx,ty].d=-10 then begin a[tx,ty].d:=1;setfillstyle(1,red);bar((ty-1)*50+1,(tx-1)*50+1,ty*50,tx*50);end
else
begin
a[tx,ty].d:=1;a[wx,wy].d:=0;
x:=a[wx,wy].x;y:=a[wx,wy].y;
setfillstyle(1,blue);
bar((wy-1)*50+1,(wx-1)*50+1,wy*50,wx*50);
wx:=x;wy:=y;
setfillstyle(1,red);
bar((ty-1)*50+1,(tx-1)*50+1,ty*50,tx*50);
end;
end;
procedure failure;
begin
setcolor(yellow);
settextstyle(10,horizdir,10);
outtextxy(100,100,'YOU FAIL');
readkey;halt;
end;
procedure play;
var i,x,y:longint;ch:char;
begin
print;
repeat
ch:=' ';
delay(1000);
if keypressed then begin ch:=readkey;if ch=#0 then ch:=readkey;end;
if(tx=2)and(ch in ['w',#72])then failure;
if(tx=13)and(ch in ['s',#80])then failure;
if(ty=2)and(ch in [#75,'a'])then failure;
if(ty=19)and(ch in [#77,'d'])then failure;
if ch=' ' then
case f of
'u':if a[tx-1,ty].d=2 then failure else if(a[tx-1,ty].d<>-1)then run('u') else failure;
'd':if a[tx+1,ty].d=2 then failure else if(a[tx+1,ty].d<>-1)then run('d') else failure;
'l':if a[tx,ty-1].d=2 then failure else if(a[tx,ty-1].d<>-1)then run('l') else failure;
'r':if a[tx,ty+1].d=2 then failure else if(a[tx,ty+1].d<>-1)then run('r') else failure;
end;
case ch of
#72,'w':if a[tx-1,ty].d=2 then failure else if(a[tx-1,ty].d<>-1)then run('u') else failure;
#80,'s':if a[tx+1,ty].d=2 then failure else if(a[tx+1,ty].d<>-1)then run('d') else failure;
#75,'a':if a[tx,ty-1].d=2 then failure else if(a[tx,ty-1].d<>-1)then run('l') else failure;
#77,'d':if a[tx,ty+1].d=2 then failure else if(a[tx,ty+1].d<>-1)then run('r') else failure;
end;
x:=random(14)+1;y:=random(20)+1;
if a[x,y].d=0 then begin a[x,y].d:=-10;settextstyle(6,horizdir,6);outtextxy((y-1)*50+1,(x-1)*50+1,#1);end;
I