GUESSIT.ATR Disk Image
GUESSIT.P is from the book Apple Pascal Games by Douglas Hergert and Joseph T. Kalash, published by Sybex.
It is a simple, guess the random number between 1 and 100 game.
It has been slightly modified to work with Kyan Pascal on the Atari 8-bit.
Source Code
(*
* Guess It
* A Computer Guessing Game
*
* From the book 'Apple Pascal Games'
* by Douglas Hergert and Joseph T. Kalash
*
* GUESSIT.P
* Kyan Pascal 2.x / Atari 8-bit
*
*)
program guessit(Input,Output);
const
MAXTRYS = 6; (* User allowed 6 tries to guess number *)
MAXNUM = 100; (* Maximum number *)
MINNUM = 1; (* Minimum number *)
var
CH : char; (* Used to answer questions *)
GUESS : INTEGER; (* Human's guess *)
NUMBER : MINNUM..MAXNUM; (* The number itself *)
NUMTRY : 0..MAXTRYS; (* Number of times human has guessed *)
#i randoms.i
(*
* Instructions
* Prints out the instructions
*)
procedure Instructions;
begin
writeln('This is Guess It');
writeln;
writeln('I will choose a number between 1 and');
writeln('100. You will try to guess that number.');
writeln('If you guess wrong, I will tell you if');
writeln('you guessed too high, or too low.');
writeln;
writeln('Enjoy');
writeln;
end; (* Instructions *)
(*
* GETNUM
* Get a guess from the human,
* with error checking (mostly removed)
*)
procedure Getnum;
begin
write('Your guess? ');
readln(GUESS);
if GUESS > MAXNUM then
begin
writeln('Illegal number');
Getnum;
end
else
begin
if GUESS > NUMBER then
writeln('Too high')
else
if GUESS < NUMBER then
writeln('Too low')
else
writeln('Correct!!!!!')
end;
end; (* Getnum *)
Procedure Randomize;
begin
(* Seed pseudo-random number generator *)
Seed(Random_Byte,Random_Byte,Random_Byte,Random_Byte);
end;
(*
Main
*)
begin
write(chr(125)); (* Clear screen *)
Instructions;
Randomize;
CH := ' ';
while (CH <> 'N') do
begin
GUESS := 0;
NUMTRY := 0;
NUMBER := Random(MINNUM, MAXNUM); (* Get Number *)
while ( NUMTRY < MAXTRYS ) and ( GUESS <> NUMBER ) do
begin
Getnum;
NUMTRY := NUMTRY + 1;
end;
writeln;
if GUESS <> NUMBER then
writeln('The number was ', NUMBER);
writeln;
WRITE('Want to try again (''N'' to exit)? ');
readln(ch);
end
end.
No comments:
Post a Comment