home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug086.arc
/
GAMES.LBR
/
RABBIT.PZS
/
RABBIT.PAS
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
5KB
|
213 lines
program RABBIT;
{Originally in BASIC for VIC-20. Conversion started 3 Sep 87.}
{$R+}
const
radius :integer = 10;
req_moves :integer = 10;
type
location = record
x,y :integer;
end;
var
died, ended, nomore :boolean;
human, rabbit :location;
move :integer;
d :real;
procedure Instruct;
var
ch :char;
begin
writeln('You are in a pit with a man-eating rabbit.');
writeln('The centre is (0,0) and it has a radius of ',radius,'.');
writeln('If you can avoid the rabbit for ',req_moves,' moves you will be released.');
writeln('You and the rabbit can move only one space each, but the rabbit can do');
writeln('multiple jumps.');
writeln('You can travel at these angles: 0, 45, 90, 135, 180, 225, 270, 315, 360.');
writeln; writeln;
write('Press RETURN to begin... ');
readln(ch);
end; (* Instruct *)
function Distance :real;
begin
distance := sqrt(sqr(rabbit.x - human.x) + sqr(rabbit.y - human.y));
end; (* Distance *)
function Within_Radius (x,y :integer) :boolean;
begin
within_radius := sqrt(sqr(x) + sqr(y)) <= radius;
end; (* Within_Radius *)
procedure Initialise;
var
dropx, dropy :integer;
begin
ended := false; died := false; move := 1;
human.x := 0; human.y := 0;
randomize;
repeat
rabbit.x := random(2*radius+1) - radius;
rabbit.y := random(2*radius+1) - radius;
until distance <= radius;
repeat
write('Where would you like to be dropped (x y)? ');
readln(dropx,dropy);
until within_radius(dropx,dropy);
human.x := dropx;
human.y := dropy;
if (human.x = rabbit.x) and (human.y = rabbit.y)
then begin
writeln('******* SQUISH *******');
writeln('You crushed the rabbit! You are set free!!!');
ended := true;
end;
end; (* Initialise *)
procedure New_Coords (angle :integer; var x,y :integer);
var
m :real;
begin
m := 1;
if (angle div 45) in [1,3,5,7] then m := sqrt(2);
x := round(m * cos(angle * (pi / 180)));
y := round(m * sin(angle * (pi / 180)));
end; (* New_Coords *)
procedure Human_Turn;
var
x,y,angle :integer;
valid :boolean;
begin
writeln; writeln('Move #',move,'. Human at (',human.x,',',human.y,')');
repeat
repeat
write('At what angle will you run? ');
readln(angle);
until (angle mod 45) = 0;
writeln('Running...');
new_coords(angle,x,y);
valid := within_radius(x+human.x,y+human.y);
if not valid then writeln('You can''t run into a wall!');
until valid;
human.x := human.x + x;
human.y := human.y + y;
writeln('Human, you are now at (',human.x,',',human.y,')');
if (human.x = rabbit.x) and (human.y = rabbit.y)
then begin
writeln('You ran right into the rabbit!!');
ended := true; died := true;
end;
end; (* Human_Turn *)
procedure Rabbit_Turn;
var
stop_pouncing :boolean;
pounce_prob, dx, dy, x, y, angle :integer;
begin
pounce_prob := 1;
repeat
stop_pouncing := true;
write('The rabbit is pouncing at angle ');
pounce_prob := succ(pounce_prob);
dx := human.x - rabbit.x;
dy := human.y - rabbit.y;
if dx = 0
then if dy < 0
then angle := 270
else angle := 90
else if dy = 0
then if dx < 0
then angle := 180
else angle := 0
else begin
angle := trunc( arctan(abs(dy div dx)) * 180 / pi );
if angle > 45+22 (* make angle a multiple of 45 degrees *)
then angle := 90
else if angle < 45-23
then angle := 0
else angle := 45;
if dx < 0
then if dy < 0
then angle := angle + 180
else angle := 180 - angle
else if dy < 0
then angle := 360 - angle;
end;
writeln(angle);
new_coords(angle,x,y);
rabbit.x := rabbit.x + x;
rabbit.y := rabbit.y + y;
if distance <> 0
then if random(pounce_prob)+1 = 1 then stop_pouncing := false;
until stop_pouncing;
end; (* Rabbit_Turn *)
function Another :boolean;
var
ans :char;
begin
writeln;
repeat
write('Another run? ');
readln(ans);
until ans in ['Y','N','y','n'];
another := ans in ['Y','y'];
end; (* Another *)
begin
nomore := false;
repeat
writeln;
writeln('RABBIT converted from BASIC by E. Reaburn: ver 1.0 3 Sep 87');
writeln;
instruct;
initialise;
while (not ended) and (move <= req_moves) do
begin
d := distance;
writeln('Rabbit at (',rabbit.x,',',rabbit.y,') and distance ',d:1:2);
if d = 0
then begin
ended := true;
died := true;
end
else begin
human_turn;
if not died then rabbit_turn;
end;
move := succ(move);
end;
if died
then writeln('*** CRUNCH *** R.I.P.')
else writeln('You are released!');
nomore := not another;
until nomore;
end.