Here is the code with some stuff commented out
rem
rem AGK Application
rem
rem A Wizard Did It!
SetVirtualResolution ( 512, 512 )
Type Square
bombCount as integer
flag as integer
Endtype
MapBombCount = 40
MapSizeX = 16
MapSizeY = 16
global row
global col
global width
global height
global bombs
global x
global y
global i
global v
global h
Dim map[MapSizeX, MapSizeY] as Square
LoadImage ( 1, "1.png" )
LoadImage ( 2, "2.png" )
LoadImage ( 3, "3.png" )
LoadImage ( 4, "4.png" )
LoadImage ( 5, "5.png" )
LoadImage ( 6, "6.png" )
LoadImage ( 7, "7.png" )
LoadImage ( 8, "8.png" )
LoadImage ( 9, "normal-button.png" )
LoadImage ( 10, "flag-button.png" )
LoadImage ( 11, "mine-red.png" )
LoadImage ( 12, "no-mine.png" )
for x = 1 to 256
CreateSprite(x,9)
next x
i = 0
h=1
v=1
for row = 1 to 16
for col = 1 to 16
inc spr
SetSpritePosition ( spr, h,v)
h = h + 32
NEXT col
v = v + 32
h = 1
next row
bombs = 40
createMap()
rem Gosub _drawMap
sync()
do
sync()
loop
rem DO
rem sync
remstart
If death = 1
endgame("GAME OVER")
Else
If win = 1
endgame("You Win!")
else
Gosub _controlUI
Endif
Endif
remend
rem Sync ()
rem LOOP
end
Function createMap()
For i = 1 to bombs
repeat
x = random(1,width-1)+1
y = random(1,height-1)+1
until map[x,y].bombCount = 0
map[x,y].bombCount = -1
Next i
For y = 1 to height
For x = 1 to width
if map[x,y].bombCount <> -1
bombs = 0
inc bombs, bombExists(x-1,y-1,width,height)
inc bombs, bombExists(x,y-1,width,height)
inc bombs, bombExists(x+1,y-1,width,height)
inc bombs, bombExists(x-1,y,width,height)
inc bombs, bombExists(x+1,y,width,height)
inc bombs, bombExists(x-1,y+1,width,height)
inc bombs, bombExists(x,y+1,width,height)
inc bombs, bombExists(x+1,y+1,width,height)
map[x,y].bombCount = bombs
endif
Next x
Next y
Endfunction
function bombExists(x,y,width,height)
if x < 1 or y < 1 or x > width or y > height then exitfunction 0
if map[x,y].bombCount = -1 then exitfunction 1
endfunction 0