Microsoft's minesweeper game

Post Reply
Posts: 793
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Location: Groningen, Netherlands
Flag: Netherlands

Microsoft's minesweeper game

Post by Henko »

If you are not familiair with the game, please search on internet.
If have not paid too much attention to a nice UI, but the little game functions well.

873FD52C-91DD-4636-9534-47FF52A20FFA.png (351.02 KiB) Viewed 6584 times

Code: Select all

' minesweeper game
graphics ! graphics clear .8,.8,.8
draw color 0,0,0 ! draw size 3 ! fill color .8,.8,.8
get screen size sw,sh ! xc=sw/2
button "s9" text "9 x 9" at 30,60 size 120,30
button "s15" text "15 x15" at 230,60 size 120,30
button "s21" text "21 x 21" at 430,60 size 120,30
draw text "s e l e c t   b o a r d   s i z e" at 100,20
do slowdown
  if bp("s9")  then ! nb=9  ! break ! end if
  if bp("s15") then ! nb=15 ! break ! end if
  if bp("s21") then ! nb=21 ! break ! end if
  until forever
fill rect 100,20 to 500,50
button "s9" delete ! button "s15" delete ! button "s21" delete
dim m(nb,nb),w(nb,nb)
for i=0 to nb-1 ! for j=0 to nb-1 ! w(i,j)=1 ! next j ! next i
nm=10 ! if nb>9 then nm+=4*(nb-9) ! if nb>15 then nm+=6*(nb-15)
for k=1 to nm
  do ! i=rnd(nb) ! j=rnd(nb) ! until m(i,j)=0
  m(i,j)=1 ! w(i,j)=0
  next k
do slowdown
  for i=0 to nb-1
    for j=0 to nb-1
      if bp(b$) then
        w(i,j)=0 ! res=check(i,j) ! if res=-1 then break
        if res>0 then button b$ text res else button b$ delete
        if check_win() then
          draw text "You win!!" at 330,40 ! beep ! stop
          end if
        end if
    next j
    if res=-1 then break
  next i
  if res=-1 then ! lose() ! stop ! end if

  until forever

def draw_field(nb)
nb2=floor(nb/2) ! d=2
xo=.xc-(nb2+.5)*bw-(nb2)*d ! yo=80
set buttons font name "Papyrus"
set buttons font size 400/.nb
for i=0 to nb-1 ! for j=0 to nb-1
  x=xo+i*(bw+d) ! y=yo+j*(bw+d)
  button i&"-"&j text "" at x,y size bw,bw
  next j ! next i
draw rect xo-5,yo-53-d to x+bw+d+3,y+bw+d+3
draw line xo-5,yo-d-3 to x+bw+d+3,yo-d-3
end def

def check(i,j)
if .m(i,j) then return -1
ii=i ! jj=j ! sum=0
for i=max(0,ii-1) to min(.nb-1,ii+1)
  for j=max(0,jj-1) to min(.nb-1,jj+1)
    if ii<>i or jj<>j then sum+=.m(i,j)
    next j
  next i
return sum
end def

def check_win()
for i=0 to .nb-1 ! for j=0 to .nb-1
  if .w(i,j) then return 0
  next j ! next i
return 1
end def

def lose()
for i=0 to .nb-1 ! for j=0 to .nb-1
  if .m(i,j) then button i&"-"&j text chr$(9899)
  next j ! next i
end def

def bp(a$) = button_pressed(a$)

Post Reply