Here we will make a simple Guess The Number Game. The computer will randomly generate a number from 1 to 20. The player will than have six chances to guess the number correctly. If a guess is too high or too low, the computer will let you know.
While this is a simple program, it has output from the computer to the player, input from the player to the computer, as well as some randomization.
Here is a run of the program:
This program makes use of the PEEKBYTE function from the PEEKPOKE module from page 151 of the Atari Pascal Language System Manual. This module makes a POKEBYTE procedure and a PEEKBYTE function available to Atari Pascal. With these two procedures/functions, and the classic book, Mapping The Atari, by Ian Chadwick, the whole world of the Atari 8-bit memory map becomes available to Atari Pascal programmers.
The PEEKPOKE module is required because Atari Pascal doesn't have any kind of randomizing functionality built in. The rand function in the GUESSNUM.PAS program uses the PEEKBYTE function to read a random value from the POKEY chip at address 53770. You can use this memory location in a Pascal program to generate a random integer between 0 and 255.
Atari Pascal, like most early versions of Pascal, doesn't have any kind of BREAK or CONTINUE statement when looping. To break out of a WHILE/DO loop, you need to maintain some flag variables to handle the control and flow of the looping.
To create this program, first you must enter and compile the PEEKPOKE.PAS program, then enter and compile the GUESSNUM.PAS program. Once both programs compile successfully, you can link them together (D2:GUESSNUM, D2:PEEKPOKE, PASLIB/s). Remember that the first filename listed in the link list, will become the filename of the program, with a .COM filename extension.
To run the program, run D2:GUESSNUM.COM.
This program could use another WHILE/DO loop so that the player could be prompted to "Play again?' without having to rerun the program all over again.
[More testing needed to see if it is using 0 to 20, or 1 to 20.]
Back To Contents Page
No comments:
Post a Comment