fb:porticula NoPaste
mine sweeper field generator (dynamic and colored)
Uploader: | gast |
Datum/Zeit: | 12.06.2006 23:46:32 |
'Autor: MisterD
#define sizex 9
#define sizey 9
#define mines 10
randomize timer
dim shared area(sizex-1,sizey-1) as integer
for n = 1 to mines 'spread mines
do 'look for an empty spot
x=int(rnd*sizex)
y=int(rnd*sizey)
loop while area(x,y)<0
for dx = x-1 to x+1 'insert into field
for dy = y-1 to y+1
if dx>=0 and dx<sizex and dy>=0 and dy<sizey then
if dx=x and dy=y then 'set mine on spot
area(dx,dy)=-1
elseif area(dx,dy)>=0 then 'increase the sourrounding fields values
area(dx,dy)=area(dx,dy)+1
end if
end if
next dy
next dx
next n
for y = 0 to sizex-1 'do output
for x = 0 to sizey-1
select case area(x,y)
case -1 : color 12 : print "X"; ' = mine
case 0 : color 8 : print "."; ' = empty
case else : color area(x,y) : print trim(str(area(x,y))); ' = empty but has a value
end select
next x
print 'next line
next y
sleep