home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
canada-remote-systems
/
c128
/
games
/
dodge.arc
/
DODGE.PAS
< prev
Wrap
Pascal/Delphi Source File
|
2019-04-13
|
12KB
|
382 lines
program dodge (input, output);
const
numattackers = 6;
length = 30;
width = 15;
numines = 15;
ninemax = 2;
type
what = (me, attacker, tank, mine, nothing);
xindex = 0..length;
yindex = 0..width;
direction = (stay, n, ne, e, se, s, sw, w, nw, nowhere);
loc = record
xcord : xindex;
ycord : yindex;
end;
var
square : array [1..width,1..length] of what;
tankloc : loc;
myloc : loc;
atack : array [1..numattackers] of loc;
ch : char;
left : 0..numattackers;
nines : 0..ninemax;
continue: char;
procedure makeboard;
var
placed : integer;
xloc : xindex;
yloc : yindex;
i,j : integer;
begin
nines := ninemax;
for i := 1 to width do
for j := 1 to length do
square [i][j] := nothing;
left := numattackers;
for i := 1 to length do
begin
square [1][i] := mine;
square [width][i] := mine;
end;
for i := 1 to width do
begin
square [i][1] := mine;
square [i][length] := mine;
end;
placed := 0;
while placed < numines do
begin
xloc := random mod length + 1;
yloc := random mod width + 1;
if square [yloc][xloc] = nothing then
begin
square [yloc][xloc] := mine;
placed := placed + 1;
end;
end;
placed := 1;
while placed <= numattackers do
begin
xloc := random mod length + 1;
yloc := random mod width + 1;
if square [yloc][xloc] = nothing then
begin
square [yloc][xloc] := attacker;
atack [placed].xcord := xloc;
atack [placed].ycord := yloc;
placed := placed + 1;
end;
end;
while square [yloc][xloc] <> nothing do
begin
xloc := random mod length + 1;
yloc := random mod width + 1;
end;
square [yloc][xloc] := tank;
tankloc.xcord := xloc;
tankloc.ycord := yloc;
while square[yloc][xloc] <> nothing do
begin
xloc := random mod length + 1;
yloc := random mod width + 1;
end;
square [yloc][xloc] := me;
myloc.xcord := xloc;
myloc.ycord := yloc
end;
(* end; *)
procedure print;
var
i : xindex;
j : yindex;
begin
for j := 1 to width do
begin
for i := 1 to length do
case square [j][i] of
me : write ('*');
tank : write ('T');
attacker : write ('$');
mine : write ('X');
nothing : write (' ');
end;
writeln ;
end;
end;
function move
(var curx : xindex;
var cury : yindex;
where : direction):what;
begin
case where of
n : cury := cury - 1;
stay : ;
s : cury := cury + 1;
w : curx := curx - 1;
e : curx := curx + 1;
nw : begin
curx := curx - 1;
cury := cury - 1;
end;
sw : begin
curx := curx - 1;
cury := cury + 1;
end;
ne : begin
curx := curx + 1;
cury := cury - 1;
end;
se : begin
curx := curx + 1;
cury := cury + 1;
end;
end;
move := square [cury][curx]
end;
function ask:what;
var
command : array ['0'..'9'] of direction; (* command list *)
dir : direction;
ch : char;
begin
dir := stay;
for ch := '0' to '9' do
begin
command [ch] := dir;
dir := succ(dir);
end;
(**)
window (1,16,40,24,1);
write ('Direction? ');
readln (ch);
if not (ch in ['0'..'9']) or ((ch = '9') and (nines = 0)) then
begin
writeln ('How is that?');
ask := ask;
end
else
begin
square [myloc.ycord][myloc.xcord] := nothing;
if ch = '9' then
begin
nines := nines - 1;
myloc.xcord := random mod length + 1;
myloc.ycord := random mod width + 1;
ch := '0';
end;
ask := move(myloc.xcord,myloc.ycord,command[ch]);
square[myloc.ycord][myloc.xcord] := me;
end;
window (0,0,79,24,0);
end;
procedure moveall;
var
i : 1..numattackers;
function which (curr : loc):direction;
var
xdir, ydir : direction;
begin
xdir := stay;
ydir := stay;
if myloc.xcord > curr.xcord then
xdir := e
else
if myloc.xcord < curr.xcord then
xdir := w;
if myloc.ycord > curr.ycord then
ydir := s
else
if myloc.ycord < curr.ycord then
ydir := n;
if (xdir = stay) or (ydir = stay) then
begin
if xdir = stay then
which := ydir
else
which := xdir
end
else
begin
case xdir of
w : if ydir = n then
which := nw
else
which := sw;
e : if ydir = n then
which := ne
else
which := se
end
end
end;
(**)
procedure checkmove (i : integer; dir : what);
var
remember, index : 1..numattackers;
begin
case dir of
nothing : square[atack[i].ycord][atack[i].xcord] := attacker;
tank : begin
window (40,5,79,8,1);
writeln ('The tank just destroyed an attacker');
atack[i].xcord := 0;
left := left - 1;
window (0,0,79,24,0);
end;
me : begin
window (40,6,79,9,1);
writeln ('You just died!!!');
myloc.xcord := 0;
WINDOW (0,0,79,24,0);
end;
attacker : begin
for index := 1 to numattackers do
if (atack[i].xcord = atack[index].xcord) and
(atack[i].ycord = atack[index].ycord) and
(i <> index) then
remember := index;
window (40,07,79,24,1);
writeln ('Two attackers just hit.');
window (0,0,79,24,0);
square [atack[remember].ycord][atack[remember].xcord]
:= nothing;
atack[i].xcord := random mod length + 1;
atack[i].ycord := random mod width + 1;
checkmove (i,move(atack[i].xcord,atack[i].ycord,
which(atack[i])));
atack [remember].xcord := random mod length + 1;
atack [remember].ycord := random mod width + 1;
checkmove (remember,move(atack[remember].xcord,
atack[remember].ycord,which(atack[remember])));
end;
mine : begin
window (40,7,79,10,1);
writeln ('An attacker just hit a mine.');
atack[i].xcord := 0;
left := left - 1;
window (0,0,79,24,0);
end;
end;
end;
begin
for i := 1 to numattackers do
begin
if atack[i].xcord > 0 then
begin
square[atack[i].ycord][atack[i].xcord] := nothing;
checkmove (i,move(atack[i].xcord, atack[i].ycord,which(atack[i])))
end;
end;
square[tankloc.ycord][tankloc.xcord] := nothing;
case move(tankloc.xcord,tankloc.ycord,which(tankloc)) of
attacker : begin
window (40,9,79,12,1);
writeln (' the tank just destroyed an attacker.');
window (0,0,79,24,0);
left := left - 1;
for i := 1 to numattackers do
if (atack[i].xcord = tankloc.xcord) and (atack[i].ycord = tankloc.ycord) then
atack[i].xcord := 0
end;
mine : begin
window (40,5,79,24,1);
writeln ('The tank just destroyed a mine.');
window (0,0,79,24,0);
end;
me : begin
window (40,10,79,13,1);
writeln ('The tank just destroyed you!');
window (0,0,79,24,0);
myloc.xcord := 0
end;
nothing :
end;
square[tankloc.ycord][tankloc.xcord] := tank;
end;
(**)
procedure inst;
begin
page ;
writeln (' *** DODGE ***');
writeln ;
writeln ('You are in a 30 by 15 square. There are ',numattackers:2,' attackers, one tank, and you.');
writeln ('If you hit one of the attackers (or the tank) you are destroyed.');
writeln ('If two attackers hit each other they are randomly put somewhere else on the');
writeln ('battlefield. If an attacker runs into the tank (or vice versa) then he is');
writeln ('destroyed. As an added bonus there are ',numines:2,' mines in the battlefield, and');
writeln ('and border of the square. Only the tank is immune to the explosion of a mine.');
writeln ('You must destroy at least 6 attackers to win the game. Moving your player is');
writeln ('accomplished by using the numeric keypad as illustrated below.');
writeln ;
writeln ('**NOTE - Pressing 0 leaves you in the same place.');
writeln (' - Pressing 9 places you randomly in the square.');
writeln ;
writeln (' NORTH 9 = TRANSPORT ');
writeln (' 1');
writeln (' NORTH/WEST 8 : 2 NORTH/EAST');
writeln (' :');
writeln (' WEST 7 .......0....... 3 EAST');
writeln (' :');
writeln (' SOUTH/WEST 6 : 4 SOUTH/EAST');
writeln (' 5');
writeln (' SOUTH');
writeln ;
end;
(* main program *)
begin
page;
writeln (' Dodge');
writeln ;
writeln ('Original program by : Joseph Kalash as published in');
writeln (' Apple Pascal Games (c) 1981 SYBEX Inc');
writeln ;
writeln ('Ported to the C128 by : Stephen A. Bungay');
writeln (' DSA Associates.');
writeln ;
writeln (' Written using Oxford Pascal by Systems Software (Oxford) Limited.');
writeln;
write (' Do you want instructions? ');
readln (ch);
if (ch = 'Y') or (ch = 'y') then
begin
inst;
write ('PRESS RETURN TO CONTINUE....');
read (continue);
writeln ;
page;
end;
repeat
page ;
makeboard;
print;
while (myloc.xcord <> 0) and (left > 0) do
begin
if ask <> nothing then
myloc.xcord := 0
else
begin
moveall;
write (chr(19));
print;
end;
writeln;
end;
if myloc.xcord = 0 then
begin
window (40,15,79,24,1);
writeln ('Well, you got yourself killed!!')
end
else
begin
window (40,15,79,24,1);
writeln ('Congratulations, you did it!!');
end;
writeln;
write ('Want to try again? ');
readln (ch);
window (0,0,79,24,1);
until ch <> 'y';
end.