Classic Computer Magazine Archive COMPUTE! ISSUE 10 / MARCH 1981 / PAGE 68

Fun With Apple and Pascal

Gene A. Mauney
Greensboro, NC

While using Kenneth Bowles' excellent textbook, Problem Solving Using PASCAL, to self teach Pascal, it occurred to me to write this game program and make learning Pascal even more exciting. Since completing this writing I have discovered that Bowles' 1980 book, Beginner's Guide for the USDA Pascal System, would have helped and I am sure will be helpful with my next Pascal ventures.

I tried to use as many of the Apple-Pascal graphics functions as feasible in order to gain experience with these and of course depended on the Apple Pascal Reference Manual for this. From TURTLEGRAPHICS used are: MOVE, MOVETO, TURN, TURNTO, GRAFMODE, TEXTMODE, VIEWPORT, FILLSCREEN, TURTLEX, TURTLEY, WCHAR, and CHARTYPE. And from APPLESTUFF the RANDOM, PADDLE, BUTTON, and NOTE functions.

My plan was to use as much as would fit in with my study of the beginning lessons in Bowles' text­book along with developing a program for a game suggested to me by Peter Hildebrandt, to whom goes my appreciation. Also thanks to Bill Stanley for his helpfulness. In these beginnings I found that it would have been very helpful to have had some real ApplePascal programs for examples. So my hope is that this real program will be helpful for those readers who are beginners as I. No claims are made as to the most efficient methods for programming and I am sure that others will be able to find improvements. I will be happy to hear from anyone who has comments and suggestions. I hope programmers and players will enjoy it.

The Program

BEGIN(*MAIN*) first draws the Pentagon War Games frame using the TURTLE, then proceeds to the MOVEPENT PROCEDURE. The program switches back and forth between MOVEPENT and IFPADDLE. MOVEPENT creates the pentagons beginning at a random start point (AX,AY) with SIDE = 1, and moving from there in random ways increasing by SIDE + 3 (*NOTE6*) each time for nine times. Here is a place to change the difficulty level for the player if you wish. NINE counts the times through to know when nine pentagons have been formed and also to know the score for adding up totals. IFPADDLE accesses the paddle position and moves the gun. At two places (*NOTE 4*) the TURTLEGRAPHICS procedure, CHARTYPE(6), is used to turn off the previous position of the gun and bullets by XORing the image. CHR(11) is the up arrow used for gun and bullet. If BUTTON(0) is pushed so is TRUE, the IFBUTTON PROCEDURE produces the four bullets with sound each. Hit or miss is determined (*NOTE 5*) by using the last value of X, the lower left corner of the pentagon and the last value of SIDE along with the paddle position. If a hit is made, NINE, SCORE and TSCORE are added up, destruction of the pentagon is shown along with sound (*NOTE 3*), and the message shown. The TURTLEX and Y functions are used (*NOTE 2*) to determine the X,Y value of the pentagon corner for the destruction picture and 20 lines are used here. The procedure FILLSCREEN is used (*NOTE 1*) to erase the last pentagon just before the destruction image. Finally, after five pentagon attacks, the end message is shown along with the total score.

PROGRAM PENTAWAR;
USES TURTLEGRAPHICS, APPLESTUFF;
VAR   SCORE, TSCORE, X,Y,
      NINE, SIDE, PENTA: INTEGER;
PROCEDURE THEEND;
BEGIN
  TEXTMODE;WRITELN;WRITELN;
  WRITELN('* * *   PENTAGON WARS   * * *  ');
  WRITELN;WRITELN;
  WRITELN(    YOUR TOTAL SCORE IS ',TSCORE);
  WRITELN;WRITELN;WRITELN;
  WRITELN('DIRECTIONS: ');
  WRITELN('YOU WILL SEE 5 PENTAGON ATTACKS.');
  WRITELN('YOU WILL GET ONLY 5 SHOTS.');
  WRITELN(MAXSCORE IS 45 IF YOU HIT THE');
  WRITELN('SMALLEST PENTAGON OF EACH ATTACK.');
  WRITELN(' (9,8,7, . .0 AS PENTAGONS ATTACK.)');
  WRITELN('USE APPLE GAME PADDLE 0.  ');
  WRITELN;WRITELN;WRITELN;
  WRITELN(    PRESS RETURN THEN R FOR');
  WRITELN;
  WRITELN(    A NEW GAME.  GOOD LUCK!');
  WRITELN;
END;
PROCEDURE MISS;
VAR  TIME:  INTEGER;
BEGIN
  TEXTMODE;WRITELN;WRITELN;
  WRITELN; WRITELN;WRITELN;
  WRITELN(	YOU MISSED !');
  WRITELN;
  WRITELN('ONLY ONE SHOT PER ATTACK.');
  WRITELN(' BETTER LUCK NEXT TIME.');
  WRITELN;
  WRITELN(' PRESS BUTTON TO CONTINUE.');
  WRITELN; WRITELN;WRITELN;
  WRITELN; WRITELN;WRITELN;
  FOR TIME: = 1 TO 800 DO
  BEGIN END;	(*WAIT BUTTON RELEASE*)