{JP: you need to patch this up a bit, you cannot just run this piece
of code}
{A program to demonstrate simple "text graphics": use of text and
background
colour; use of some of the "graphics characters" available on the IBM
PC;
use of RANDOM; use of gotoxy}
PROGRAM Arty;
USES CRT;
CONST MaxWallLength = 10;
TYPE
DirectionType = (up,down, left, right, none);
WhatType = (Hunter, Target, Wall, empty, visited);
PlayerType = RECORD
Kind : WhatType;
shape: char;
color :byte;
x, y : byte; {location}
END;
ScreenType = ARRAY[0..80, 0..25] OF WhatType;
VAR
code, {holds error code if parameter is wrong}
dtime: word; {delay time -- passed as parameter to the program}
fn : string; {holds name of file to read in wall configuration
from}
f : text;
orientation: char; {horiz or vertical}
wlength :byte; {length of wall}
i, j,
x, y :byte;
Robot,
PrSply : PlayerType;
Screen : ScreenType;
TacticalDirection,
MainHDirection, MainVDirection,
MainDirection:DirectionType;
Found: boolean;
ULCorner, {Box drawing characters -- not used in this program}
URCorner,
LLCorner,
LRCorner,
HBar,
VBar,
LineCross,
TDown,
TUp,
TRight,
TLeft,
BGThin, {'background' characters}
BGMed,
BGDense:char;
PROCEDURE InitPlayer( VAR P:PlayerType; W:WhatType; C:byte; S:char);
BEGIN
P.kind:=W; P.Color:=C; P.Shape:=S
END;
PROCEDURE PlaceObstacle( VAR S: ScreenType; o:char; x, y:byte; l:byte);
VAR
i {loop counter}
: byte;
BEGIN
i:=0;
IF o IN['V','v'] {Decide if wall will be horiz. or vertical}
THEN {vertical wall}
WHILE (i<=L) DO BEGIN
screen[x, y+i]:= wall; {stop if we reach edge}
IF (y+i) < 24 THEN i:=i+1 ELSE i:=L+1 END
ELSE {horizontal wall}
WHILE (i<=L) DO BEGIN
screen[x+i, y]:=wall;
IF (x+i) < 79 THEN i:=i+1 ELSE i:=L+1 END;
END;
PROCEDURE MakePath(VAR S:ScreenType; P1, P2:PlayerType);
VAR xdir, ydir, ydetour: -1..+1;
d: directiontype;
i, dcount, xsteps, ysteps:byte;
BEGIN
xsteps:=0;ysteps:=0;
REPEAT
IF P1.xP2.x THEN xdir:=-1 ELSE
xdir:=0;
IF P1.yP2.y THEN ydir:=-1 ELSE
ydir:=0;
{ IF ydir=0 THEN BEGIN FOR i:= 1 TO 3 DO BEGIN P1.y:=P1.y+1;
IF (P1.x<>P2.x) OR (P1.y<>P2.y)
THEN S[P1.x, P1.y]:=empty END; P1.x:=P1.x+xdir; IF
(P1.x<>P2.x) OR (P1.y<>P2.y)
THEN S[P1.x, P1.y]:=empty END
ELSE
IF xdir=0 THEN BEGIN FOR i:= 1 TO 3 DO BEGIN P1.x:=P1.x+1;
IF (P1.x<>P2.x) OR (P1.y<>P2.y)
THEN S[P1.x, P1.y]:=empty END END
ELSE
}
IF ydir<>0 THEN ydetour:=ydir ELSE ydetour:=-1;
IF (random<0.5) THEN
BEGIN
IF P1.x<>P2.x THEN P1.x:=P1.x+xdir; xsteps:=xsteps+1;
ysteps:=0
END
ELSE {must not increment both x and y in one step or will make
diagonal 'paths'}
BEGIN
IF (P1.y<>P2.y) OR (xsteps>5) THEN P1.y:=P1.y+ydetour;
ysteps:=ysteps+1;
END;
{now make path step}
IF (P1.x<>P2.x) OR (P1.y<>P2.y) {don't erase target}
THEN S[P1.x, P1.y]:=empty;
gotoxy(P1.x, P1.y); write('.'); delay(100);
UNTIL (P1.x=P2.x) AND (P1.y=P2.y);
END;
PROCEDURE PlacePlayer( VAR P:PlayerType; VAR S:ScreenType; Lx,
xrange:byte);
BEGIN
REPEAT
P.x:=Lx+random(xrange);
P.y:=random(22)+1;
UNTIL screen[P.x, P.y]=empty;
Screen[P.x, P.y]:=P.kind;
END;
PROCEDURE PrintPlayer(P:PlayerType);
BEGIN
gotoxy(P.x, P.y);
Textcolor(P.color);
Write(P.shape);
END;
PROCEDURE PrintWall;
BEGIN
textcolor(black);
write( BGMed )
eND;
PROCEDURE MovePlayer( VAR P:PlayerType; VAR S:ScreenType; d:
directiontype);
BEGIN
S[P.x, P.y]:=empty; {remove player from old position}
gotoxy(P.x, P.y);
write(' '); {erase player at old position on screen}
CASE d OF
up: P.y := P.y-1;
down: P.y := P.y+1;
left: P.x := P.x-1;
right: P.x := P.x+1
END;
S[P.x, P.y]:=P.kind; {place player in new position}
PrintPlayer(P); {display player on screen}
END;
FUNCTION IsBlocked (P:PlayerType; D:DirectionType; VAR
S:Screentype):boolean;
BEGIN
CASE D OF
up: IsBlocked:=NOT(S[P.x, P.y-1] IN [empty, target{, wall,
visited}]);
down: IsBlocked:=NOT(S[P.x, P.y+1] IN [empty, target{, wall,
visited}]);
left: IsBlocked:=NOT(S[P.x-1, P.y] IN [empty, target{, wall,
visited}]);
right:IsBlocked:=NOT(S[P.x+1, P.y] IN [empty, target{, wall,
visited}]);
END;
END;
PROCEDURE Visit(VAR S:ScreenType; VAR P, T:PlayerType; D:DirectionType;
VAR FoundIt:boolean);
VAR D1, D2, D3, D4 : directiontype;
xdir, ydir: -1..+1;
BEGIN
IF NOT FoundIt
THEN
IF (P.x<>T.x) OR (P.y<>T.y)
THEN
BEGIN
FoundIt:=false;
delay(100);
MovePlayer(P, S, D);
S[P.x, P.y]:=visited;
IF P.x=T.x THEN BEGIN D1:=none; D3:=none; xdir:=0 END
ELSE
IF P.x < T.x THEN BEGIN D1:=right; xdir:=+1;
D3:=left;
END
ELSE BEGIN D1:=left; xdir:=-1;
D3:=right
END;
IF P.y=T.y THEN BEGIN D2:=none; D4:=none; ydir:=0 END
ELSE
IF P.y < T.y THEN BEGIN D2:=down; ydir:=+1;
D4:=up
END
ELSE BEGIN D2:=up; ydir:=-1;
D4:=down
END;
IF (D1<>none) OR (D2<>none)
THEN
BEGIN
IF NOT (IsBlocked(P, D1, S) OR (S[P.x+xdir, P.y]=visited)) THEN
Visit(S,P, T, D1, FoundIt);
IF NOT (IsBlocked(P, D2, S) OR (S[P.x, P.y+ydir]=visited)) THEN
Visit(S,P, T, D2, Foundit) ;
IF NOT (IsBlocked(P, D3, S) OR (S[P.x+xdir, P.y]=visited)) THEN
Visit(S,P, T, D3, FoundIt) ;
IF NOT (IsBlocked(P, D4, S) OR (S[P.x, P.y+ydir]=visited)) THEN
Visit(S,P, T, D4, Foundit );
END
ELSE {we are 'over' or 'under' target, so try vertical motion first}
BEGIN
IF NOT (IsBlocked(P, D2, S) OR (S[P.x, P.y+ydir]=visited)) THEN
Visit(S,P, T, D2, Foundit) ;
IF NOT (IsBlocked(P, D1, S) OR (S[P.x+xdir, P.y]=visited)) THEN
Visit(S,P, T, D1, FoundIt);
IF NOT (IsBlocked(P, D4, S) OR (S[P.x, P.y+ydir]=visited)) THEN
Visit(S,P, T, D4, Foundit );
IF NOT (IsBlocked(P, D3, S) OR (S[P.x+xdir, P.y]=visited)) THEN
Visit(S,P, T, D3, FoundIt) ;
END;
S[P.x, P.y]:=empty
END
ELSE FoundIt:=true
ELSE
END;
BEGIN {Main Body}
{the next statement allows user to run .exe version of the program,
and pass a delay time as a parameter. This caters for machines of
different speeds}
val(paramstr(1), dtime, code); {read in delay time}
IF dtime=0 THEN dtime:=100;
{Initialise drawing characters}
{Most of these haven't been used in this program, but are
available
for use in improved versions}
ULCorner := Chr(201);
URCorner := Chr(187);
LLCorner := Chr(200);
LRCorner := Chr(188);
HBar := Chr(205);
VBar := Chr(186);
LineCross := Chr(206);
TDown := Chr(203);
TUp := Chr(202);
TRight := Chr(185);
TLeft := Chr(204);
BGThin := Chr(176);
BGMed := Chr(177);
BGDense := Chr(178);
{Clear the screen}
Textbackground(green);
Textcolor(black);
Clrscr;
randomize; {comment this out for debugging if you want same
arrangement each time}
{Set up Playing Field}
FOR i:= 1 TO 80 DO
FOR j:=1 TO 25 DO
screen[i,j]:=empty;
{Set up Players}
InitPlayer(Robot, hunter, red, BGDense);
InitPlayer(PrSply, target, yellow+blink, BGDense);
{Place the outer walls}
FOR i:=1 TO 79 DO BEGIN screen[i,1]:=wall; screen[i,25]:=wall END;
FOR i:=1 TO 25 DO BEGIN screen[1,i]:=wall; screen[79,i]:=wall END;
{Place obstacles}
IF paramcount = 2
THEN {get wall locations and lengths from external file}
BEGIN
fn:=paramstr(2);
assign(f, fn);
reset(f);
WHILE NOT eof(f) DO BEGIN
read(f, orientation); write(orientation);
read(f, x); write(x);
read(f, y); write(y);
read(f, wlength); write(wlength);
readln(f);
{readln(f, orientation, x, y, wlength);}
PlaceObstacle(Screen, orientation, x, y, wlength);
END;close(f) END
ELSE {place them randomly}
FOR i:= 1 TO 60 DO BEGIN
wlength:=random(maxwalllength)+5; {get wall length}
IF random<0.5 THEN orientation:='V' ELSE orientation:='V'; {get
orientation}
REPEAT
x:= random(70) + 5;
y:= random(20) + 2;
UNTIL Screen[x,y]=empty; {find an unused part of screen to start
wall from}
PlaceObstacle( Screen, orientation, x, y, wlength ); END;
{Place Players}
PlacePlayer(PrSply, Screen, 40, 30); {on left of screen}
PlacePlayer(Robot, Screen, 2, 20); {on right of screen}
{Make sure there is at least one free path through field}
MakePath(Screen, Robot, PrSply);
{Draw field}
FOR i:= 1 TO 79 DO
FOR j:=1 TO 25 DO BEGIN
gotoxy(i,j);
CASE screen[i,j] OF
hunter: PrintPlayer(Robot);
target: PrintPlayer(PrSply);
wall : PrintWall;
empty :
END; END;
{start hunt}
WHILE NOT keypressed DO
BEGIN {stop when any key is pressed}
IF (Robot.x<>PrSply.x) OR (Robot.y<>PrSply.y) THEN
BEGIN
IF Robot.x < PrSply.x THEN MainHdirection:=right
ELSE MainHdirection:=left;
IF Robot.y < PrSply.y THEN MainVdirection:=down
ELSE MainVdirection:=up;
IF abs(Robot.x-PrSply.x)>=abs(Robot.y-PrSply.y)
THEN BEGIN IF NOT IsBlocked(Robot, MainHDirection, Screen)
THEN MainDirection:=MainHDirection END
ELSE BEGIN IF NOT IsBlocked(Robot, MainVDirection, Screen)
THEN MainDirection:=MainVDirection END;
Visit(Screen, Robot, PrSply, MainDirection, Found)
END
ELSE {Robot and PrSply coincide, SO}
BEGIN textcolor(red+blink);
gotoxy(wherex-1, wherey);
REPEAT write(chr(random(240)+14));gotoxy(wherex-1, wherey)
UNTIL keypressed;
END
END;
END.
IF PrSply.x<>Robot.x
THEN
BEGIN
IF PrSply.x>Robot.x
THEN
direction:=right
ELSE
direction:=left;
IF direction=right THEN dirunit:=+1 ELSE dirunit:=-1;
CASE direction OF
right: IF rightpath=blocked
IF screen[Robot.x + dirunit, Robot.y]=empty
THEN
MovePlayer(Robot, Screen, direction)
ELSE
IF (screen[Robot.x, Robot.y+1]=empty) AND (DownPath=Open)
THEN
MovePlayer(Robot, Screen, down)
ELSE
MovePlayer(Robot, Screen, up)
END }
ELSE {hunted and hunter are on same x-line, so move along
y-line}
IF PrSply.y<>Robot.y
THEN
BEGIN
IF PrSply.y>Robot.y
THEN
direction:=down
ELSE
direction:=up;
IF screen[Robot.x, Robot.y]=empty
THEN
MovePlayer(Robot, Screen, direction)
ELSE
IF screen[Robot.x, Robot.y+1]=empty
THEN
MovePlayer(Robot, Screen, down)
ELSE
MovePlayer(Robot, Screen, up)
END
block:
IF Robot.x<>PrSply.x
THEN
BEGIN
IF Robot.x < PrSply.x THEN MainHdirection:=right
ELSE MainHdirection:=left;
IF Robot.y < PrSply.y THEN MainVdirection:=down
ELSE MainVdirection:=up;
IF abs(Robot.x-PrSply.x)>=abs(Robot.y-PrSply.y)
THEN MainDirection:=MainHDirection
ELSE MainDirection:=MainVDirection;
WHILE (NOT IsBlocked(Robot, Maindirection, Screen))
AND (Robot.x<>PrSply.x) DO
MovePlayer(Robot, Screen, Maindirection);
IF Robot.yPrSply.x)
AND IsBlocked(Robot, Maindirection, Screen) DO
MovePlayer(Robot, Screen, TacticalDirection);
END
ELSE {begin y-motion}
IF Robot.y<>PrSply.y
THEN
BEGIN
IF Robot.y < PrSply.y THEN Maindirection:=down ELSE
Maindirection:=up;
WHILE (NOT IsBlocked(Robot, Maindirection, Screen))
AND (Robot.y<>PrSply.y) DO
MovePlayer(Robot, Screen, Maindirection);
IF Robot.xPrSply.y)
AND IsBlocked(Robot, Maindirection, Screen) DO
MovePlayer(Robot, Screen, TacticalDirection);
END
--------------747318AB1067
Content-Type: text/plain; charset=us-ascii; name="Hunt01.pas"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Hunt01.pas"
{A program to demonstrate simple "text graphics": use of text and background
colour; use of some of the "graphics characters" available on the IBM PC;
use of RANDOM; use of gotoxy}
PROGRAM Arty;
USES CRT;
CONST MaxWallLength = 10;
TYPE
DirectionType = (up,down, left, right, none);
WhatType = (Hunter, Target, Wall, empty, visited);
PlayerType = RECORD
Kind : WhatType;
shape: char;
color :byte;
x, y : byte; {location}
END;
ScreenType = ARRAY[0..80, 0..25] OF WhatType;
VAR
code, {holds error code if parameter is wrong}
dtime: word; {delay time -- passed as parameter to the program}
fn : string; {holds name of file to read in wall configuration from}
f : text;
orientation: char; {horiz or vertical}
wlength :byte; {length of wall}
i, j,
x, y :byte;
Robot,
PrSply : PlayerType;
Screen : ScreenType;
TacticalDirection,
MainHDirection, MainVDirection,
MainDirection:DirectionType;
Found: boolean;
ULCorner, {Box drawing characters -- not used in this program}
URCorner,
LLCorner,
LRCorner,
HBar,
VBar,
LineCross,
TDown,
TUp,
TRight,
TLeft,
BGThin, {'background' characters}
BGMed,
BGDense:char;
PROCEDURE InitPlayer( VAR P:PlayerType; W:WhatType; C:byte; S:char);
BEGIN
P.kind:=W; P.Color:=C; P.Shape:=S
END;
PROCEDURE PlaceObstacle( VAR S: ScreenType; o:char; x, y:byte; l:byte);
VAR
i {loop counter}
: byte;
BEGIN
i:=0;
IF o IN['V','v'] {Decide if wall will be horiz. or vertical}
THEN {vertical wall}
WHILE (i<=L) DO BEGIN
screen[x, y+i]:= wall; {stop if we reach edge}
IF (y+i) < 24 THEN i:=i+1 ELSE i:=L+1 END
ELSE {horizontal wall}
WHILE (i<=L) DO BEGIN
screen[x+i, y]:=wall;
IF (x+i) < 79 THEN i:=i+1 ELSE i:=L+1 END;
END;
PROCEDURE MakePath(VAR S:ScreenType; P1, P2:PlayerType);
VAR xdir, ydir, ydetour: -1..+1;
d: directiontype;
i, dcount, xsteps, ysteps:byte;
BEGIN
xsteps:=0;ysteps:=0;
REPEAT
IF P1.xP2.x THEN xdir:=-1 ELSE xdir:=0;
IF P1.yP2.y THEN ydir:=-1 ELSE ydir:=0;
{ IF ydir=0 THEN BEGIN FOR i:= 1 TO 3 DO BEGIN P1.y:=P1.y+1; IF (P1.x<>P2.x) OR (P1.y<>P2.y)
THEN S[P1.x, P1.y]:=empty END; P1.x:=P1.x+xdir; IF (P1.x<>P2.x) OR (P1.y<>P2.y)
THEN S[P1.x, P1.y]:=empty END
ELSE
IF xdir=0 THEN BEGIN FOR i:= 1 TO 3 DO BEGIN P1.x:=P1.x+1; IF (P1.x<>P2.x) OR (P1.y<>P2.y)
THEN S[P1.x, P1.y]:=empty END END
ELSE
}
IF ydir<>0 THEN ydetour:=ydir ELSE ydetour:=-1;
IF (random<0.5) THEN
BEGIN
IF P1.x<>P2.x THEN P1.x:=P1.x+xdir; xsteps:=xsteps+1; ysteps:=0
END
ELSE {must not increment both x and y in one step or will make diagonal 'paths'}
BEGIN
IF (P1.y<>P2.y) OR (xsteps>5) THEN P1.y:=P1.y+ydetour; ysteps:=ysteps+1;
END;
{now make path step}
IF (P1.x<>P2.x) OR (P1.y<>P2.y) {don't erase target}
THEN S[P1.x, P1.y]:=empty;
gotoxy(P1.x, P1.y); write('.'); delay(100);
UNTIL (P1.x=P2.x) AND (P1.y=P2.y);
END;
PROCEDURE PlacePlayer( VAR P:PlayerType; VAR S:ScreenType; Lx, xrange:byte);
BEGIN
REPEAT
P.x:=Lx+random(xrange);
P.y:=random(22)+1;
UNTIL screen[P.x, P.y]=empty;
Screen[P.x, P.y]:=P.kind;
END;
PROCEDURE PrintPlayer(P:PlayerType);
BEGIN
gotoxy(P.x, P.y);
Textcolor(P.color);
Write(P.shape);
END;
PROCEDURE PrintWall;
BEGIN
textcolor(black);
write( BGMed )
eND;
PROCEDURE MovePlayer( VAR P:PlayerType; VAR S:ScreenType; d: directiontype);
BEGIN
S[P.x, P.y]:=empty; {remove player from old position}
gotoxy(P.x, P.y);
write(' '); {erase player at old position on screen}
CASE d OF
up: P.y := P.y-1;
down: P.y := P.y+1;
left: P.x := P.x-1;
right: P.x := P.x+1
END;
S[P.x, P.y]:=P.kind; {place player in new position}
PrintPlayer(P); {display player on screen}
END;
FUNCTION IsBlocked (P:PlayerType; D:DirectionType; VAR S:Screentype):boolean;
BEGIN
CASE D OF
up: IsBlocked:=NOT(S[P.x, P.y-1] IN [empty, target{, wall, visited}]);
down: IsBlocked:=NOT(S[P.x, P.y+1] IN [empty, target{, wall, visited}]);
left: IsBlocked:=NOT(S[P.x-1, P.y] IN [empty, target{, wall, visited}]);
right:IsBlocked:=NOT(S[P.x+1, P.y] IN [empty, target{, wall, visited}]);
END;
END;
PROCEDURE Visit(VAR S:ScreenType; VAR P, T:PlayerType; D:DirectionType; VAR FoundIt:boolean);
VAR D1, D2, D3, D4 : directiontype;
xdir, ydir: -1..+1;
BEGIN
IF NOT FoundIt
THEN
IF (P.x<>T.x) OR (P.y<>T.y)
THEN
BEGIN
FoundIt:=false;
delay(100);
MovePlayer(P, S, D);
S[P.x, P.y]:=visited;
IF P.x=T.x THEN BEGIN D1:=none; D3:=none; xdir:=0 END
ELSE
IF P.x < T.x THEN BEGIN D1:=right; xdir:=+1;
D3:=left;
END
ELSE BEGIN D1:=left; xdir:=-1;
D3:=right
END;
IF P.y=T.y THEN BEGIN D2:=none; D4:=none; ydir:=0 END
ELSE
IF P.y < T.y THEN BEGIN D2:=down; ydir:=+1;
D4:=up
END
ELSE BEGIN D2:=up; ydir:=-1;
D4:=down
END;
IF (D1<>none) OR (D2<>none)
THEN
BEGIN
IF NOT (IsBlocked(P, D1, S) OR (S[P.x+xdir, P.y]=visited)) THEN Visit(S,P, T, D1, FoundIt);
IF NOT (IsBlocked(P, D2, S) OR (S[P.x, P.y+ydir]=visited)) THEN Visit(S,P, T, D2, Foundit) ;
IF NOT (IsBlocked(P, D3, S) OR (S[P.x+xdir, P.y]=visited)) THEN Visit(S,P, T, D3, FoundIt) ;
IF NOT (IsBlocked(P, D4, S) OR (S[P.x, P.y+ydir]=visited)) THEN Visit(S,P, T, D4, Foundit );
END
ELSE {we are 'over' or 'under' target, so try vertical motion first}
BEGIN
IF NOT (IsBlocked(P, D2, S) OR (S[P.x, P.y+ydir]=visited)) THEN Visit(S,P, T, D2, Foundit) ;
IF NOT (IsBlocked(P, D1, S) OR (S[P.x+xdir, P.y]=visited)) THEN Visit(S,P, T, D1, FoundIt);
IF NOT (IsBlocked(P, D4, S) OR (S[P.x, P.y+ydir]=visited)) THEN Visit(S,P, T, D4, Foundit );
IF NOT (IsBlocked(P, D3, S) OR (S[P.x+xdir, P.y]=visited)) THEN Visit(S,P, T, D3, FoundIt) ;
END;
S[P.x, P.y]:=empty
END
ELSE FoundIt:=true
ELSE
END;
BEGIN {Main Body}
{the next statement allows user to run .exe version of the program,
and pass a delay time as a parameter. This caters for machines of
different speeds}
val(paramstr(1), dtime, code); {read in delay time}
IF dtime=0 THEN dtime:=100;
{Initialise drawing characters}
{Most of these haven't been used in this program, but are available
for use in improved versions}
ULCorner := Chr(201);
URCorner := Chr(187);
LLCorner := Chr(200);
LRCorner := Chr(188);
HBar := Chr(205);
VBar := Chr(186);
LineCross := Chr(206);
TDown := Chr(203);
TUp := Chr(202);
TRight := Chr(185);
TLeft := Chr(204);
BGThin := Chr(176);
BGMed := Chr(177);
BGDense := Chr(178);
{Clear the screen}
Textbackground(green);
Textcolor(black);
Clrscr;
randomize; {comment this out for debugging if you want same arrangement each time}
{Set up Playing Field}
FOR i:= 1 TO 80 DO
FOR j:=1 TO 25 DO
screen[i,j]:=empty;
{Set up Players}
InitPlayer(Robot, hunter, red, BGDense);
InitPlayer(PrSply, target, yellow+blink, BGDense);
{Place the outer walls}
FOR i:=1 TO 79 DO BEGIN screen[i,1]:=wall; screen[i,25]:=wall END;
FOR i:=1 TO 25 DO BEGIN screen[1,i]:=wall; screen[79,i]:=wall END;
{Place obstacles}
IF paramcount = 2
THEN {get wall locations and lengths from external file} BEGIN
fn:=paramstr(2);
assign(f, fn);
reset(f);
WHILE NOT eof(f) DO BEGIN
read(f, orientation); write(orientation);
read(f, x); write(x);
read(f, y); write(y);
read(f, wlength); write(wlength);
readln(f);
{readln(f, orientation, x, y, wlength);}
PlaceObstacle(Screen, orientation, x, y, wlength); END;close(f) END
ELSE {place them randomly}
FOR i:= 1 TO 60 DO BEGIN
wlength:=random(maxwalllength)+5; {get wall length}
IF random<0.5 THEN orientation:='V' ELSE orientation:='V'; {get orientation}
REPEAT
x:= random(70) + 5;
y:= random(20) + 2;
UNTIL Screen[x,y]=empty; {find an unused part of screen to start wall from}
PlaceObstacle( Screen, orientation, x, y, wlength ); END;
{Place Players}
PlacePlayer(PrSply, Screen, 40, 30); {on left of screen}
PlacePlayer(Robot, Screen, 2, 20); {on right of screen}
{Make sure there is at least one free path through field}
MakePath(Screen, Robot, PrSply);
{Draw field}
FOR i:= 1 TO 79 DO
FOR j:=1 TO 25 DO BEGIN
gotoxy(i,j);
CASE screen[i,j] OF
hunter: PrintPlayer(Robot);
target: PrintPlayer(PrSply);
wall : PrintWall;
empty :
END; END;
{start hunt}
WHILE NOT keypressed DO BEGIN {stop when any key is pressed}
IF (Robot.x<>PrSply.x) OR (Robot.y<>PrSply.y) THEN
BEGIN
IF Robot.x < PrSply.x THEN MainHdirection:=right
ELSE MainHdirection:=left;
IF Robot.y < PrSply.y THEN MainVdirection:=down
ELSE MainVdirection:=up;
IF abs(Robot.x-PrSply.x)>=abs(Robot.y-PrSply.y)
THEN BEGIN IF NOT IsBlocked(Robot, MainHDirection, Screen) THEN MainDirection:=MainHDirection END
ELSE BEGIN IF NOT IsBlocked(Robot, MainVDirection, Screen) THEN MainDirection:=MainVDirection END;
Visit(Screen, Robot, PrSply, MainDirection, Found)
END
ELSE {Robot and PrSply coincide, SO}
BEGIN textcolor(red+blink);
gotoxy(wherex-1, wherey);
REPEAT write(chr(random(240)+14));gotoxy(wherex-1, wherey) UNTIL keypressed;
END
END;
END.
IF PrSply.x<>Robot.x
THEN
BEGIN
IF PrSply.x>Robot.x
THEN
direction:=right
ELSE
direction:=left;
IF direction=right THEN dirunit:=+1 ELSE dirunit:=-1;
CASE direction OF
right: IF rightpath=blocked
IF screen[Robot.x + dirunit, Robot.y]=empty
THEN
MovePlayer(Robot, Screen, direction)
ELSE
IF (screen[Robot.x, Robot.y+1]=empty) AND (DownPath=Open)
THEN
MovePlayer(Robot, Screen, down)
ELSE
MovePlayer(Robot, Screen, up)
END }
ELSE {hunted and hunter are on same x-line, so move along y-line}
IF PrSply.y<>Robot.y
THEN
BEGIN
IF PrSply.y>Robot.y
THEN
direction:=down
ELSE
direction:=up;
IF screen[Robot.x, Robot.y]=empty
THEN
MovePlayer(Robot, Screen, direction)
ELSE
IF screen[Robot.x, Robot.y+1]=empty
THEN
MovePlayer(Robot, Screen, down)
ELSE
MovePlayer(Robot, Screen, up)
END
block:
IF Robot.x<>PrSply.x
THEN
BEGIN
IF Robot.x < PrSply.x THEN MainHdirection:=right
ELSE MainHdirection:=left;
IF Robot.y < PrSply.y THEN MainVdirection:=down
ELSE MainVdirection:=up;
IF abs(Robot.x-PrSply.x)>=abs(Robot.y-PrSply.y)
THEN MainDirection:=MainHDirection
ELSE MainDirection:=MainVDirection;
WHILE (NOT IsBlocked(Robot, Maindirection, Screen))
AND (Robot.x<>PrSply.x) DO
MovePlayer(Robot, Screen, Maindirection);
IF Robot.yPrSply.x)
AND IsBlocked(Robot, Maindirection, Screen) DO
MovePlayer(Robot, Screen, TacticalDirection);
END
ELSE {begin y-motion}
IF Robot.y<>PrSply.y
THEN
BEGIN
IF Robot.y < PrSply.y THEN Maindirection:=down ELSE Maindirection:=up;
WHILE (NOT IsBlocked(Robot, Maindirection, Screen))
AND (Robot.y<>PrSply.y) DO
MovePlayer(Robot, Screen, Maindirection);
IF Robot.xPrSply.y)
AND IsBlocked(Robot, Maindirection, Screen) DO
MovePlayer(Robot, Screen, TacticalDirection);
END
               (
geocities.com/~franzglaser)