hey i'm still making my minesweeper game, but i've run into a couple of other problems.
1. I don't know how to do that thing where when you click on a blank square, loads of squares sometimes open up (unless I do a stupidly long check for each possible place it could be in relation to it but the grid sizes go up to 20x20 so there must be a more efficient way)
2. I don't know how to make it tell when the game is over... it can now tell when you've clicked on a mine, but not when you've marked all the mines correctly and opened up all the other spaces.
3. I don't know how to do that thing which you can do on the windows version where you press the left and right mouse buttons at once and it checks the area around you.
My complete code so far is here, but you can ignore most of it because the first 2 thirds is just the menu...
sync on
sync rate 0
goto options
exitprog:
cls
for t=1 to 21
delete image t
next t
sync off
end
`options screen
options:
load bitmap "media\button.bmp",1
get image 1,0,0,200,30
delete bitmap 1
load bitmap "media\marker.bmp",1
get image 2,0,0,25,25
mirror bitmap 1
get image 3,0,0,25,25
delete bitmap 1
load bitmap "media\bg1.bmp",1
get image 4,0,0,256,256
delete bitmap 1
load bitmap "media\gobutton.bmp",1
get image 5,0,0,300,50
delete bitmap 1
load bitmap "media\xgr.bmp",1
get image 6,0,0,11,11
delete bitmap 1
load bitmap "media\xrd.bmp",1
get image 7,0,0,11,11
delete bitmap 1
load bitmap "media\xyl.bmp",1
get image 8,0,0,11,11
delete bitmap 1
load bitmap "media\confscreen.bmp",1
get image 9,0,0,395,251
delete bitmap 1
load bitmap "media\tiles.bmp",1
get image 10,0,0,20,20
get image 11,20,0,40,20
get image 12,0,20,20,40
get image 13,20,20,40,40
get image 14,0,40,20,60
get image 15,20,40,40,60
get image 16,0,60,20,80
get image 17,20,60,40,80
get image 18,0,80,20,100
get image 19,20,80,40,100
get image 20,0,100,20,120
get image 21,20,100,40,120
delete bitmap 1
`prepare variables
gridsize#=10
mineno#=10
do
cls
`background
for t=0 to 2
for n=0 to 1
paste image 4,t*256,n*256,1
next n
next t
`titles
set text font "verdana"
set text size 20
center text 320,5,"choose grid size"
center text 320,150,"choose number of mines"
set text size 15
`menus
for t=1 to 3
paste image 1,220,t*35-5,1
paste image 1,220,t*35+140,1
center text 320,t*35+3,str$(t*5+5)+"x"+str$(t*5+5)
next t
`closebutton
if mousex()>620 and mousex()<640 and mousey()>0 and mousey()<20
paste image 6,623,4,1
paste image 8,622,3,1
if mouseclick()=1 then goto exitprog
else
for t=6 to 7
paste image t,629-t,10-t,1
next t
endif
if gridsize#=10
paste image 2,190,32,1
paste image 3,425,32,1
endif
if gridsize#=15
paste image 2,190,67,1
paste image 3,425,67,1
endif
if gridsize#=20
paste image 2,190,102,1
paste image 3,425,102,1
endif
`check
if mousex()>220 and mousex()<420 and mousey()>30 and mousey()<60
tempgridsize#=10
else
if mousex()>220 and mousex()<420 and mousey()>65 and mousey()<95
tempgridsize#=15
else
if mousex()>220 and mousex()<420 and mousey()>100 and mousey()<130
tempgridsize#=20
else
tempgridsize#=0
endif
endif
endif
if tempgridsize#>0 and mouseclick()=1
gridsize#=tempgridsize#
if gridsize#=10 then mineno#=10
if gridsize#=15 then mineno#=25
if gridsize#=20 then mineno#=40
endif
if tempmineno#>0 and mouseclick()=1
mineno#=tempmineno#
endif
rem -------- 10*10 -----------
if gridsize#=10
for t=1 to 3
center text 320,t*35+148,str$(t*15-5)
next t
if mineno#=10
paste image 2,190,177,1
paste image 3,425,177,1
endif
if mineno#=25
paste image 2,190,212,1
paste image 3,425,212,1
endif
if mineno#=40
paste image 2,190,247,1
paste image 3,425,247,1
endif
if mousex()>220 and mousex()<420 and mousey()>175 and mousey()<205
tempmineno#=10
else
if mousex()>220 and mousex()<420 and mousey()>210 and mousey()<240
tempmineno#=25
else
if mousex()>220 and mousex()<420 and mousey()>245 and mousey()<275
tempmineno#=40
else
tempmineno#=0
endif
endif
endif
endif
rem -------- 15*15 -----------
if gridsize#=15
for t=1 to 3
center text 320,t*35+148,str$(t*25)
next t
if mineno#=25
paste image 2,190,177,1
paste image 3,425,177,1
endif
if mineno#=50
paste image 2,190,212,1
paste image 3,425,212,1
endif
if mineno#=75
paste image 2,190,247,1
paste image 3,425,247,1
endif
if mousex()>220 and mousex()<420 and mousey()>175 and mousey()<205
tempmineno#=25
else
if mousex()>220 and mousex()<420 and mousey()>210 and mousey()<240
tempmineno#=50
else
if mousex()>220 and mousex()<420 and mousey()>245 and mousey()<275
tempmineno#=75
else
tempmineno#=0
endif
endif
endif
endif
rem -------- 20*20 -----------
if gridsize#=20
for t=1 to 3
center text 320,t*35+148,str$(t*25+15)
next t
if mineno#=40
paste image 2,190,177,1
paste image 3,425,177,1
endif
if mineno#=65
paste image 2,190,212,1
paste image 3,425,212,1
endif
if mineno#=90
paste image 2,190,247,1
paste image 3,425,247,1
endif
if mousex()>220 and mousex()<420 and mousey()>175 and mousey()<205
tempmineno#=40
else
if mousex()>220 and mousex()<420 and mousey()>210 and mousey()<240
tempmineno#=65
else
if mousex()>220 and mousex()<420 and mousey()>245 and mousey()<275
tempmineno#=90
else
tempmineno#=0
endif
endif
endif
endif
rem ----go button----
paste image 5,170,340,1
set text size 40
center text 320,345,"GO"
if mousex()>170 and mousex()<470 and mousey()>340 and mousey()<390 and mouseclick()=1
goto optionsconfirm
endif
sync
loop
rem -------------------------------------------------------------------------------------------
optionsconfirm:
do
cls
for t=0 to 2
for n=0 to 1
paste image 4,t*256,n*256,1
next n
next t
set text font "verdana"
set text size 20
center text 320,5,"choose grid size"
center text 320,150,"choose number of mines"
set text size 15
for t=1 to 3
paste image 1,220,t*35-5,1
paste image 1,220,t*35+140,1
center text 320,t*35+3,str$(t*5+5)+"x"+str$(t*5+5)
next t
for t=6 to 7
paste image t,629-t,10-t,1
next t
if gridsize#=10
paste image 2,190,32,1
paste image 3,425,32,1
endif
if gridsize#=15
paste image 2,190,67,1
paste image 3,425,67,1
endif
if gridsize#=20
paste image 2,190,102,1
paste image 3,425,102,1
endif
if gridsize#=10
for t=1 to 3
center text 320,t*35+148,str$(t*15-5)
next t
if mineno#=10
paste image 2,190,177,1
paste image 3,425,177,1
endif
if mineno#=25
paste image 2,190,212,1
paste image 3,425,212,1
endif
if mineno#=40
paste image 2,190,247,1
paste image 3,425,247,1
endif
endif
if gridsize#=15
for t=1 to 3
center text 320,t*35+148,str$(t*25)
next t
if mineno#=25
paste image 2,190,177,1
paste image 3,425,177,1
endif
if mineno#=50
paste image 2,190,212,1
paste image 3,425,212,1
endif
if mineno#=75
paste image 2,190,247,1
paste image 3,425,247,1
endif
endif
if gridsize#=20
for t=1 to 3
center text 320,t*35+148,str$(t*25+15)
next t
if mineno#=40
paste image 2,190,177,1
paste image 3,425,177,1
endif
if mineno#=65
paste image 2,190,212,1
paste image 3,425,212,1
endif
if mineno#=90
paste image 2,190,247,1
paste image 3,425,247,1
endif
endif
paste image 5,170,340,1
set text size 40
center text 320,345,"GO"
paste image 9,122,95,1
set text size 40
center text 320,90,"are you sure?"
set text size 60
center text 320,140,"yes"
center text 320,210,"no"
set text size 18
center text 320,300,"current settings: "+str$(mineno#)+" mines in a "+str$(gridsize#)+" by "+str$(gridsize#)+" grid"
if mousex()>270 and mousex()<370 and mousey()>160 and mousey()<205 and mouseclick()=1
goto mainloop
endif
if mousex()>285 and mousex()<355 and mousey()>230 and mousey()<265 and mouseclick()=1
cls
goto options
endif
sync
loop
mainloop:
rem =========================================================================
rem =========================================================================
rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MAIN GAME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rem =========================================================================
rem =========================================================================
rem set up array
dim gclicked(gridsize#,gridsize#)
dim glocations(gridsize#,gridsize#)
dim gneed(gridsize#,gridsize#)
dim openme(gridsize#,gridsize#)
remstart
for t=1 to gridsize#
for n=1 to gridsize#
gclicked(t,n)=1
next n
next t
remend
for t=1 to mineno#
do
x=rnd(gridsize#-1)
x=x+1
y=rnd(gridsize#-1)
y=y+1
if glocations(x,y)=0
glocations(x,y)=9
gneed(x,y)=0
exit
endif
loop
next t
for t=1 to gridsize#
for n=1 to gridsize#
if t>1
if glocations(t-1,n)>8 then glocations(t,n)=glocations(t,n)+1
endif
if n>1
if glocations(t,n-1)>8 then glocations(t,n)=glocations(t,n)+1
endif
if t<gridsize#
if glocations(t+1,n)>8 then glocations(t,n)=glocations(t,n)+1
endif
if n<gridsize#
if glocations(t,n+1)>8 then glocations(t,n)=glocations(t,n)+1
endif
if t>1 and n>1
if glocations(t-1,n-1)>8 then glocations(t,n)=glocations(t,n)+1
endif
if t<gridsize# and n>1
if glocations(t+1,n-1)>8 then glocations(t,n)=glocations(t,n)+1
endif
if t>1 and n<gridsize#
if glocations(t-1,n+1)>8 then glocations(t,n)=glocations(t,n)+1
endif
if t<gridsize# and n<gridsize#
if glocations(t+1,n+1)>8 then glocations(t,n)=glocations(t,n)+1
endif
next n
next t
for t=1 to gridsize#
for n=1 to gridsize#
if glocations(t,n)>9
glocations(t,n)=9
endif
next n
next t
do
if updated#=0
cls
for t=0 to 2
for n=0 to 1
paste image 4,t*256,n*256,1
next n
next t
for t=19 to 23
draw#=gridsize#*20+t
draw2#=38-t
draw3#=t*10
draw4#=250-draw3#
ink rgb(draw4#,draw4#,draw4#),0
line draw2#,draw2#,draw#,draw2#
line draw2#,draw2#,draw2#,draw#
line draw#,draw2#,draw#,draw#
line draw2#,draw#,draw#,draw#
ink rgb(255,255,255),0
next t
for t=1 to gridsize#
for n=1 to gridsize#
if gclicked(t,n)=0
paste image 10,t*20,n*20,1
endif
if gclicked(t,n)=2
paste image 21,t*20,n*20,1
endif
if gclicked(t,n)=1
if glocations(t,n)=0 then paste image 11,t*20,n*20,1
if glocations(t,n)=9
paste image 12,t*20,n*20,1
die#=1
endif
for q=1 to 8
if glocations(t,n)=q then paste image q+12,t*20,n*20,1
next q
endif
next n
next t
updated#=1
endif
if mousex()>620 and mousex()<640 and mousey()>0 and mousey()<20
paste image 6,623,4,1
paste image 8,622,3,1
if mouseclick()=1 then goto exitprog
else
for t=6 to 7
paste image t,629-t,10-t,1
next t
endif
for t=1 to gridsize#
for n=1 to gridsize#
if mousex()>t*20 and mousey()>n*20 and mousex()<t*20+20 and mousey()<n*20+20
if mouseclick()=1
if gclicked(t,n)=0
gclicked(t,n)=1
if glocations(t,n)=0
if t>1
if gclicked(t-1,n)=0 then gclicked(t-1,n)=1
endif
if t<gridsize#
if gclicked(t+1,n)=0 then gclicked(t+1,n)=1
endif
if t>1 and n>1
if gclicked(t-1,n-1)=0 then gclicked(t-1,n-1)=1
endif
if t<gridsize# and n>1
if gclicked(t+1,n-1)=0 then gclicked(t+1,n-1)=1
endif
if t>1 and n<gridsize#
if gclicked(t-1,n+1)=0 then gclicked(t-1,n+1)=1
endif
if t<gridsize# and n<gridsize#
if gclicked(t+1,n+1)=0 then gclicked(t+1,n+1)=1
endif
if n>1
if gclicked(t,n-1)=0 then gclicked(t,n-1)=1
endif
if n<gridsize#
if gclicked(t,n+1)=0 then gclicked(t,n+1)=1
endif
endif
updated#=0
endif
endif
if mouseclick()=2
if gclicked(t,n)=0
gclicked(t,n)=2
wait 500
else
if gclicked(t,n)=2
gclicked(t,n)=0
wait 500
endif
endif
updated#=0
endif
endif
next n
next t
if die#=1 then goto diecode
sync
loop
diecode:
wait 500
cls
wait 500
center text 320,25,"GAME OVER"
center text 320,65,"press any key to return to the menu"
suspend for key
die#=0
updated#=0
rem remove array
undim gclicked(gridsize#,gridsize#)
undim glocations(gridsize#,gridsize#)
undim gneed(gridsize#,gridsize#)
undim openme(gridsize#,gridsize#)
goto options
you can also have a look at the screenshot, download the .exe as it is or download a zip with the code and all the media here if that would help:
http://jamesmason01.googlepages.com/index.htm
any other comments, suggestions or tips would also be greatly appreciated.
by the way, I'm only using DBC.
http://jamesmason01.googlepages.com/index.htm