!########################################################################
!
! BUMPER.BAS
!
! by
!
! Hal S. Mothershed (PIG/AM)
!
! December 27, 1989
!
!
! (Based on a dimly-remembered game from long ago)
!
!########################################################################
!
! Requires: INKEY.SBR
!
!########################################################################
!
! The object of the game is to guess the locations of 'bumpers'
! on the 10 X 24 position game board. A ball fired from a position
! on the side of the board will re-emerge at a point determined
! by the bounces it makes off of the hidden bumpers. There are
! only two types of bumpers, left (/) and right (\), and they have
! the following effects on the ball:
!
! ^ / ---<---*
! Left: | or |
! *--->--- / v
!
! *--->--- \ ^
! Right: | or |
! v \ ---<---*
!
!
! Positions on the board are represented by a two-letter
! coordinate, in the format Rc, where R is the upper-case letter
! of the Row, and c is the lower-case letter of the column.
!
! The following commands are recognized:
!
! <Cursor key> : Move to new firing position
! <Space> : Fire a ball
! G : Guess a bumper position
! <Escape> : Quit
!
!########################################################################
PROGRAM BUMPER,1.0A(101)
! 1.0A(101) HSM 28-DEC-89
! Highlights undiscovered bumpers at end of game.
!
! 1.0A(100) HSM 27-DEC-89
!
!########################################################################
MAP 1 GRID(10,24),S,1 ! The Game board
MAP 1 BUMPER'COUNT,F,6 ! Bumpers guessed
MAP 1 NUM'BUMPERS,F,6 ! Total # of bumpers on board
MAP 1 GUESSES,F,6 ! Guesses made
MAP 1 BUMPER'MASK,S,20,"]0.................." ! Mask for creation of board
MAP 1 PROB,B,1,20 ! Length of mask, bumper probability
MAP 1 CURPOSX,B,1,1 ! Current firing row
MAP 1 CURPOSY,B,1,0 ! Current firing column
MAP 1 K$,S,1 ! Input from INKEY
MAP 1 G$,S,2 ! Input guessed coordinate
R=INT(RND(0)*PROB)+1 ! Bumper probability is 2/PROB
GRID(X,Y)=BUMPER'MASK[R;1]
IF R=1 OR R=2 NUM'BUMPERS=NUM'BUMPERS+1
NEXT Y
NEXT X
! **** NOTE ****
! I have not implemented an algorithm for determining if there are
! any unreachable bumpers on the board. An unreachable bumper makes
! the game unwinnable. At the current level of complexity (PROB) this
! is rarely a problem.
IF GUESSES>0 &
EFFICIENCY=(BUMPER'COUNT/GUESSES)*100 &
ELSE &
EFFICIENCY=0
PRINT TAB(1,66);
PRINT USING " Finds: ##/##",BUMPER'COUNT,NUM'BUMPERS;
PRINT TAB(2,66);
PRINT USING "Guesses:####",GUESSES
PRINT TAB(3,66);
PRINT USING " Score: ###%",EFFICIENCY
KEYIN: XCALL INKEY,K$
IF LEN(K$)=0 GOTO KEYIN
IF K$=ESCAPE GOTO QUIT'GAME
IF K$=UPARROW GOSUB UP'ARROW
IF K$=DNARROW GOSUB DOWN'ARROW
IF K$=LFARROW GOSUB LEFT'ARROW
IF K$=RTARROW GOSUB RIGHT'ARROW
IF K$=SPC GOSUB FIRE
IF UCS(K$)=GUESS GOSUB MAKE'GUESS
GOTO GET'A'KEY
! NOTE -- All of the cursor key actions could be written more
! elegantly, but for the sake of debugging it was convenient
! to be explicit, and therefore redundant.
IF CURPOSX=0 DX=1 : DY=0
IF CURPOSX=11 DX=-1 : DY=0
IF CURPOSY=0 DX=0 : DY=1
IF CURPOSY=25 DX=0 : DY=-1
PX=CURPOSX : PY=CURPOSY
FIRE'LOOP:
PX=PX+DX : PY=PY+DY
IF PX<1 OR PX>10 OR PY<1 OR PY>24 GOTO FIRE'EXIT
IF GRID(PX,PY)="." GOTO FIRE'LOOP
IF GRID(PX,PY)="0" OR GRID(PX,PY)="/" GOTO FIRE'LOOP'LEFT
IF GRID(PX,PY)="]" OR GRID(PX,PY)="\" GOTO FIRE'LOOP'RIGHT
FIRE'LOOP'LEFT:
IF DX=0 AND DY=1 THEN DX=-1 : DY=0 : GOTO FIRE'LOOP
IF DX=0 AND DY=-1 THEN DX=1 : DY=0 : GOTO FIRE'LOOP
IF DX=1 AND DY=0 THEN DX=0 : DY=-1 : GOTO FIRE'LOOP
IF DX=-1 AND DY=0 THEN DX=0 : DY=1 : GOTO FIRE'LOOP
FIRE'LOOP'RIGHT:
IF DX=0 AND DY=1 THEN DX=1 : DY=0 : GOTO FIRE'LOOP
IF DX=0 AND DY=-1 THEN DX=-1 : DY=0 : GOTO FIRE'LOOP
IF DX=1 AND DY=0 THEN DX=0 : DY=1 : GOTO FIRE'LOOP
IF DX=-1 AND DY=0 THEN DX=0 : DY=-1 : GOTO FIRE'LOOP
FIRE'EXIT:
! Determine position of re-emergence
IF PX=0 &
LPX=3 : LPY=16+(PY-1)*2
IF PX>10 &
LPX=23 : LPY=16+(PY-1)*2
IF PY=0 &
LPX=4+(PX-1)*2 : LPY=14
IF PY>24 &
LPX=4+(PX-1)*2 : LPY=63
! Abort if CR entered
IF G$="" GOTO MAKE'GUESS'OUT
! Ensure proper format (Rc)
IF LEN(G$)<2 GOTO MAKE'GUESS
IF G$[1;1]<"A" OR G$[1;1]>"J" PRINT CHR$(7); : GOTO MAKE'GUESS
IF G$[2;1]<"a" OR G$[2;1]>"x" PRINT CHR$(7); : GOTO MAKE'GUESS