10 mode 1:randomize time 20 defint a-z 30 boardx=6:boardy=4 40 dim a(boardx,boardy) 50 dim c(boardx+2,boardy+2) 60 dim c2(boardx+2,boardy+2) 70 nmines=int((rnd/3+.1)*boardx*boardy) 80 for i=1 to nmines 90 ' place random mines 100 xp=int(rnd*(boardx-1)+1) 110 yp=int(rnd*(boardy-1)+1) 120 if a(xp,yp) then 100 130 a(xp,yp)=64 140 for xx=xp to xp+2 150 for yy=yp to yp+2 160 c(xx,yy)=c(xx,yy)+1 170 next yy 180 next xx 190 next i 200 gosub 350 210 x=1:y=1 220 gosub 600 230 ' wait for key press 240 k$=lower$(inkey$) 250 if k$="" then 240 260 if k$="q" and y>1 then gosub 660:y=y-1:gosub 600 270 if k$="a" and y1 then gosub 660:x=x-1:gosub 600 290 if k$="p" and x1000 then a(x2,y2)=vv xor 1024 890 next y2 900 next x2 910 locate 1,25:print " "; 920 return 930 ' find neighbors 940 c2(x2+1,y2+1)=(c2(x2+1,y2+1) xor 512) or 256 or 1024 950 for ii=0 to 2 960 for jj=0 to 2 970 if ii=0 and jj=0 then 1030 980 if c2(x2+ii,y2+jj) and 64 then 1030 990 if c2(x2+ii,y2+jj) and 128 then 1030 1000 if c2(x2+ii,y2+jj) and 1024 then 1030 1010 c2(x2+ii,y2+jj)=c2(x2+ii,y2+jj) or 512 1020 ' next tile 1030 next jj 1040 next ii 1050 return 1060 ' update discovered mine count 1070 mm=0 1080 for x2=1 to boardx 1090 for y2=1 to boardy 1100 if (a(x2,y2) and 128)>0 and (a(x2,y2) and 64)>0 then mm=mm+1 1110 next 1120 next 1130 if mm=nmines then locate 5,22:print "Congratulations, you've won!":end 1140 return