!------------------------------------------------
!
!  Artillery
!
!  This classic interactive text game lets you
!  pick the angle of your artillery gun in
!  an attempt to knock out the enemy position.
!  The computer picks a secret distance. When
!  you fire, you will be told how much you
!  missed by, and must fire again. The object
!  is to hit the target with the fewest shells.
!
!------------------------------------------------
!
BLASTRADIUS = 50.0			:! max distance from target for a hit
DTR = 0.01745329			:! convert from degrees to radians
VELOCITY = 434.6			:! muzzle velocity
!
! choose a distance to the target
!
distance = RND(1)*5900.0
!
! not done yet...
!
done = 0
tries = 1
!
! shoot 'til we hit it
!
DO
  !
  ! get the firing angle
  !
  INPUT "Firing angle: "; ANGLE
  !
  ! compute the muzzle velocity in x, y
  !
  angle = angle*DTR
  vx = COS(angle)*VELOCITY
  vy = SIN(angle)*VELOCITY
  !
  ! find the time of flight 
  ! (velocity = acceleration*flightTime, two trips)
  !
  flightTime = 2.0*vy/32.0
  !
  ! find the distance 
  ! (distance = velocity*flightTime) 
  !
  x = vx*flightTime
  !
  ! see what happened...
  !
  IF abs(distance - x) < BLASTRADIUS THEN
    done = 1
    PRINT "A hit, after "; tries;
    IF tries = 1 THEN
      PRINT " try!"
    ELSE
      PRINT " tries!"
    END IF
    SELECT CASE tries
      CASE 1
        PRINT "(A lucky shot...)"
      CASE 2
        PRINT "Phenomenal shooting!"
      CASE 3
        PRINT "Good shooting."
      CASE ELSE
        PRINT "Practice makes perfect - try again."
    END SELECT
  ELSE IF distance > x THEN
    PRINT USING "You were short by # feet."; distance - x
  ELSE
    PRINT USING "You were over by # feet."; x - distance
  END IF
  tries = tries + 1
LOOP WHILE NOT done
