5

Time bomb


The story behind the game is well explained in lines 580 to 720 of the listing, so we may proceed to a discussion of the program. There are seven digits to be found and these are placed in the array N%(X). The box of explosives is drawn using Mode 7 graphics, which explains that weird and wonderful PRINT statement of line 122. CHR$149 is the command to print graphics magenta, so the strange mixture of characters is translated into block graphics, representing the sticks of dynamite poking up out of the box. Similarly, on line 90, X$ and E$ are constructed of commands to start and stop background printing in red, thus allowing us to draw the box and its windows with ease. See the introduction for an easier way of doing this.
   The user's input is accepted on line 250, without use of the RETURN key, which speeds things up. The input is compared with the current screen digit in lines 260 to 290, with the appropriate high or low tones being sounded. In practice the player will not want to keep looking at the timer counting down, because this will slow him. Instead, he will find that listening to the tones is quite sufficient. When a digit has been found it is displayed in the bomb window and the program moves automatically and swiftly to the next digit. Although very little time is allowed for winning, and although the user may not win for some time, nevertheless it can be beaten by anyone with a little nerve and concentration. Considering the times that we live in, I have thought it advisable to keep the tone of the game light and humorous.
   PROCUPDATE is responsible for the timer countdown, while PROCCRASH gives the explosive sound and PROCWARBLE a happy warbling sound when the bomb has successfully been defused.

Variables

Q$User input string
N%(0) to N%(6)The seven secret digits
X%General counter
Z%Starting allowance in seconds
X$Graphics line start
E$Graphics line end
G%Player's input digit
T%Time left in seconds
C%Colour of double-height print

   10 REM - Time bomb
   20 CLS:PROCDBL(5,5,129,"TIME-BOMB")
   30 INPUT''"Do you want instructions",Q$
   40 IF Q$="Y" PROCINSTR
   50 DIM N%(6),S%(6):VDU23;8202;0;0;0;
   60  
   70 REM - Set-up
   80 FOR X%=0 TO 6:N%(X%)=RND(10)-1:S%(X%)=0:NEXT
   90 Z%=RND(10)+10:X$=CHR$129+CHR$157+CHR$135:E$=CHR$156
  100  
  110 REM - Draw box of explosives
  120 CLS:PRINTTAB(5,3);:RESTORE:FOR X%=1 TO 23:READ Y%
  122 PRINTCHR$(Y%);:NEXT
  125 DATA149,248,248,53,232,244,245,126,52,124,126,234
  126 DATA32,244,224,52,53,248,232,53,244,234,52
  130 PRINTTAB(3,4);X$;TAB(50);E$
  140 PRINTTAB(3,5);X$;"  E X P L O S I V E S   ";E$
  150 PRINTTAB(0,6);X$;TAB(33);E$
  160 PRINTTAB(3,7);X$;TAB(27);E$
  180 PROCUPDATE
  190 PRINTTAB(3)X$;"   ";E$;STRING$(15," ");X$;"  ";E$
  200 PRINTTAB(3);X$;TAB(30);E$
  210 TIME=0:X%=0
  220  
  230 REM - Game loop
  240  
  250 REPEAT:G%=INKEY(0)-48
  260 IF G%<0GOTO300
  270 IF G%=N%(X%) VDU7:S%(X%)=G%:X%=X%+1:IF X%=7 GOTO400
  280 IF G%<N%(X%) SOUND1,-15,50,1
  290 IF G%>N%(X%) SOUND 1,-15,500,1
  300 T%=Z%-TIME/100:PROCUPDATE
  310 UNTIL TIME>=Z%*100
  320  
  330 REM - Big bang
  340 CLS:PROCCRASH:*FX15,1
  350 PROCDBL(5,3,129,"OH DEAR!")
  360 PRINT''"That's another fine pair of eyebrows"
  370 PRINT"you've lost, Stanley!":GOTO430
  380  
  390 REM - Win
  400 PROCDBL(2,16,130,"C O N G R A T U L A T I O N S !")
  410 PROCWARBLE:PRINT'"YOU DID IT AND SAVED THE OLD SCHOOL!"
  420 PRINT"The Head kisses you on both cheeks!"
  430 *FX15,0
  435 INPUT"PLAY AGAIN (Y-N)",Q$:IF Q$="Y" GOTO80 ELSE END
  440  
  450 DEFPROCDBL(X%,Y%,C%,X$)
  460 PRINTTAB(X%,Y%)CHR$141;CHR$C%;X$
  470 PRINTTAB(X%,Y%+1)CHR$141;CHR$C%;X$:ENDPROC
  480  
  490 DEFPROCUPDATE
  500 PRINTTAB(3,8)X$;"    TIME:";T%;X$;;TAB(27);E$
  510 PRINTTAB(3)X$;TAB(30);E$
  520 PRINTTAB(3)X$;"   ";E$;STRING$(15," ");X$;"  ";E$
  530 PRINTTAB(3);X$;"   ";E$;" ";
  540 FOR Q%=0TO6:PRINT;S%(Q%);" ";:NEXT:PRINT;X$;"  ";E$
  550 ENDPROC
  560  
  570 DEFPROCINSTR
  580 CLS:PRINT''"The dastardly Sir Simon Ffoul-Enuff has"
  590 PRINT"planted a bomb in the refreshment tent"
  600 PRINT"at your school fete!  It is bolted to"
  610 PRINT"the tea urn and so cannot be moved. The"
  620 PRINT"only way for you to save civilisation"
  630 PRINT"as we know it, is to render"
  640 PRINT"the bomb harmless."'
  650 PRINT"There are seven numbers to find. If"
  660 PRINT"your guess is low, the mechanism gives"
  670 PRINT"a low note, while if it is high, then"
  680 PRINT"a high note is emitted."
  690 PRINT'"A beep tells you that you have found"
  700 PRINT"that number & can move on to the next."
  710 PRINT'"You have only a few seconds."''
  720 PRINT"Good luck!":INPUT'" Press RETURN...";Q$
  730 ENDPROC
  740  
  750 DEFPROCWARBLE
  760 FORS%=1TO20:SOUND1,-12,30,1
  770 SOUND1,-12,100,1:NEXT:ENDPROC
  780  
  790 DEFPROCCRASH
  800 FOR Q%=-160TO0:SOUND0,Q%/10,6,1:NEXT:ENDPROC