20

Simon


A simple game, this; a computer implementation of the well-known game. The computer flashes a sequence of coloured squares, each accompanied by its own note, and the user attempts to duplicate it. As he does so, the same coloured squares flash and the same notes are emitted. The program starts by asking for a difficulty level, which determines the length of time each square is displayed, the begins the sequence with only one item. If successful, the sequence is lengthened by one each time and this continues until the player makes an error.
   The listing is quite interesting. The VDU19 commands turn all colours to black and then the four calls to PROCSQ draw (invisibly) the four squares, each in a different computer colour. Similarly, for speed the message 'READY!' and the prompt '. . . . . . ?' are preprinted on the screen invisibly. Adopting this method, all that we need do is change appropriate computer colours (confusing that; all colours are black at this point!) to their real or screen colours for them to appear immediately. In line 220, for example, changing logical colour 15 makes the message 'READY!' appear. Line 230 times it for three seconds, and then line 240 switches it off again. Simple!
   The variable called GO% specifies the overall length of the series so far correctly remembered and stored in A%(X), and the variable SEG% is the current one. The appropriate colour is switched in line 290, with accompanying sound in line 300. This makes the square appear, before it is switched off again in line 320 after a period of time determined by D%. Line 340 switches another colour, causing the prompt '. . . . . . .?' to appear, which is the signal for the player to repeat the sequence he or she has just seen.
   Player input is at line 360. He is required to press R, G, B or Y (for red, green, blue and yellow), as appropriate. No RETURN is necessary. If correct, line 430 switches the proper colour and sounds the note. The colour is switched back again by line 450.

Variables

A%(30)Array to hold each item of the series, up to 30
D%Difficulty level
GO%Length of series so far
G$Dummy
SEG%Current item of series
C%Colour to be switched
Q%Count of user's inputs
Q$User's input; R, G, B or Y
NOWTimer for display

    5 REM - Simon
   10 MODE7:DIM A%(30)
   20 PROCDBL(12,5,"SIMON")
   30 PRINTTAB(13,7);CHR$130;"_____"''
   40 PRINT''"How difficult?"''
   50 PRINT"Type a number from 1 (hard) to 9 (easy)"''
   60 REPEAT:D%=INKEY(0):UNTIL D%>48 AND D%<58:D%=D%-48
   70 MODE2
   80  
   90 REM - Print squares in black
  100  
  110 VDU19,1,0,0,0,0,19,2,0,0,0,0,19,3,0,0,0,0
  120 VDU19,4,0,0,0,0,19,5,0,0,0,0,19,15,0,0,0,0,5
  130 PROCSQ(100,100,1):PROCSQ(600,100,2)
  140 PROCSQ(100,550,3):PROCSQ(600,550,4)
  150 MOVE 40,50:GCOL0,15:PRINT"READY!"
  160 MOVE 500,50:GCOL0,5:PRINT "......?"
  170  
  180 REM - GAME LOOP *************
  190  
  200 GO%=0
  210 REPEAT:GO%=GO%+1
  220 VDU19,15,15,0,0,0
  230 G$=INKEY$(300)
  240 VDU19,15,0,0,0,0
  250 A%(GO%)=RND(4)
  260 IF A%(GO%)=A%(GO%-1) GOTO250
  270 FOR SEG%=1 TO GO%
  280 C%=A%(SEG%)
  290 VDU19,C%,C%,0,0,0
  300 SOUND1,-10,C%*50,3
  310 TIME=0:REPEAT UNTIL TIME>=D%*20
  320 VDU19,C%,0,0,0,0
  330 NEXT SEG%
  340 VDU19,5,5,0,0,0:*FX15,0
  350 FOR Q%=1 TO GO%
  360 REPEAT:Q$=GET$
  370 UNTIL Q$="R" OR Q$="Y" OR Q$="B" OR Q$="G"
  380 IF Q$="R" AND A%(Q%)=1 GOTO430
  390 IF Q$="G" AND A%(Q%)=2 GOTO430
  400 IF Q$="Y" AND A%(Q%)=3 GOTO430
  410 IF Q$="B" AND A%(Q%)=4 GOTO430
  420 GOTO480
  430 VDU19,A%(Q%),A%(Q%),0,0,0:SOUND1,-10,A%(Q%)*50,3
  440 NOW=TIME
  450 REPEAT UNTIL TIME>=NOW+25:VDU19,A%(Q%),0,0,0,0:NEXT
  460 VDU19,5,0,0,0,0:REM - VANISH PROMPT
  470 UNTIL 0
  480 MODE7:VDU4:COLOUR 6
  490 PRINTTAB(0,5);"YOU SCORED ";GO%-1
  500 PRINT''"TYPE RUN TO PLAY AGAIN."
  510 END
  520  
  530 DEFPROCDBL(X%,Y%,X$)
  540 PRINTTAB(X%,Y%);:VDU 130,141:PRINT X$
  550 PRINTTAB(X%,Y%+1);:VDU 130,141:PRINT X$
  560 ENDPROC
  570  
  580 DEFPROCSQ(X%,Y%,C%)
  590 GCOL0,C%
  600 MOVEX%,Y%:MOVEX%+500,Y%
  610 PLOT81,-500,450
  620 PLOT81,500,0
  630 ENDPROC