{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "" -1 256 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Text Output" -1 6 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 2 2 2 2 2 1 2 1 3 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Tim es" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 } {PSTYLE "Author" -1 19 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 11 "MineSweeper" }}{PARA 19 " " 0 "" {TEXT -1 16 "by Jason Cornish" }}{PARA 0 "" 0 "" {TEXT -1 50 "T his maplet emulates the Windows Minesweeper game." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 256 96 "To run this maplet, clic k the \"Execute-Worksheet\" button in the tool-bar menu (the !!! butt on)\n" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "wit h(Maplets):with(Elements):with(Tools):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "row:=9:\ncol:=9:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 68 "field:=array(1..row,1..col):\nfield1:=array(1..row,1. .col):\nminelist:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "count: =0:numuncovered:numflagged:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 432 "init:=proc()\n local r,rn,i,j:\n global field,field1,count,numu ncovered,minelist,numflagged:\n\n count:=0:\n numuncovered:=1:\n nu mflagged:=0:\n randomize():\n r:=rand(1..100):\n for i from 1 to ro w do\n for j from 1 to col do\n field1[i,j]:=0:\n rn:=r() :\n if rn > 85 then\n field[i,j]:=M:\n count:=count +1:\n minelist[count]:=[i,j]:\n else\n field[i,j]:= 0:\n end:\n end:\n end:\nend: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2541 "counter:=proc()\n local num,i,j,c:\n global field :\n\n for i from 1 to row do\n for j from 1 to col do\n if fi eld[i,j]<>M then\n num:=0: \n if i=1 and j=1 then\n \+ if field[i,j+1] = M then num:=num+1 end:\n if field[i+ 1,j] = M then num:=num+1 end:\n if field[i+1,j+1] = M then nu m:=num+1 end:\n elif i=1 and j=col then\n if field[i,j -1] = M then num:=num+1 end:\n if field[i+1,j] = M then num:= num+1 end:\n if field[i+1,j-1] = M then num:=num+1 end:\n \+ elif i=row and j=1 then\n if field[i-1,j] = M then num:=n um+1 end:\n if field[i-1,j+1] = M then num:=num+1 end:\n \+ if field[i,j+1] = M then num:=num+1 end:\n elif i=row and \+ j=col then\n if field[i-1,j-1] = M then num:=num+1 end:\n \+ if field[i-1,j] = M then num:=num+1 end:\n if field[i,j -1] = M then num:=num+1 end:\n elif i=1 then\n if fiel d[i,j-1] = M then num:=num+1 end:\n if field[i,j+1] = M then \+ num:=num+1 end:\n if field[i+1,j-1] = M then num:=num+1 end: \n if field[i+1,j] = M then num:=num+1 end:\n if fie ld[i+1,j+1] = M then num:=num+1 end:\n elif i=row then\n \+ if field[i-1,j-1] = M then num:=num+1 end:\n if field[i-1, j] = M then num:=num+1 end:\n if field[i-1,j+1] = M then num: =num+1 end:\n if field[i,j-1] = M then num:=num+1 end:\n \+ if field[i,j+1] = M then num:=num+1 end:\n elif j=1 then\n if field[i-1,j] = M then num:=num+1 end:\n if field [i-1,j+1] = M then num:=num+1 end:\n if field[i,j+1] = M then num:=num+1 end:\n if field[i+1,j] = M then num:=num+1 end:\n if field[i+1,j+1] = M then num:=num+1 end:\n elif j=c ol then\n if field[i-1,j-1] = M then num:=num+1 end:\n \+ if field[i-1,j] = M then num:=num+1 end:\n if field[i,j-1] = M then num:=num+1 end:\n if field[i+1,j-1] = M then num:=n um+1 end:\n if field[i+1,j] = M then num:=num+1 end:\n \+ else\n if field[i-1,j-1] = M then num:=num+1 end:\n \+ if field[i-1,j] = M then num:=num+1 end:\n if field[i-1,j+1] = M then num:=num+1 end:\n if field[i,j-1] = M then num:=num +1 end:\n if field[i,j+1] = M then num:=num+1 end:\n \+ if field[i+1,j-1] = M then num:=num+1 end:\n if field[i+1,j] = M then num:=num+1 end:\n if field[i+1,j+1] = M then num:=n um+1 end:\n end: \n field[i,j]:=num:\n end:\n \+ c:=c+1:\n end:\n end:\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 2754 "recurs:=proc(i,j,l)\n global field,numuncovered,nu mflagged:\n local bn,str,flag,clr,unflag:\n\n bn:=convert(cat(\"B\", i,\"a\",j),name):\n\n flag:=convert(Get(RBF(value)),string):\n unfla g:=convert(Get(RBU(value)),string):\n clr:=convert(Get(bn(background) ),string):\n\n if flag=\"true\" and numflagged=row*col-count then\n gameover (\"win\"):\n end: \n str:=convert(cat(\"MineSweeper: \",convert(cou nt,string),\" ,\",convert(numuncovered,string),\",\",convert(numflagge d,string)),string):\n\n if field[i,j]<>0 then\n if field[i,j]=M th en\n Set(bn(caption)=convert(field[i,j],string)):\n gameover (\"lose\"):\n elif field[i,j]<>E then\n Set(bn(caption)=conver t(field[i,j],string)):\n Set(bn(background)=\"white\"):\n nu muncovered:=numuncovered+1:\n Set(W(title)=str):\n field[i,j ]:=E:\n end:\n else\n field[i,j]:=E:\n Set(bn(background)=\" white\"):\n Set(W(title)=str):\n numuncovered:=numuncovered+1:\n if i=1 and j=1 then\n recurs(i,j+1,l+1):\n recurs(i+1,j, l+1):\n recurs(i+1,j+1,l+1):\n elif i=1 and j=col then\n \+ recurs(i,j-1,l+1):\n recurs(i+1,j,l+1):\n recurs(i+1,j-1,l+1 ):\n elif i=row and j=1 then\n recurs(i,j+1,l+1):\n recur s(i-1,j,l+1):\n recurs(i-1,j+1,l+1):\n elif i=row and j=col th en\n recurs(i,j-1,l+1):\n recurs(i-1,j,l+1):\n recurs(i -1,j-1,l+1):\n elif i=1 then\n recurs(i,j-1,l+1):\n recur s(i,j+1,l+1):\n recurs(i+1,j,l+1):\n recurs(i+1,j-1,l+1):\n \+ recurs(i+1,j+1,l+1):\n elif i=row then\n recurs(i,j-1,l+1 ):\n recurs(i,j+1,l+1):\n recurs(i-1,j,l+1):\n recurs(i -1,j-1,l+1):\n recurs(i-1,j+1,l+1):\n elif j=1 then\n rec urs(i,j+1,l+1):\n recurs(i-1,j,l+1):\n recurs(i+1,j,l+1):\n \+ recurs(i-1,j+1,l+1):\n recurs(i+1,j+1,l+1):\n elif j=col \+ then\n recurs(i,j-1,l+1):\n recurs(i-1,j,l+1):\n recurs (i+1,j,l+1):\n recurs(i-1,j-1,l+1):\n recurs(i+1,j-1,l+1):\n else\n recurs(i,j-1,l+1):\n recurs(i,j+1,l+1):\n re curs(i-1,j,l+1):\n recurs(i+1,j,l+1):\n recurs(i-1,j-1,l+1): \n recurs(i-1,j+1,l+1):\n recurs(i+1,j-1,l+1):\n recurs (i+1,j+1,l+1):\n end:\n end:\nend: #!!!\nend:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 273 "gameover:=proc(winlose)\n local i,bn,cl r:\n\n if winlose=\"win\" then\n clr:=\"green\":\n elif winlose= \"lose\" then\n clr:=\"red\":\n end:\n\n for i from 1 to count do \n bn:=convert(cat(\"B\",minelist[i][1],\"a\",minelist[i][2]),name) :\n Set(bn(background)=clr):\n end:\nend: " }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 239 "reset:=proc()\n local i,j,bn:\n \n init( ):\n counter():\n for i from 1 to row do\n for j from 1 to col do \n bn:=convert(cat(\"B\",i,\"a\",j),name):\n Set(bn(backgrou nd)=\"#C0C0C0\"):\n Set(bn(caption)=\" \"):\n end:\n end:\ne nd: \n" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "\nbarray:=array(1..row,1..col):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 192 "for i from 1 to row do\n for j from 1 to col d o\n bn:=convert(cat(\"B\",i,\"a\",j),name): \n barray[i,j]:=But ton[bn](\" \",Evaluate(function='recurs'(i,j,1)),background=\"#C0C0C0 \"):\n end:\nend:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "garray:=array (1..row):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 244 "lout:=GridLayout(inse t=0):\nfor i from 1 to row do\n garray[i]:=GridRow():\n for j from 1 to col do\n bn:=convert(cat(\"B\",i,\"a\",j),name):\n garray[i] :=AddContent(garray[i],GridCell(value=bn)):\n end:\n lout:=AddConten t(lout,garray[i]):\nend: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 529 "Mine:=Maplet(onstartup=RunWindow(W),\n Window[W](title=\"M ineSweeper: 0,0\",\n [\n lout,\n [\n \+ \"normal\",RadioButton[RB](value=true,group=BG),\n \+ \"flag\",RadioButton[RBF](value=false,group=BG),\n \+ \"unflag\",RadioButton[RBU](value=false,group=BG),\n Butt on(\"Reset\",Evaluate(function='reset()'))\n ]\n ] \n ),\n convert(barray,listlist),\n CheckBox[CB]( value=false,onchange=Shutdown()),\n ButtonGroup[BG]()\n ): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "play:=proc()\n init(): \n counter():\n Display(Mine):\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "play();" }}{PARA 6 "" 1 "" {TEXT -1 38 "Initializing J ava runtime environment." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "0 4 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }