Mastermind
From CPCWiki - THE Amstrad CPC encyclopedia!
Mastermind is a short type-in from Happy Computer magazine (December 1986, pp. 80/81). Gameplay is the same as the Mastermind board game.
Download
Source code
10 '**** MASTER-MIND **** 11 ' from Your Computer, December 1986, Vol 6, n° 12. 12 ' scans: ftp://ftp.worldofspectrum.org/pub/sinclair/magazines/YourComputer/Issue8612/Pages/YourComputer861200080.jpg 20 mode 1 30 ink 0,15:ink 1,1 40 dim g(4),ans(4) 50 cls 60 for i=1 to 4 70 ans(i)=int(rnd*6) 80 next i 90 locate 14,2:print" MASTER-MIND" 100 print:print" You have to guess a four digit" 110 print" number. Each digit must be between" 120 print" 0 and 5 e.g. 2501 or 4431." 130 print" You will be allowed a maximum " 140 print" of 12 guesses!" 150 print 160 for g=1 to 12 170 bl=0:wh=0 180 locate 2,g+8 190 print " Enter guess ";g;" ";:locate 20,g+8:input "- ", guess$ 200 if len(guess$)<> 4 then print" Invalid entry - try again ":goto 180 210 for j=1 to 4:g(j)=asc(mid$(guess$,j,1))-48 220 if g(j)<0 or g(j)>5 then print " Invalid - try again ":goto 180 230 next j 240 locate 26,g+8:print using "&"; space$(200) 250 for k=1 to 4:if g(k)=ans(k) then bl=bl+1 260 if bl=4 then locate 2,22:print" Well done - you guessed correctly. ":goto 440 270 next k 280 for w=1 to 4 290 for x=1 to 4 300 if ans(w)=g(x) then wh=wh+1:g(x)=6:goto 320 310 next x 320 next w 330 wh=wh-bl 340 locate 27,g+8 350 pen 2:ink 2,0 360 if bl<1 then 380 370 for c=1 to bl:print using "&"; chr$(143);" ";:next c 380 if wh<1 then 400 390 pen 3:ink 3,26:for c2=1 to wh:print chr$(143);" ";:next c2 400 pen 1 410 next g 420 print:print:print" Bad luck! The answer is ";ans(1);ans(2);ans(3);ans(4); 430 ' 440 print:print" Do you want to play again (y/n) "; 450 a$=inkey$:on instr(" yn",lower$(a$)) goto 450,50,470 460 goto 450 470 stop
Links
- Mastermind at the English-language Wikipedia
- Mastermind at CPC-Power