2
Quickdraw and
100 metres sprint
'Quickdraw' takes the idea of the timed response one stage further. We suppose a Western situation, with the user required to type the word BANG as quickly as possible. The computer will keep track of the best time.
In line 10 we set the best time impossibly high, because otherwise otherwise no-one would ever better it. We ask for the user's name and then in line 40 have him or her wait for an indeterminate time before challenging him to draw and fire on line 50. You should be able to follow the listing quite easily, except perhaps for line 60, where *FX15,0 is a command to flush the internal buffers. This prevents the user cheating by having the word BANG already typed in before the 'Draw!' prompt appears. This would be possible because anything typed is stored in a buffer and not until RETURN is pressed does the BBC computer start to operate on it. Flushing the buffers means that the user is allowed to start typing only after the prompt appears.
Variables
BEST | The best (i.e. shortest) time so far recorded |
NAME$ | Name of current user |
X | General counter |
TIME | The internal elapsed-time counter |
X$ | Required input from the user |
T | Time in seconds taken by the current user |
BEST$ | Name of the player with BEST time |
100 metres sprint
Quickdraw will sustain user interest for only a little while, but at least one best-selling program extended the idea to a Computer Decathlon, with ten different keyboard responses for the ten different events. If you like button-bashing programs, there's an idea for you! Merely in the spirit of showing you how one would go about it, here is a listing that would simulate the 100 metres sprint. You are required to type L and R alternately 100 times.
The listing is very similar to the last. The only additional information you need in order to understand it is that the GET$ command does not require the RETURN key to be pressed, so playing is quite literally L and R alternately.
10 BEST=999
20 INPUT "Please type your name",NAME$
30 PRINTTAB(3,12);"Ready"
40 FOR X=1 TO RND(1000):
50 PRINTTAB(RND(30),RND(15));"Draw!"
60 TIME=0:*FX15,0
70 REPEAT
80 INPUT X$
90 UNTIL X$="BANG"
95 T=TIME/100
100 PRINT;"You drew and fired in ";T;" seconds"
110 IF T>=BEST GOTO 145
115 PRINT "The best so far!"
120 BEST=T
130 BEST$=NAME$
135 PROCRET:CLS
140 GOTO 20
145 PRINT "You're dead!"'
150 PRINT "The best shot so far is ";BEST$;","
160 PRINT "who took only ";BEST;" seconds"'
165 PROCRET:CLS
170 GOTO 20
10 BEST=999
40 PRINT "On your marks"
50 FOR X=1 TO RND(5000):NEXT
70 PRINT "GO!":*FX15,0
80 TIME=0
90 FOR X=1 TO 100
100 REPEAT
110 G$=GET$
120 UNTIL G$="L"
130 REPEAT
140 G$=GET$
150 UNTIL G$="R"
160 NEXT X
170 PRINT"Your time was ";TIME/100;" seconds"