home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG133.ARC
/
VILLAGE2.ARC
/
VILLAGER.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-08-07
|
13KB
|
382 lines
program Villager;
{ A multi-user game written by Andrew Scott. This version: 2
Needs: VILLAGER.INC - Include file. }
const
version = 'Version 2'; { Villager version no. }
movelimit = 30; { Maximum moves. }
xvill = 7; { X and Y co-indinates for }
yvill = 7; { village and start pos. }
xmax = 15; { Maximum X and Y }
ymax = 15; { co-ordinates. }
foodneeded = 10; { Food to complete game }
price = 2; { Price to hire a scout }
bonuspoints = 2500; { Bonus points gained when game completed }
fightbonus = 150; { Bonus points gained when a fight won }
type
strng = string[80];
people = record { Data for players }
name: strng;
xpos, ypos, gold, foodheld, foodrtrn, scouts, bonus: integer;
dead, expert, played: boolean;
end;
others = record { Data for computer players }
name: strng;
xpos, ypos, gold, foodheld: integer;
villager, friendly: boolean;
end;
pozzis = array[1..xmax,1..ymax]of integer; { Data for grid }
var
personfile: file of people; { File with players on it }
person: people; { A player }
player: people; { The player }
otherfile: file of others; { File with computer players on it }
other: others; { A computer player }
grid: pozzis; { Grid Map }
i, { Misc. uses }
turns: integer; { Turns used }
occupied: boolean;
inp: strng; { Player input stack }
lucky: array[1..2]of integer; { Position of random gold }
newspaper: file of strng; { Newspaper file }
{$I VILLAGER.INC} { Include File }
procedure instructions; { Displays instructions on run }
var
inp: strng;
begin
write('Do you want instructions [Y,n] ? ');
inp:=getinput;
if inp='' then inp:='Y';
if inp='Y' then begin
writeln('Villager - Instructions');
writeln;
writeln(' You are a villager from an African tribe, the one of the');
writeln('tribes to cease being hunters and gatherers. But.. after a');
writeln('long drought, your herds have died and with them most of your');
writeln('people.');
writeln(' You have been sent out to roam the land, gathering enough');
writeln('food for your village, but a few things make it harder than');
writeln('it seems. Firstly, most of the other tribes are savages, and');
writeln('would kill you for your insolence.. tresspassing on their');
writeln('hunting grounds. There are also strangers wandering the land,');
writeln('eager to capture your gold.. for there is gold out in the land.');
writeln('But the people you meet may care to swap, so your job is not');
writeln('too difficult. You might find some wealth lying on the ground!');
writeln(' You can wander the land on a ',xmax,' x ',ymax,
' grid, where there are');
writeln('3 other tribes hunting. Your village is at position ',
xvill,',',yvill,' and');
writeln('when you gather food, you can return there to leave it, otherwise');
writeln('others may steal it from you when you rest. For you can only');
writeln('move ',movelimit,
' spaces per day. You may use scouts to check possible directions,');
writeln('and then go that direction. When you have collected (then');
writeln('deposited) ',foodneeded,
' loads of food, you have won. Good luck!!');
writeln; write('Press RETURN to continue. ');
inp:=getinput
end;
end;
procedure initialise; { Initialises files first time and sets grid }
var
i, j: integer;
inp: strng;
begin
for i:=1 to ymax do begin for j:=1 to xmax do begin
grid[j,i]:=0
end; end;
{$I-} reset(otherfile); {$I+}
if IOresult<>0 then begin
rewrite(otherfile);
with other do begin
name:='An unfamiliar tribesman';
xpos:=random(xmax)+1; ypos:=random(ymax)+1; gold:=0; foodheld:=1;
villager:=true; friendly:= false;
end;
write(otherfile,other);
with other do begin
name:='A wandering stranger';
xpos:=random(xmax)+1; ypos:=random(ymax)+1; gold:=0; foodheld:=1;
villager:=false; friendly:= true;
end;
write(otherfile,other);
with other do begin
name:='A skillful warrior';
xpos:=random(xmax)+1; ypos:=random(ymax)+1; gold:=1; foodheld:=0;
villager:=true; friendly:= false;
end;
write(otherfile,other);
with other do begin
name:='Another tribesman';
xpos:=random(xmax)+1; ypos:=random(ymax)+1; gold:=1; foodheld:=1;
villager:=true; friendly:=true;
end;
write(otherfile,other);
with other do begin
name:='A strange person';
xpos:=random(xmax)+1; ypos:=random(ymax)+1; gold:=0; foodheld:=0;
villager:=false; friendly:=false;
end;
write(otherfile,other);
reset(otherfile);
end;
for i:=1 to 5 do begin
read(otherfile,other);
grid[other.xpos,other.ypos]:= grid[other.xpos,other.ypos]+1;
end;
close(otherfile);
reset(personfile);
while not eof(personfile) do begin
read(personfile,person);
if (player.name<>person.name) and (not person.dead) then
grid[person.xpos,person.ypos]:= grid[person.xpos,person.ypos]+1;
end;
close(personfile);
end;
function personnum(line: strng): integer; { Checks for player & loads it }
var
i: integer;
begin
i:=0;
{$I-} reset(personfile); {$I+}
if IOresult<>0 then begin
rewrite(personfile);
person:=player;
write(personfile,person);
i:=-1;
end
else begin
person.name:='';
while (person.name<>line) and not eof(personfile) do begin
read(personfile,person);
i:=i+1
end;
if eof(personfile) and (person.name<>line) then begin
person:=player;
write(personfile,person);
i:=0-i;
end;
end;
close(personfile);
if i<0 then setpaper('New player '+player.name+' plays game.') else
setpaper(player.name+' plays game.');
player:=person;
personnum:=i
end;
procedure save; { Saves player and erases mistakes in file }
var
afile: file of people;
bfile: file of others;
a: people;
begin
assign(afile,'VILL3.DAT');
assign(bfile,'VILL3.DAT');
rewrite(afile);
reset(personfile);
a.name:='';
while not eof(personfile) do begin
read(personfile,person);
if person.name<>a.name then begin
if person.name=player.name then write(afile,player)
else write(afile,person);
end;
a:= person;
end;
rewrite(personfile);
reset(afile);
while not eof(afile) do begin
read(afile,person);
write(personfile,person);
end;
close(personfile);
close(afile); erase(afile);
reset(otherfile);
rewrite(bfile);
for i:=1 to 5 do begin
read(otherfile,other);
other.xpos:=other.xpos+i;
if other.xpos>xmax then other.xpos:=other.xpos-xmax;
other.ypos:=other.ypos-i+1;
if other.ypos<1 then other.ypos:=other.ypos+ymax;
write(bfile,other);
end;
reset(bfile);
rewrite(otherfile);
for i:=1 to 5 do begin read(bfile,other); write(otherfile,other) end;
close(otherfile);
close(bfile); erase(bfile);
end;
procedure leave; { Leave/Take food at/from village }
var
i: integer;
inp: strng;
begin
if (player.xpos<>xvill) or (player.ypos<>yvill)
then writeln('You can only leave food at your tribe.') else begin
writeln('You have ',player.foodheld,' amounts of food on you..');
writeln('The tribe has ',player.foodrtrn,' amounts of food.');
writeln;
repeat
write('Options: Give or Take food, or Quit [g,t,Q]? ');
inp:=getinput;
until (inp='G') or (inp='T') or (inp='Q') or (inp='');
if inp='G' then begin
repeat
write('How much food will you give? ');
i:= strint(getinput);
until (i>=0) and (i<=player.foodheld);
player.foodrtrn:=player.foodrtrn+i;
player.foodheld:=player.foodheld-i;
case i of
0: writeln('Your tribe is confused.');
1: writeln('Your tribe is grateful.');
else writeln('Your tribe rejoices!');
end;
if player.foodrtrn>foodneeded-1 then begin
setpaper(player.name+' completes game!');
writeln('You have completed the game!!',#7,#7);
player.bonus:=player.bonus+bonuspoints;
player.foodrtrn:=0;
end;
end else if inp='T' then begin
repeat
write('How much food will you take? ');
i:= strint(getinput);
until (i>=0) and (i<=player.foodrtrn);
player.foodrtrn:=player.foodrtrn-i;
player.foodheld:=player.foodheld+i;
case i of
0: writeln('Your tribe is confused.');
1: writeln('Your tribe doesn''t like this.');
else writeln('Your tribe is very angry!');
end;
end;
end;
end;
function confirmed:boolean;
var
i: strng;
begin
if inp[1]='Q'then begin
repeat
write('Quit. Are you sure [y,N] ? ');
inp:=getinput;
until (inp='Y') or (inp='N') or (inp='');
if inp='Y' then confirmed:=true else confirmed:=false;
end;
end;
procedure help; { Immediate help on commands }
var
inp: strng;
begin
writeln('Villager - Help'); writeln;
writeln('N - Travel North, S - Travel South,');
writeln('E - Travel East, W - Travel West,');
writeln('A - Attack person, T - Trade with person,');
writeln('L - Leave/pick-up food at/from tribe, P - Display points,');
writeln('H - This HELP, X - Expert mode toggle,');
writeln('B - Borrow scouts from village, U - Use scouts,');
writeln('D - Listen/Use Drums, Q - Quit the game.');
writeln('* Note: You can''t do anything if you lose an attack.'); writeln;
write('Press RETURN to continue...');
inp:=getinput; writeln;
end;
begin { Main program }
writeln('Villager, ',version);
writeln('A multi-player game by Andrew Scott.'); writeln;
assign(personfile,'VILL1.DAT');
assign(otherfile,'VILL2.DAT');
assign(newspaper,'VILPAPER.DAT');
instructions; inp:=''; turns:=1;
with player do begin
name:=''; gold:=0; xpos:=xvill; ypos:=yvill; foodheld:=0; foodrtrn:=0;
scouts:=0; bonus:=0; dead:=false; expert:=false;
end;
repeat
write('What is your name or alias? ');
player.name:= getinput;
until player.name<>'';
i:= personnum(player.name);
if i<0 then writeln('Ah ha! A new player..');
if player.played then writeln('You have already played today!') else begin
if player.dead=true then begin
writeln('You lost a fight, but you are now healed.');
player.dead:=false;
end;
initialise;
randomize; randomize; lucky[1]:=random(xmax)+1; lucky[2]:=random(ymax)+1;
repeat
showgrid(player.xpos,player.ypos);
if inp='' then
repeat
inp:= getinput;
if inp='' then showgrid(player.xpos,player.ypos);
until inp<>'';
if inp[1] in ['N','S','E','W','A','T','L','B','U'] then turns:=turns+1;
if ((not occupied) and (inp[1] in ['A','T'])) or (((inp[1]='L') or
(inp[1]='B')) and ((player.xpos<>xvill) or (player.ypos<>yvill))) then
turns:=turns-1;
if (not player.dead) and (turns<movelimit+2) then case inp[1] of
'N': begin
player.ypos:= player.ypos+1;
if player.ypos>ymax then player.ypos:=player.ypos-ymax;
end;
'S': begin
player.ypos:= player.ypos-1;
if player.ypos<1 then player.ypos:=player.ypos+ymax;
end;
'E': begin
player.xpos:= player.xpos+1;
if player.xpos>xmax then player.xpos:=player.xpos-xmax;
end;
'W': begin
player.xpos:= player.xpos-1;
if player.xpos<1 then player.xpos:=player.xpos+xmax;
end;
'L': leave;
'A': action(1);
'T': action(2);
'B': begin
if (player.xpos<>xvill) or (player.ypos<>yvill) then
writeln('You need to be at your village.')
else getscout;
end;
'U': usescout;
end;
if inp[1]='H' then help;
if inp[1]='P' then points;
if inp[1]='X' then player.expert:=not player.expert;
if inp[1]='D' then drums;
if player.dead and not(inp[1]='Q') then
writeln('You are injured. When you play again you will be healed.');
if (turns>movelimit+1) and not(inp[1]='Q') then begin
writeln('You have expired all ',movelimit,' of your moves.');
if inp[1] in ['N','S','E','W','L','A','T','B','U'] then turns:=turns-1;
end;
if length(inp)>1 then inp:=copy(inp,2,length(inp)-1) else if inp<>'Q' then
inp:='';
until (inp='Q') and confirmed;
writeln('Leaving Villager...');
player.played:=true;
save;
end;
end.