Bowling For John

Discuss popular GCS tools like ZZT, Megazeux and Adventure Game Studio, as well as programming and other topics related to game design.
Post Reply
Guest

Bowling For John

Post by Guest »

Here's my creation. It only runs in QBasic, so don't bother if you don't have it.

This is the revamped version...

Code: Select all

'THIS PROGRAM IS A SUBMISSION TO QBASICNEWS FORUM WRITTEN BY JOHN KREITLOW.
'IT HAS BEEN REORGANIZED TO REMOVE GOTOs, UNNEEDED LOOPS, AND GENERALLY MADE
'QUITE A BIT EASIER TO FOLLOW, LOGICALLY.  PLEASE LET ME KNOW IF THERE ARE
'ANY CHANGES I MADE WHICH ARE TOO DIFFICULT TO UNDERSTAND.  THANKS!
'
'                                                            - 01/27/2005 MB.

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Subroutine and Function declarations.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
DECLARE SUB Initialize ()               'SET UP INITIAL PROGRAM STATE
DECLARE SUB Intro ()                    'DISPLAY INTRO SCREEN
DECLARE SUB Instructions ()             'DISPLAY GAME DIRECTIONS
DECLARE SUB ResetPins ()                'MAKE ALL PINS STANDING
DECLARE SUB DrawLane ()                 'DRAW THE LANE, PINS, AND INFO
DECLARE SUB RollBall ()                 'ROLL THE BALL, AND CHECK COLLISIONS
DECLARE SUB HitPin (n%)                 'RECURSIVE PIN-COLLISION ROUTINE
DECLARE SUB StrikeOrSpare ()            'FLASH A MESSAGE FOR STRIKE OR SPARE
DECLARE SUB GameOver ()                 'END THE CURRENT GAME
DECLARE SUB CheckHighScore ()           'SEE IF USER SET A NEW HIGH SCORE
DECLARE SUB Pause (t&)                  'PAUSE THE PROGRAM FOR SET TIME
DECLARE FUNCTION GetBallColor% ()       'CHOOSE BALL COLOR
DECLARE FUNCTION GetLane% ()            'CHOOSE LANE TO RELEASE BALL DOWN
DECLARE FUNCTION GetPower% ()           'CHOOSE POWER OF BALL ***NOT USED***

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Variable TYPE declarations.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
TYPE BallType
     x    AS INTEGER                    'X-COORDINATE OF BALL
     y    AS INTEGER                    'Y-COORDINATE OF BALL
     c    AS INTEGER                    'COLOR OF BALL
     p    AS INTEGER                    'POWER OF BALL ***NOT USED***
END TYPE
DIM SHARED Ball AS BallType             'CREATE A BALL

TYPE PinType
     x    AS INTEGER                    'X-COORDINATE OF PIN
     y    AS INTEGER                    'Y-COORDINATE OF PIN
     Up   AS INTEGER                    'IS THE PIN STANDING? 1=YES 0=NO
END TYPE
DIM SHARED Pin(1 TO 10) AS PinType      'CREATE ARRAY OF 10 PINS
     
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'The following variables can be used / changed in any subroutine or function
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
COMMON SHARED adjScore%                 '# OF POINTS SCORED IN CURRENT ROLL
COMMON SHARED Score%                    'TOTAL SCORE FOR THE GAME
COMMON SHARED Frame%                    'WHICH FRAME IT IS [1 THROUGH 10]
COMMON SHARED Roll%                     'WHICH ROLL IT IS [1 THROUGH 2]
COMMON SHARED QuitFlag%                 '0=CONTINUE GAME, 1=END GAME
COMMON SHARED OneSecond&                '# OF LOOPS COMPUTER RUNS / SECOND

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'These next few lines set up the game to be played.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
CALL Initialize                         'INITIALIZE SOME GAME VARIABLES
CALL Intro                              'SHOW THE INTRO SCREEN
Ball.c = GetBallColor%                  'GET DESIRED BALL COLOR FROM USER
CALL Instructions                       'DISPLAY GAME INSTRUCTIONS
                                        '
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Here is the main game loop.  This runs through 10 frames, 2 rolls per frame
'unless the user hits the escape key.  If a strike is bowled, the 2nd roll
'gets skipped for that frame.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
DO WHILE QuitFlag% = 0                  '---MAIN GAME LOOP UNTIL QuitFlag%---
     Score% = 0                         'SET TOTAL GAME SCORE TO ZERO
     FOR Frame% = 1 TO 10               '   ----THIS LOOPS EACH NEW FRAME----
          CALL ResetPins                '   SET ALL THE PINS TO STANDING
          FOR Roll% = 1 TO 2            '      ---THIS LOOPS EACH NEW ROLL---
               CALL DrawLane            '      DRAW THE LANE, PINS, & INFO
               Ball.x = GetLane%        '      USER SELECTS LANE TO BOWL DOWN
               IF QuitFlag% = 1 THEN    '      DID THEY HIT ESCAPE?
                    Roll% = 2           '      ..YES. THEY CANCELLED BOWL.
                    Frame% = 10         '      ....SKIP ALL REMAINING FRAMES.
               ELSE                     '      ..NO. THEY ACTUALLY BOWLED.
                    Ball.p = GetPower%  '      ....***POWER DOES NOTHING***
                    CALL RollBall       '      ....ROLL THE BALL DOWN LANE.
               END IF                   '
          NEXT Roll%                    '      -----END OF THE ROLL LOOP-----
     NEXT Frame%                        '   ------END OF THE FRAME LOOP------
     CALL GameOver                      '   END THE CURRENT BOWLING GAME
LOOP                                    '----END LOOP WHEN QuitFlag% IS 1----

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'End the program, return control to the O/S.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
SYSTEM

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'This data contains the x- and y-coordinates of the 10 pins.  The Initialize
'subroutine loads this data into the 10-element array, Pin().
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
DATA 70  , 10                                          'PIN 1
DATA 110 , 10                                          'PIN 2
DATA 150 , 10                                          'PIN 3
DATA 190 , 10                                          'PIN 4
DATA 90  , 30                                          'PIN 5
DATA 130 , 30                                          'PIN 6
DATA 170 , 30                                          'PIN 7
DATA 110 , 50                                          'PIN 8
DATA 150 , 50                                          'PIN 9
DATA 130 , 70                                          'PIN 10

SUB CheckHighScore
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Check to see whether the user has beaten the high score.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

     OPEN "BOWLING.HSR" FOR INPUT AS #1                'OPEN HIGHSCORE FILE
          INPUT #1, HighScore.Points%                  'GET SCORE FROM FILE
          LINE INPUT #1, HighScore.Name$               'GET NAME FROM FILE
     CLOSE #1                                          'CLOSE HIGHSCORE FILE

     IF Score% > HighScore.Points% THEN                'HIGH SCORE BEATEN!!

          PRINT "CONGRATULATIONS! YOU BEAT THE HIGH"   '..\
          PRINT "SCORE. YOU SHOULD BE IN THE HALL"     '.. > DISPLAY MESSAGE
          PRINT "OF FAME!"                             '../
          PRINT
          PRINT "OLD HISCORE: "; HighScore.Points%     '..\ SHOW OLD BEST
          PRINT "MADE BY: "; HighScore.Name$           '../ SCORE AND NAME
          PRINT
          PRINT "YOUR SCORE:"; Score%                  '..SHOW YOUR SCORE

          INPUT "PLEASE ENTER YOUR NAME: ", YourName$  '..GET USER NAME
          OPEN "BOWLING.HSR" FOR OUTPUT AS #1          '..OPEN HISCORE FILE
               PRINT #1, Score%                        '..SAVE SCORE TO FILE
               PRINT #1, YourName$                     '..SAVE NAME TO FILE
          CLOSE #1                                     '..CLOSE HISCORE FILE

     ELSE                                              'HIGH SCORE NOT BEATEN
          PRINT "TOTAL SCORE:"                         '..\
          PRINT Score%                                 '../ SHOW USER SCORE
     END IF
END SUB

SUB DrawLane
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Draw the bowling lane.  This will happen at the start of each roll.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     SCREEN 7                                          '\ SET AND CLEAR
     CLS                                               '/ THE SCREEN
    
     FOR i% = 1 TO 10                                  '-START LOOP 1 TO 10--
          IF Pin(i%).Up THEN                           'IS THIS PIN STANDING?
               CIRCLE (Pin(i%).x, Pin(i%).y), 5, 15    ' ..YES, SO DRAW IT.
          END IF
     NEXT i%                                           '---END LOOP AT 10----

     LINE (300, 10)-(310, 190), 4, BF                  'DRAW RED BOX ON RIGHT
     LINE (30, 10)-(30, 190), 15                       'DRAW WHITE LINE LEFT
     LINE (230, 10)-(230, 190), 15                     'DRAW WHITE LINE RIGHT

     COLOR 15                                          'SET COLOR: WHITE
     LOCATE 2, 30: PRINT "SCORE:"                      '\
     LOCATE 3, 30: PRINT Score%                        ' \
     LOCATE 5, 30: PRINT "FRAME:"                      '  \ SHOW THE SCORE,
     LOCATE 6, 30: PRINT Frame%                        '  / FRAME, AND ROLL
     LOCATE 8, 30: PRINT "ROLL:"                       ' /
     LOCATE 9, 30: PRINT Roll%                         '/
END SUB

SUB GameOver
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Either the user bowled the last frame, or hit escape during play.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     SCREEN 0                                          '\
     WIDTH 80, 25                                      ' > SET & CLEAR SCREEN
     CLS                                               '/

     CALL CheckHighScore                               'CHECK FOR NEW HISCORE

     PRINT
     PRINT "CREATED BY JOHN KREITLOW"                  '\ CLOSING GAME
     PRINT "IN ASSOCIATION WITH RADIUM-V"              '/ CREDITS
     PRINT
    
     PRINT "Play Again? (Y/N)"                         'WANT TO PLAY AGAIN?
     DO                                                '-----START LOOP------
          k$ = UCASE$(INKEY$)                          'MONITOR KEYPRESS
     LOOP UNTIL k$ = "Y" OR k$ = "N"                   '---END WHEN Y OR N---
     IF k$ = "N" THEN QuitFlag% = 1 ELSE QuitFlag% = 0 'SET QuitFlag%
END SUB

FUNCTION GetBallColor%
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Change to Screen Mode 7 to display the balls and clear keyboard buffer.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     WHILE INKEY$ <> ""&#58; WEND
     SCREEN 7

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Make a string to hold the seven ball color values.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     BallColors$ = "01020304051214"
    
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Display all seven balls, and a message prompting selection.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     FOR i% = 1 TO 7
          CIRCLE &#40;i% * 40 - 5, 10&#41;, 10, VAL&#40;MID$&#40;BallColors$, i% * 2 - 1, 2&#41;&#41;
     NEXT i%
     LOCATE 12, 5&#58; PRINT "PLEASE SELECT YOUR BALL COLOR."

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'ArrowX% and ArrowY% store the coordinates of the selection indicator.
     'By adjusting the ArrowY% value inside of a loop and a random color,
     'the indicator appears to be pointing at the selected ball and flashing.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     ArrowX% = 5                                            'START X-COORD
     DO
          ArrowY% = 8                                       'START Y-COORD
          DO
               ArrowY% = ArrowY% - 1                        'MOVE ARROW UP
               IF ArrowY% = 4 THEN ArrowY% = 7              'RESET ARROW
              
               COLOR INT&#40;RND * 15&#41; + 1                      'RANDOM COLOR
               LOCATE ArrowY%, ArrowX%&#58; PRINT CHR$&#40;127&#41;;    'DRAW ARROW
               Pause OneSecond& / 50                        'SHORT PAUSE
               LOCATE ArrowY%, ArrowX%&#58; PRINT " ";          'ERASE ARROW
              
               k$ = UCASE$&#40;INKEY$&#41;                          'CHECK KEYPRESS
          LOOP UNTIL k$ <> ""                               'EXIT ON KEYPRESS
         
          '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
          'If the user hits left or right arrow keys, adjust ArrowX% if able.
          '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
          SELECT CASE k$
               CASE CHR$&#40;0&#41; + "K"
                    IF ArrowX% > 5 THEN ArrowX% = ArrowX% - 5
               CASE CHR$&#40;0&#41; + "M"
                    IF ArrowX% < 35 THEN ArrowX% = ArrowX% + 5
          END SELECT
     LOOP UNTIL k$ = CHR$&#40;13&#41;

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Return to Screen Mode 0.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     SCREEN 0
     WIDTH 80, 25
    
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Set the return value of the function to the appropriate color value.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     GetBallColor% = VAL&#40;MID$&#40;BallColors$, &#40;ArrowX% \ 5&#41; * 2 - 1, 2&#41;&#41;
END FUNCTION

FUNCTION GetLane%
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'This function returns the lane down which the user rolls their ball.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     WHILE INKEY$ <> ""&#58; WEND                          'CLEAR KEYBOARD BUFFER

     x% = 41                                           'WHERE BALL IS
     xAdj% = 1                                         'DIRECTION IT'S GOING
    
     DO                                                '-----START LOOP------
          x% = x% + xAdj%                              'MOVE BALL
          IF x% = 41 OR x% = 219 THEN xAdj% = -xAdj%   'REVERSE DIRECTION

          CIRCLE &#40;x%, 190&#41;, 10, Ball.c                 'DRAW BALL IN COLOR
          Pause OneSecond& / 800                       'PAUSE SHORT MOMENT
          CIRCLE &#40;x%, 190&#41;, 10, 0                      'ERASE BALL

          k$ = INKEY$                                  'CHECK FOR KEYPRESS
     LOOP UNTIL k$ = CHR$&#40;13&#41; OR k$ = CHR$&#40;27&#41;         '-END @ ENTER OR ESC--
     IF k$ = CHR$&#40;27&#41; THEN QuitFlag% = 1               'IF ESC, SET QuitFlag%

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'This next formula looks complex.  Basically, we want the ball's x-coord
     'to be&#58; 50, 70, 90, 110, 130, 150, 170, 190, or 210.  This formula says&#58;
     '
     '    if ball is between 40 and 60, make it 50
     '    if ball is between 60 and 80, make it 70
     '
     '                   etc, etc...
     '
     '    if ball is between 180 and 200, make it 190
     '    if ball is between 200 and 220, make it 210
     '
     'Again, let me know if you have trouble following how this works.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
     GetLane% = &#40;&#40;x% - 40&#41; \ 20&#41; * 20 + 50             'CENTER BALL IN LANE
END FUNCTION

FUNCTION GetPower%
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     '                         *** NOTE TO JOHN ***
     '
     ' I spent a while looking through your code and couldn't figure
     'out how the power of the ball affected anything.  So I just left
     'that part of of the re-written code.  However, if you want it in
     'here, either let me know, or write it in this area. =&#41;
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
END FUNCTION

SUB HitPin &#40;n%&#41;
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'This routine uses recursion to calculate your score for this roll. It
     'it passed the value of the pin your ball hit, then checks to see is the
     'pin is standing or not.  If it is not, nothing happens and your score
     'is unchanged.  If the pin is standing, it knocks it over, then calls
     'HitPin &#40;itself&#41; on any pins that first pin might have bumped into.
     'The variable adjScore% keeps track of the total pin count of the roll.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'First of all, check to see whether a strike or spare was rolled, since
     'either of these results in a special score value &#40;i.e. not just the
     'number of pins that got knocked over&#41;.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     IF n% = 10 THEN                                   'SPARE OR STRIKE!

          IF Roll% = 1 THEN                            '1ST ROLL, SO STRIKE
               CALL StrikeOrSpare                      '..FLASH MESSAGE
               adjScore% = 30                          '..SET adjScore% TO 30
               Roll% = 2                               '..NEXT ROLL SKIPPED

          ELSE                                         '2ND ROLL, SO SPARE.
               CALL StrikeOrSpare                      '..FLASH MESSAGE
               adjScore% = 20                          '..SET adjScore% TO 20
          END IF
    
    
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'If the 10-pin &#40;front pin&#41; is not hit, there is no strike or spare. So
     'next we check to see if the pin is standing.  If so, make it knocked
     'down, erase it from screen, and increase adjScore% variable.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     ELSE                                              'NO SPARE OR STRIKE!

          IF Pin&#40;n%&#41;.Up = 1 THEN                       'THE PIN IS STANDING
               Pin&#40;n%&#41;.Up = 0                          '..KNOCK IT OVER
               CIRCLE &#40;Pin&#40;n%&#41;.x, Pin&#40;n%&#41;.y&#41;, 5, 0     '..ERASE IT
               adjScore% = adjScore% + 1               '..ADD 1 TO adjScore%

               '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
               'Since the pin was standing, we need to see what other pins it
               'might knock into.  For each one of those, we call HitPin sub.
               '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
              
               SELECT CASE n%           'WHICH PIN ARE WE LOOKING AT?
                    CASE 5              '..PIN 5
                         HitPin 1       '  ..PIN 5 HITS PIN 1
                         HitPin 2       '  ..PIN 5 HITS PIN 2
                    CASE 6              '..PIN 6
                         HitPin 2       '  ..PIN 6 HITS PIN 2
                         HitPin 3       '  ..PIN 6 HITS PIN 3
                    CASE 7              '..PIN 7
                         HitPin 3       '  ..PIN 7 HITS PIN 3
                         HitPin 4       '  ..PIN 7 HITS PIN 4
                    CASE 8              '..PIN 8
                         HitPin 5       '  ..PIN 8 HITS PIN 5
                         HitPin 6       '  ..PIN 8 HITS PIN 6
                    CASE 9              '..PIN 9
                         HitPin 6       '  ..PIN 9 HITS PIN 6
                         HitPin 7       '  ..PIN 9 HITS PIN 7
               END SELECT

               '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
               'Recursion is kind of tricky to understand at first.  Imagine
               'if you hit pin 9 first.  Well, you get 1 point for that, and
               'also hit pins 6 and 7.  Well, when HitPin 6 and 7 get called,
               'those each give you one point.  HitPin 6 then hits 2 and 3,
               'while HitPin 7 hits pins 3 and 4.  But because HitPin 6
               'already called HitPin 3, by the time HitPin 7 calls HitPin 3,
               'Pin 3 is already knocked over. Let me know if you have any
               'trouble following the logic here. =&#41;
               '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
          END IF
     END IF
END SUB

SUB Initialize
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Seed the RND&#40;&#41; function, set the screen mode.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     RANDOMIZE TIMER                              'SEED THE RND&#40;&#41; FUNCTION
     SCREEN 0                                     '\
     WIDTH 80, 25                                 ' > SET & CLEAR SCREEN
     CLS                                          '/

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Initialize the x- and y-coordinates of the 10 pins and QuitFlag%
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     FOR i% = 1 TO 10                             '---START LOOP FIRST PIN---
          READ Pin&#40;i%&#41;.x                          'READ X-COORD FROM DATA
          READ Pin&#40;i%&#41;.y                          'READ Y-COORD FROM DATA
     NEXT i%                                      '---END LOOP @ TENTH PIN---

     QuitFlag% = 0                                'INITIALIZE QuitFlag% TO 0

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Because different computers will run this game at different speeds, we
     'need to figure out how fast this computer is running it, so that we can
     'make sure pauses within the program always pause for the same length of
     'time.  To do this, we need to see how many loops this computer goes
     'through in one second.  We will save this number as OneSecond& and use
     'it for all calls to the Pause&#40;&#41; sub in the game code.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     PRINT "Determining computer speed...";       'NOTIFY USER OF SPEED TEST
     MarkedTime# = TIMER                          'MARK START TIME
     FOR t& = 1 TO 2000000                        '---LOOP 2 MILLION TIMES---
     NEXT t&                                      '---------END LOOP---------
     OneSecond& = 2000000 / &#40;TIMER - MarkedTime#&#41; 'CALCULATE LOOPS PER SECOND
     PRINT "Done! OneSecond&="; OneSecond&        'NOTIFY USER TEST COMPLETED
END SUB

SUB Instructions
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Explain to the user how to play.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     CLS
     PRINT "BOWLING"
     PRINT "CREATED BY JOHN KREITLOW"
     PRINT "IN ASSOCIATION WITH RADIUM-V"
     LOCATE 5, 18&#58; PRINT "BASED ON ACME SOFTWARE'S `BOWLIN' FOR THE TI-83"
     PRINT
     LOCATE 7, 31&#58; PRINT "PRESS SPACE TO START"
     LOCATE 8, 31&#58; PRINT "PRESS ESCAPE TO QUIT"
     LOCATE 9, 32&#58; PRINT "+---------------+"
     LOCATE 10, 32&#58; PRINT "| LANE    RULES |"
     LOCATE 11, 32&#58; PRINT "+---------------+"
     PRINT
     PRINT "STRIKE = 30 POINTS"
     PRINT "SPARE = 20 POINTS"
     PRINT "HIT `ENTER' AT WANTED SPACE ON THE LANE TO SELECT IT."
     PRINT "SELECT STRENGTH, INDICATED AT BASE OF POWER METER. CHOOSE"
     PRINT "QUICKLY, BECAUSE YOU WILL MISS A TURN IF YOU TAKE TOO LONG!"

     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Show the user the current high score.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     OPEN "BOWLING.HSR" FOR INPUT AS #1                'OPEN HIGHSCORE FILE
          INPUT #1, HighScore.Points%                  'GET SCORE FROM FILE
          LINE INPUT #1, HighScore.Name$               'GET NAME FROM FILE
     CLOSE #1                                          'CLOSE HIGHSCORE FILE
     PRINT "HI-SCORE&#58; ";
     PRINT HighScore.Points%; "BY "; HighScore.Name$   'SHOW THE HIGH SCORE
    
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Wait for a keypress.  Spacebar will start the game.  Escape will quit.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     DO                                                '-----START LOOP------
          k$ = UCASE$&#40;INKEY$&#41;                          'MONITOR KEYPRESSES
     LOOP UNTIL k$ = " " OR k$ = CHR$&#40;27&#41;              '-END AT SPACE OR ESC-
     IF k$ = CHR$&#40;27&#41; THEN QuitFlag% = 1               'IF ESC, SET QuitFlag%
END SUB

SUB Intro
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Draw an intro screen showing a ball rolling a strike.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     CLS                                     'CLEAR THE SCREEN
     LOCATE 2, 37&#58; PRINT "O O O O"           '\
     LOCATE 3, 37&#58; PRINT " O O O"            ' \ DRAW A RACK OF PINS
     LOCATE 4, 37&#58; PRINT "  O O"             ' / AT TOP OF THE SCREEN
     LOCATE 5, 37&#58; PRINT "   O"              '/

     FOR i% = 23 TO 1 STEP -1                '---START LOOP BALL AT BOTTOM---
          LOCATE i%, 37                      'POSITION CURSOR AT BALL'S SPOT
          PRINT "   0   ";                   'DRAW ERASING LINE WITH BALL
          Pause OneSecond& / 20              'SHORT PAUSE
          LOCATE i%, 40                      'POSITION CURSOR AT BALL'S SPOT
          PRINT " ";                         'ERASE THE BALL
     NEXT i%                                 '---END LOOP WHEN BALL AT TOP---
END SUB

SUB Pause &#40;t&&#41;
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Pause for t& loops.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     FOR Counter& = 1 TO t&                            '---START LOOP AT 1---
     NEXT Counter&                                     '---END LOOP AT t&----
END SUB

SUB ResetPins
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Set all 10 pins so that they are standing.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     FOR i% = 1 TO 10                             '---START LOOP 1 THRU 10---
          Pin&#40;i%&#41;.Up = 1                          'SET THIS PIN TO STANDING
     NEXT i%                                      '------END LOOP AT 10------
END SUB

SUB RollBall
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Roll ball down the lane, see what pins are hit, and determine scoring.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
     FOR y% = 190 TO -5 STEP -1              '---START LOOP BALL AT BOTTOM---
          CIRCLE &#40;Ball.x, y%&#41;, 10, Ball.c    'DRAW BALL IN PICKED COLOR
          Pause OneSecond& / 500             'PAUSE A BRIEF MOMENT
          CIRCLE &#40;Ball.x, y%&#41;, 10, 0         'COVER BALL WITH BLACK CIRCLE
     NEXT y%                                 '---END LOOP WHEN BALL AT TOP---

     adjScore% = 0                           'AMOUNT OF POINTS FOR THIS ROLL
     SELECT CASE Ball.x                      '\
          CASE 70&#58; HitPin 1                  ' \
          CASE 90&#58; HitPin 5                  '  `  DEPENDING ON BALL'S LANE
          CASE 110&#58; HitPin 8                 '  |  DETERMINE WHICH PIN WAS
          CASE 130&#58; HitPin 10                '   > STRUCK FIRST. PASS THIS
          CASE 150&#58; HitPin 9                 '  |  PIN # TO THE HitPin SUB
          CASE 170&#58; HitPin 7                 '  '  WHICH WILL SET adjScore%
          CASE 190&#58; HitPin 4                 ' /
     END SELECT                              '/
     Score% = Score% + adjScore%             'ADD ROLL SCORE TO TOTAL SCORE
END SUB

SUB StrikeOrSpare
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'User has bowled a strike or a spare.  Show them a framed message.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     CLS                                          'CLEAR THE SCREEN
     COLOR 7                                      'SET COLOR&#58; GREY
     LOCATE 5, 13&#58; PRINT "+------------+"         'TOP OF FRAME
     LOCATE 6, 13
     IF Roll% = 1 THEN                            'CHECK WHICH ROLL IT IS...
          PRINT "|   STRIKE!  |"                  ' ..FIRST ROLL, SO STRIKE
     ELSE
          PRINT "|   SPARE!   |"                  ' ..SECOND ROLL, SO SPARE
     END IF
     LOCATE 7, 13&#58; PRINT "+------------+"         'BOTTOM OF FRAME
     LOCATE 9, 13&#58; PRINT " PRESS  SPACE"          'SHOW EXIT CONDITION
    
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     'Highlight the frame with moving yellow stars until they hit spacebar.
     '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     FlashHi% = 13                                'TOP STAR
     FlashLo% = 25                                'BOTTOM STAR
     DO                                           '--------START LOOP--------
          FlashHi% = FlashHi% + 1                 'MOVE TOP STAR RIGHT
          FlashLo% = FlashLo% - 1                 'MOVE BOTTOM STAR LEFT
         
          IF FlashHi% = 25 THEN FlashHi% = 14     'RESET TOP STAR
          IF FlashLo% = 13 THEN FlashLo% = 24     'RESET BOTTOM STAR
         
          COLOR 14                                'SET COLOR&#58; YELLOW
          LOCATE 5, FlashHi%&#58; PRINT "-*"          'DRAW TOP STAR
          LOCATE 7, FlashLo%&#58; PRINT "*-"          'DROP BOTTOM STAR
         
          Pause OneSecond& / 75                   'PAUSE BRIEF MOMENT
         
          COLOR 7                                 'SET COLOR&#58; GREY
          LOCATE 5, FlashHi%&#58; PRINT "--"          'REDRAW TOP FRAME
          LOCATE 7, FlashLo%&#58; PRINT "--"          'REDRAW BOTTOM FRAME
     LOOP UNTIL INKEY$ = " "                      '---END LOOP UPON SPACE----
END SUB
User avatar
Dosser
Way too much free time
Way too much free time
Posts: 462
Joined: Sun Jan 02, 2005 2:05 am
Location: BEHIND YOU

Post by Dosser »

I haven't tried to run it yet, but I suspect there will be an error when loading the hiscore file. We do not have a copy of the file, and the game never tries to create one (as far as I can see), so when opening it for input there will be an error.

I recommend you do some error checking: if the file cannot be found, open it for output and put some default values into the file, then open it again.
j2krei08
Newbie
Newbie
Posts: 1
Joined: Tue Mar 29, 2005 3:14 pm
Location: Buffalo, MN

Post by j2krei08 »

Oops, that's right. Just make a file named bowling.hsr and put:

0
Noah Baude

And, you must delete the comments at the DATA for it to work.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
!
Post Reply