Showing posts with label Apple Pascal Games. Show all posts
Showing posts with label Apple Pascal Games. Show all posts

Wednesday, April 29, 2020

ARTILLER.P

[Table of Contents]
ARTILLERY.ATR Disk Image




ARTILLER.P is from page 115 of the book Apple Pascal Games by Douglas Hergert and Joseph T. Kalash, published by Sybex.

It is a simple combat game where you attempt to knock out the enemy's base.

It could be a much better game if

  • the computer shot back
  • a graphical display was implemented

It has been slightly modified to work with Kyan Pascal and fit on the Atari 8-bit display.

Source Code


(*
 * Artillery
 * Fire a shell at an enemy outpost
 *
 * From the book 'Apple Pascal Games'
 * by Douglas Hergert and Joseph T. Kalash
 *
 * ARTILLER.P
 * Kyan Pascal 2.x / Atari 8-bit
 *)

Program ARTILLERY(Input,Output);
Const
   NUMSHELLS =     10;    (* Allowed 10 shells per target *)
   MINDIST   =    100;    (* Minimum distance for a target *)
   MAXDIST   =   1000;    (* Maximum distance for a target *)

   VELOCITY  =  200.0;    (* Initial velocity of 200 ft/sec *)
   GRAVITY   =   32.2;    (* Gravity of 32.2 ft/sec^2 *)
   PI        = 3.1415;
Var
   ANGLE  : REAL;         (* Angle to shoot at *)
   ENEMY  : INTEGER;      (* How far away the enemy is *)
   KILLED : INTEGER;      (* How many we have hit *)
   SHOTS  : 0..NUMSHELLS; (* Number of shells left *)
   CH     : CHAR;         (* Used to answer questions *)
   HIT    : BOOLEAN;      (* Whether the enemy has been hit *)

#i RANDOMS.I

   (*
    * DIST
    * Returns how far the shell went
    *)
   Function DIST : INTEGER;

      (*
       * TIMEINAIR
       * Figures out how long the shell
       * stays in the air
       *)
      Function TIMEINAIR:REAL;
      Begin
         TIMEINAIR := (2*VELOCITY * SIN(ANGLE)) / GRAVITY
      End; (* TIMEINAIR *)

   Begin
      DIST := ROUND((VELOCITY * COS(ANGLE)) * TIMEINAIR)
   End; (* DIST *)

   (*
    * FIRE
    * The user fires at the enemy
    *)
   Procedure FIRE;
   Begin
      Seed(Random_Byte,Random_Byte,Random_Byte,Random_Byte);
   (* ENEMY := MINDIST + RANDOM MOD MAXDIST; *)
      ENEMY := RANDOM(MINDIST,MAXDIST);

      Writeln('The enemy is ',ENEMY:3,' feet away!!!');
      SHOTS := NUMSHELLS;

      Repeat
         Write('What angle? ');
         Readln(ANGLE);
         ANGLE := (ANGLE * PI)/180.0; (* Convert from degrees to radians *)
         HIT := ABS(ENEMY-DIST) <= 1;
         If HIT Then
         Begin
            KILLED := KILLED + 1;
            Writeln('You hit him!!!');
            Writeln('It took you ',(NUMSHELLS-SHOTS),' shots');
            If KILLED = 1 Then
               Writeln('You have killed one enemy')
            Else
            Begin
               Writeln('You have now destroyed ',KILLED,' enemies of');
               Writeln('democracy');
            End;
         End
         Else
         Begin
            SHOTS := SHOTS - 1;
            If DIST > ENEMY Then
               Write('You over shot by ')
            Else
               Write('You under shot by ');
            Writeln(ABS(ENEMY - DIST))
         End
      UNTIL (SHOTS = 0) OR HIT;

      If SHOTS = 0 THEN
         Writeln('You have run out of ammo')
      End; (* Fire *)

Begin
   Write(Chr(125));
   Writeln('Welcome to Artillery');
   Writeln;
   Writeln('You are in the middle of a war');
   Writeln('(Depressing, no?) and are being charged');
   Writeln('by thousands of enemies.');
   Writeln('You job is to destroy their outpost.');
   Writeln('You have at your disposal, ');
   Writeln('a cannon, which you can shoot at any');
   Writeln('angle. As this is war, supplies are');
   Writeln('short, so you only have ',NUMSHELLS,' per target');
   Writeln;

   KILLED := 0;
   Repeat
      Writeln('********************');
      FIRE;
      Write('I see another one, care to shoot again? ');
      Readln(CH);
      While NOT (CH in ['Y','N']) Do
      Begin
         Writeln('Please answer YES or NO');
         Write('Want to try again? ');
         Readln(CH);
      End
   Until CH <> 'Y';

   Writeln;
   Writeln('You killed ', KILLED, ' of the enemy');
End. (* ARTILLERY 7/7/81 D.H. *)

Sample Run



Tuesday, April 28, 2020

GUESSIT.P

[Table of Contents]
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.

Sample Run