'y'
REM **** MASTERMIND to PLAY ***** by smbstarv
     IF DEVICE_TYPE$()<>"iPad" THEN
         PRINT "for iPad only"
         STOP
     END IF
     SET ORIENTATION 2
     makkelijk=1                                 'alleen verschillende kleuren
     maxattempts=12
     SET TOOLBAR OFF
 init:
     OPTION BASE 0
     GRAPHICS CLEAR
     GOSUB beeld
     SPRITE "ptr" BEGIN 30,30
     FILL COLOR 0,0,0
     FILL CIRCLE 10,10 SIZE 8
     SPRITE END
     SPRITE "ptr" HIDE
     BUTTON "exit" TEXT "EXIT" AT 10,10
     DRAW COLOR 1,0,1
     SPRITE "hintptr" BEGIN 50,50
     FILL COLOR 1,0,1
     FILL CIRCLE 25,25 SIZE 12
     SPRITE END
     SPRITE "hintptr" HIDE
     SPRITE "ptr" SHOW
     DIM codes(15,5)                             'codes(0,i) bevat de geheime code
 geheimecode:
     RANDOMIZE
     codes(0,1)=RND(6)+1
 r2:codes(0,2)=RND(6)+1
     IF makkelijk AND codes(0,2)=codes(0,1) THEN GOTO r2
 r3:codes(0,3)=RND(6)+1
     IF makkelijk AND codes(0,3)=codes(0,2) OR codes(0,3)=codes(0,1) THEN GOTO r3
 r4:codes(0,4)=RND(6)+1
     IF makkelijk AND codes(0,4)=codes(0,3) OR codes(0,4)=codes(0,2) OR codes(0,4)=codes(0,1) THEN GOTO r4
'b'
 rst:poging=1
     hintcnt=0
     selklr=0
     SPRITE "ptr" HIDE
     FOR i=1 TO 14
         FOR j=1 TO 4
             codes(i,j)=0
         NEXT j
     NEXT i
     
 gettouch:
     IF BUTTON_PRESSED("exit") THEN GOTO afsluiten
     FOR i=0 TO 9
         GET TOUCH i AS tx,ty
         IF tx>0 THEN GOTO gt2
     NEXT i
     GOTO gettouch
 gt2:
     WHILE TOUCH_X (i)<>-1
         SLOWDOWN
     END WHILE                                   'wacht op einde toets
     
 besturing:
     IF isplek(670,150) THEN                     'bepaal score
         score(poging)
         IF score.zwart=4 THEN
             DRAW FONT SIZE 30
             DRAW COLOR 0,0,0
             DRAW TEXT "code broken !" AT 50,200
             DRAW TEXT "with "&STR$(poging,"#")&" attempts" AT 50,230
             DRAW TEXT "and "&STR$(hintcnt,"#")&" hints" AT 50,260
         END IF
         IF poging>maxattempts AND score.zwart<4 THEN
             DRAW FONT SIZE 30
             DRAW COLOR 0,0,0
             DRAW TEXT "code unbroken !" AT 50,200
             DRAW TEXT "after "&STR$(poging-1,"#")&" attempts" AT 50,230
             DRAW TEXT "and "&STR$(hintcnt,"#")&" hints" AT 50,260
             GOSUB showcode
             NOTES SET "1: v40 tc7b6agfedcb5agfedcb4agfedcb3ag"
             NOTES PLAY
             PAUSE 6
             NOTES MIDI 0,12,31
             NOTES MIDI 0,9,88,99
             NOTES MIDI 9,8,88,0
             PAUSE 1
             GOTO rst
         END IF
     END IF
     IF isplek(670,300) THEN                     'geef een hint
         GOSUB HINT
     END IF
     IF isplek(670,500) THEN                     'reset met behoud van code
         GRAPHICS CLEAR
         GOSUB beeld
         GOTO rst
     END IF
     IF isplek(670,780) THEN                     'nieuw spel
         GOTO init
     END IF
     IF isplek(670,940) THEN                     'moeilijkheidsgraad
         makkelijk=ABS(makkelijk-1)
         GOTO init
     END IF
     
 kleur:
     DATA .7,.4,0,1,0,0,0,1,0,0,0,1,1,1,0,1,1,1
     RESTORE TO kleur
     FOR k=1 TO 6
         READ r,g,b
         IF isplek(k*100,850) THEN
             selklr=k
             FILL COLOR r,g,b
             sr=r
             sg=g
             sb=b
             SPRITE "ptr" AT 780,k*100-10
             SPRITE "ptr" SHOW
             BREAK k
         END IF
     NEXT k
     IF selklr=0 THEN GOTO gettouch
     
 plaats:
     FOR plek=1 TO 4
         IF isplek(640-poging*40,200+plek*90) THEN
             FILL COLOR sr,sg,sb
             FILL CIRCLE cx, cy SIZE 16
             codes(poging,plek)=selklr
         END IF
     NEXT plek
     GOTO gettouch
'c'
     DEF isplek(y,x)
         IF (.tx-x)^2+(.ty-y)^2<1200 THEN
             cc=1
             .cx=x
             .cy=y
             NOTES MIDI 0,12,12
             NOTES SET "v40sc7"
             NOTES PLAY
         ELSE
             cc=0
         END IF
         isplek=cc
     END DEF
     
     DEF score(n)
         IF n<1 THEN RETURN
         IF .codes(n,1)*.codes(n,2)*.codes(n,3)*.codes(n,4)=0 THEN RETURN
         zwart=0
         wit=0
         FOR j=1 TO 4
             code=.codes(0,j)
             zw=0
             wt=0
             FOR i=1 TO 4
                 IF .codes(n,i)=code THEN
                     wt=1
                     IF i=j THEN zw=1
                 END IF
             NEXT i
             IF zw=1 THEN zwart+=1
             IF zw=0 AND wt=1 THEN wit+=1
         NEXT j
         
         drawscore(n,zwart,wit)
         IF zwart<4 THEN .poging=n+1
     END DEF
     
     DEF drawscore (n,z,w)                       ' n-de poging, z juiste kleur en plek, w alleen juiste kleur
         FOR i=1 TO z
             FILL COLOR 0,0,0
             FILL CIRCLE (60 + i*25), 640-n*40 SIZE 10
         NEXT i
         FOR i=1 TO w
             FILL COLOR 1,1,1
             FILL CIRCLE (60 + (z+i)*25), 640-n*40 SIZE 10
         NEXT i
         IF z+w=0 THEN
             DRAW FONT SIZE 30
             DRAW TEXT "none" AT 90,620-n*40
         END IF
         IF z=4 THEN
             NOTES MIDI 0,12,12
             NOTES SET "v70sc5egc6"
             NOTES PLAY
             PAUSE 1
         END IF
     END DEF
'r'
 beeld:
     GRAPHICS
     DRAW ALPHA 1
     FILL ALPHA 1
     FILL COLOR 0.3,1,1
     FILL RECT 1,1 TO 1024,800
     DRAW COLOR 0,0,0
     DRAW FONT NAME "Zapfino"
     DRAW FONT SIZE 50
     DRAW TEXT "MASTERMIND" AT 130,0
     FOR i=1 TO 12
         FOR j=1 TO 4
             DRAW CIRCLE 200+j*90, 160+(12-i)*40 SIZE 8
         NEXT j
     NEXT i
     
     RESTORE TO kleur
     FOR k=1 TO 6
         READ r,g,b
         FILL COLOR r,g,b
         FILL CIRCLE 850,k*100 SIZE 30
     NEXT k
     FILL COLOR 1,1,1
     FILL CIRCLE 150,670 SIZE 20,20
     DRAW FONT NAME "TimesNewRomanPSMT"
     DRAW FONT SIZE 20
     DRAW TEXT "SCORE ?" AT 110,660
     FILL CIRCLE 500,670 SIZE 20,20
     DRAW TEXT "RESET THIS GAME ?" AT 420,660
     FILL CIRCLE 780,670 SIZE 20,20
     DRAW TEXT "NEW GAME ?" AT 720, 660
     FILL CIRCLE 940,670 SIZE 20,20
     DRAW TEXT "I < - > II" AT 910,660
     IF makkelijk THEN
         DRAW TEXT "I = no duplicate colors in the secret code" AT 300,110
     ELSE
         DRAW TEXT "II = there may be duplicate colors in the secret code" AT 300,110
     END IF
     FILL CIRCLE 300,670 SIZE 20,20
     DRAW COLOR 1,0,1
     DRAW TEXT "HINT..." AT 270,660
     DRAW COLOR 0,0,0
     RETURN
     
 hint:
     RANDOMIZE
     hintcnt+=1
     k=RND(4)+1
     kl=codes(0,k)
 hintloop:
     t0=TIME()+.7
     SPRITE "hintptr" AT 890,kl*100-30
     SPRITE "hintptr" SHOW
     WHILE  t0>TIME()
         IF TOUCH_X(0)<>-1 THEN GOTO exithint
     END WHILE
     t0=TIME()+.7
     SPRITE "hintptr" AT 175+k*90, 115+(12-poging)*40
     WHILE t0>TIME()
         IF TOUCH_X(0)<>-1 THEN GOTO exithint
     END WHILE
     GOTO hintloop
 exithint:
     SPRITE "hintptr" HIDE
     RETURN
     
 showcode:
     FOR i=1 TO 4
         code=codes(0,i)
         RESTORE TO kleur
         FOR s=1 TO code
             READ r,g,b
         NEXT s
         FILL COLOR r,g,b
         FILL CIRCLE 20+50*i,120 SIZE 15
     NEXT i
     RETURN
     
 afsluiten:
     BUTTON "exit" DELETE
     SPRITES DELETE
     GRAPHICS CLEAR 0,0,0
     DRAW COLOR 1,1,1
     DRAW FONT NAME "Zapfino"
     DRAW FONT SIZE 70
     DRAW TEXT "STOPPED" AT 230,260
     NOTES SET "1: v40 tc7b6agfedcb5agfedcb4agfedcb3ag"
     NOTES PLAY
     PAUSE 3
     NOTES MIDI 0,12,31
     NOTES MIDI 0,9,88,99
     NOTES MIDI 9,8,88,0
     PAUSE 1
     TEXT
     END
			
			
									
									
						