A quick example of a minesweeper game in roughly 100 lines of code.
setVirtualResolution(640,960)
Global _Width = 0
Global _Height = 0
Global _OffsetX = 0
Global _OffsetY = 0
Global _BlockSize = 0
type Block
sprite as integer
text as integer
state as integer
bomb as integer
number as integer
endtype
buildMap(8, 10, 4)
do
if getRawMouseLeftPressed()
x = trunc((getRawMouseX()-_OffsetX) / _BlockSize)
y = trunc((getRawMouseY()-_OffsetY) / _BlockSize)
clearBlocks(x, y)
if isMapCleared() = 1
win$ = "You Won!"
endif
endif
print(win$)
Sync()
loop
function buildMap(width, height, bombs)
W = GetVirtualWidth()
H = GetVirtualHeight()
_BlockSize = trunc(W / width)
_Width = width
_Height = height
_OffsetX = (W - _BlockSize*width) / 2
_OffsetY = H - _BlockSize*height
dim blocks[width, height] as Block
// Add bombs
for i = 1 to bombs
x = random(0, width-1)
y = random(0, height-1)
blocks[x, y].bomb = 1
next i
// Calculate numbers
for y = 0 to height-1
for x = 0 to width-1
if blocks[x,y].bomb = 0
count = 0
inc count, findBombs(x-1, y-1)
inc count, findBombs(x, y-1)
inc count, findBombs(x+1, y-1)
inc count, findBombs(x-1, y+1)
inc count, findBombs(x, y+1)
inc count, findBombs(x+1, y+1)
inc count, findBombs(x-1, y)
inc count, findBombs(x+1, y)
blocks[x,y].number = count
endif
next x
next y
// Create tiles
for y = 0 to height-1
for x = 0 to width-1
blocks[x,y].sprite = createSprite(0)
blocks[x,y].text = createText(str(blocks[x,y].number))
setTextDepth(blocks[x,y].text, 11)
if blocks[x,y].bomb = 1
setTextString(blocks[x,y].text, "X")
setTextColor(blocks[x,y].text, 255,0,0,255)
endif
blocks[x,y].state = 1
setTextSize(blocks[x,y].text, _BlockSize)
tox = (_BlockSize - getTextTotalWidth(blocks[x,y].text)) / 2
setSpriteSize(blocks[x,y].sprite, _BlockSize, _BlockSize)
setSpritePosition(blocks[x,y].sprite, _OffsetX + x*_BlockSize, _OffsetY + y*_BlockSize)
setTextPosition(blocks[x,y].text, _OffsetX + x*_BlockSize + tox, _OffsetY + y*_BlockSize)
setSpriteColor(blocks[x,y].sprite, random(0,255),random(0,255),random(0,255),255)
next x
next y
endfunction
function findBombs(x, y)
if x >= 0 and x < _Width and y >= 0 and y < _Height
t = blocks[x,y].bomb
exitfunction t
endif
endfunction 0
function clearBlocks(x, y)
sync()
if x >= 0 and x < _Width and y >= 0 and y < _Height
if blocks[x, y].state > 0
blocks[x, y].state = 0
setSpriteVisible(blocks[x,y].sprite, 0)
if blocks[x, y].number = 0 and blocks[x,y].bomb = 0
clearBlocks(x-1, y-1)
clearBlocks(x, y-1)
clearBlocks(x+1, y-1)
clearBlocks(x-1, y+1)
clearBlocks(x, y+1)
clearBlocks(x+1, y+1)
clearBlocks(x-1, y)
clearBlocks(x+1, y)
endif
endif
endif
endfunction
function isMapCleared()
for y = 0 to _Height-1
for x = 0 to _Width-1
if blocks[x,y].state = 1
if blocks[x,y].bomb = 0 then exitfunction 0
endif
next x
next y
endfunction 1
"You're all wrong. You're all idiots." ~Fluffy Rabbit