home *** CD-ROM | disk | FTP | other *** search
/ APDL Best Games 1 / APDL_GAMES_1.iso / _minesweep / _runimage (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1998-08-03  |  13.0 KB  |  560 lines

  1.  !Minesweeper v1.41
  2.  by Keith Drakard
  3.  11/04/94
  4. Wimp_WindowAlert("ERROR!","at line "+
  5. ):finished%=
  6.  "<MineData$Dir>.Wimp"
  7. Wimp_Start("Minesweeper",9248,3351)
  8. User_SetInitialData
  9. Create_Windows
  10. Create_Menus
  11. Wimp_WaitForEvent
  12. Wimp_CloseDown
  13. User_SetInitialData
  14.  done%=
  15. :start%=
  16. :new%=
  17. : maxcols%=16:maxrows%=12:cols%=maxcols%:rows%=maxrows%
  18.  mines%=35:ms%=
  19. :gr%=1
  20.  square%(maxcols%,maxrows%)
  21.  bnum%(maxcols%,maxrows%)
  22.  grid%(maxcols%,maxrows%)
  23.  state%(maxcols%,maxrows%)
  24.  scores%(5,3),names$(5,3)
  25.  dum%=
  26. reset
  27. " done%=
  28. :oldm$="x":oldten$="x"
  29.  bnum%()=0:left%=mines%
  30.  wrong%=0:colon%=0
  31. Wimp_IconPutText(main_Window%,194,"happy")
  32.  n%=1 
  33.  (maxrows%*maxcols%)
  34.   x%=((n%-1) 
  35.  maxcols%)+1
  36.   y%=((n%-1) 
  37.  maxcols%)+1
  38.  square%(x%,y%)<>0 
  39.  grid%(x%,y%)=2 
  40. Wimp_IconPutText(main_Window%,n%,"blank")
  41.  state%(x%,y%)=1 
  42.  s%=1 
  43. Wimp_IconPutText(main_Window%,n%,"blank")
  44.  state%(x%,y%)=0 
  45.  s%=1 
  46. Wimp_IconPutText(main_Window%,n%,"off")
  47.  square%()=0:grid%()=0:s%=0
  48.  m%=1 
  49.  mines%
  50. -$   x%=
  51. (maxcols%):y%=
  52. (maxrows%)
  53.  grid%(x%,y%)=0 
  54.  state%(x%,y%)=1
  55.   grid%(x%,y%)=1
  56. Create_Windows
  57. Wimp_SpritesLoad
  58. 7* main_Window%=
  59. Wimp_WindowLoad("main")
  60. 8* info_Window%=
  61. Wimp_WindowLoad("info")
  62. 9* high_Window%=
  63. Wimp_WindowLoad("high")
  64. :* talk_Window%=
  65. Wimp_WindowLoad("talk")
  66. ;* size_Window%=
  67. Wimp_WindowLoad("size")
  68. <* Bar_Icon%=
  69. Wimp_IconBar("!Minesweep")
  70. Wimp_WindowBringToTop(main_Window%)
  71. loadhiscores
  72. Wimp_WindowBringToTop(high_Window%)
  73. Event_Save(window%)=
  74. Event_Sprites(window%)=sprites%
  75. Create_Menus
  76. JE Bar_Menu%=
  77. Wimp_MenuCreate("Minesweeper\Info>info_Window%\Quit")
  78. Ke main_Menu%=
  79. Wimp_MenuCreate("Minesweeper\Info>info_Window%\Grid size\New game\Hiscores...\Quit")
  80. LY size_Menu%=
  81. Wimp_MenuCreate("Grid size\16 x 12\12 x 12\10 x 10\Custom>size_Window%")
  82. Wimp_MenuGlue(main_Menu%,2,size_Menu%)
  83. Wimp_MenuTick(size_Menu%,1)
  84. Wimp_MenuDottedLine(main_Menu%,4)
  85. Event_Menu(window%)
  86.  window% 
  87.  Bar_Window%        : =Bar_Menu%
  88.  main_Window%       : =main_Menu%
  89.                : =
  90. Event_WindowClose(window%,buttons%)
  91.  window% 
  92.  main_Window%       : 
  93. Wimp_WindowClose(high_Window%)
  94. Event_Draw(window%,x_origin%,y_origin%)
  95.  window% 
  96.  main_Window%        : 
  97. User_DrawmainWindow
  98.  info_Window%        : 
  99. User_DrawinfoWindow
  100.  high_Window%        : 
  101. User_DrawhighWindow
  102.  talk_Window%        : 
  103. User_DrawtalkWindow
  104. User_DrawmainWindow
  105. User_DrawinfoWindow
  106. User_DrawhighWindow
  107. User_DrawtalkWindow
  108. setwindow
  109.  state%()=1
  110.  maxcols%-cols%=0 
  111.  xmod%=0 
  112.  xmod%=
  113. ((maxcols%-cols%)/2)
  114.  maxrows%-rows%=0 
  115.  ymod%=0 
  116.  ymod%=
  117. ((maxrows%-rows%)/2)
  118.  n%=1 
  119.  (maxrows%*maxcols%)
  120.   x%=((n%-1) 
  121.  maxcols%)+1
  122.   y%=((n%-1) 
  123.  maxcols%)+1
  124.  x%<=xmod% 
  125.  x%>(cols%+xmod%) 
  126.  y%<=ymod% 
  127.  y%>(rows%+ymod%) 
  128.  state%(x%,y%)=0
  129. reset
  130. Event_MouseClick(window%,icon%,button%,x%,y%)
  131.  window% 
  132.  Bar_Window%        : 
  133. User_MouseBar
  134.  main_Window%       : 
  135. User_Mousemain( button%,icon%)
  136.  info_Window%       : 
  137. User_Mouseinfo( button%,icon%)
  138.  high_Window%       : 
  139. User_Mousehigh( button%,icon%)
  140.  talk_Window%       : 
  141. User_Mousetalk( button%,icon%)
  142.  size_Window%       : 
  143. User_Mousesize( button%,icon%)
  144. User_MouseBar
  145. Wimp_WindowBringToTop(main_Window%):
  146. Wimp_WindowBringToTop(high_Window%)
  147. User_Mousemain( button%,icon%)
  148.  icon%=194 
  149.  ms%=
  150. setwindow:start%=
  151. clock:
  152. minesleft
  153.  start%=
  154.  icon%>=1 
  155.  icon%<=192 
  156.  done%=
  157.  ms%=
  158. !  x%=((icon%-1) 
  159.  maxcols%)+1
  160. !  y%=((icon%-1) 
  161.  maxcols%)+1
  162.  state%(x%,y%)=1 
  163.  button% 
  164. #    
  165.  1 : 
  166.  square%(x%,y%)>=0 
  167. X              
  168.  (left%>0 
  169.  square%(x%,y%)>0) 
  170.  square%(x%,y%)=(square%(x%,y%)+1) 
  171. %              
  172.  square%(x%,y%) 
  173. E               
  174. Wimp_IconPutText(main_Window%,icon%,"blank")
  175. M               
  176. Wimp_IconPutText(main_Window%,icon%,"flag"):left%-=1
  177. M               
  178. Wimp_IconPutText(main_Window%,icon%,"mark"):left%+=1
  179.               
  180.               
  181. minesleft
  182.               
  183.  left%=0 
  184.                time%=
  185.                
  186.                
  187.  wrong%>0 
  188. =                
  189. Wimp_IconPutText(main_Window%,194,"sad")
  190. P                
  191. talk("Sorry, you have "+
  192. wrong%+" wrongly placed flag(s)!")
  193.                
  194. B                
  195. Wimp_IconPutText(main_Window%,194,"laughing")
  196. S                
  197. talk("Well done! You have located and defused all the mines!")
  198. )                
  199. checkscores(time%,0)
  200.                
  201.               
  202.              
  203. "    
  204.  4 : 
  205.  square%(x%,y%)=0 
  206. (              numb%=
  207. around(x%,y%,0)
  208.               
  209.  numb%=-2 
  210. ?               
  211. Wimp_IconPutText(main_Window%,icon%,"mine")
  212. <               
  213. Wimp_IconPutText(main_Window%,194,"sad")
  214.                
  215.                
  216.               
  217.              
  218.  wrong%=0
  219.  n%=1 
  220.  (maxrows%*maxcols%)
  221.   x%=((n%-1) 
  222.  maxcols%)+1
  223.   y%=((n%-1) 
  224.  maxcols%)+1
  225.  square%(x%,y%)>0 
  226.  grid%(x%,y%)=0 
  227. Wimp_IconPutText(main_Window%,n%,"wrong")
  228.    wrong%+=1
  229.  square%(x%,y%)=0 
  230.  grid%(x%,y%)=1 
  231. Wimp_IconPutText(main_Window%,n%,"mine"):grid%(x%,y%)=2
  232.  done%=
  233. Wimp_IconPutText(main_Window%,206,"digi_:")
  234. around(x2%,y2%,f%)
  235.  cnt%,p%,q%
  236.  (x2%<xmod% 
  237.  x2%>cols%+xmod% 
  238.  y2%<ymod% 
  239.  y2%>rows%+ymod%) 
  240.  square%(x2%,y2%)<>0 
  241.  f%=0 
  242.  bnum%()=0
  243.  grid%(x2%,y2%)=1 
  244.  f%=0 
  245.  cnt%=
  246. count(x2%,y2%)
  247.  cnt%=0 
  248. Wimp_IconPutText(main_Window%,((y2%-1)*maxcols%)+x2%,"safe")
  249.   square%(x2%,y2%)=-1
  250.   p%=x2%-2
  251.    p%+=1:q%=y2%-2
  252.     q%+=1
  253. G    
  254.  (p%>xmod% 
  255.  p%<=cols%+xmod%) 
  256.  (q%>ymod% 
  257.  q%<=rows%+ymod%) 
  258. U     
  259. (p%=x2% 
  260.  q%=y2%) 
  261.  bnum%(p%,q%)=0 
  262.  bnum%(p%,q%)=1:cnt%=
  263. around(p%,q%,1)
  264.         
  265.  q%=y2%+1
  266.  p%=x2%+1
  267. Wimp_IconPutText(main_Window%,((y2%-1)*maxcols%)+x2%,"num"+
  268. cnt%)
  269.   square%(x2%,y2%)=-1
  270.     =cnt%
  271.  DEF FNoldcount(x3%,y3%)
  272.   LOCAL c%,u%,v%
  273.   c%=0:u%=x3%-2
  274.   REPEAT
  275.    u%+=1:v%=y3%-2
  276.    REPEAT
  277.     v%+=1
  278.     IF NOT(u%=x3% AND v%=y3%) THEN IF (u%>0 AND u%<=cols%) AND (v%>0 AND v%<=rows%) THEN c%+=grid%(u%,v%)
  279.    UNTIL v%=y3%+1
  280.   UNTIL u%=x3%+1
  281. count(x3%,y3%)
  282.  c%,u%,v%
  283.      c%=0
  284. M u%=x3%-1:v%=y3%-1:
  285.  u%>xmod%        
  286.  v%>ymod%        
  287.  c%+=grid%(u%,v%)
  288. O u%=x3%  :v%=y3%-1:
  289.                      v%>ymod%        
  290.  c%+=grid%(u%,v%)
  291. M u%=x3%+1:v%=y3%-1:
  292.  u%<=cols%+xmod% 
  293.  v%>ymod%        
  294.  c%+=grid%(u%,v%)
  295. O u%=x3%-1:v%=y3%  :
  296.  u%>xmod%                            
  297.  c%+=grid%(u%,v%)
  298. O u%=x3%+1:v%=y3%  :
  299.  u%<=cols%+xmod%                     
  300.  c%+=grid%(u%,v%)
  301. M u%=x3%-1:v%=y3%+1:
  302.  u%>xmod%        
  303.  v%<=rows%+ymod% 
  304.  c%+=grid%(u%,v%)
  305. O u%=x3%  :v%=y3%+1:
  306.                      v%<=rows%+ymod% 
  307.  c%+=grid%(u%,v%)
  308. M u%=x3%+1:v%=y3%+1:
  309.  u%<=cols%+xmod% 
  310.  v%<=rows%+ymod% 
  311.  c%+=grid%(u%,v%)
  312. User_Mouseinfo( button%,icon%)
  313. User_Mousehigh( button%,icon%)
  314. User_Mousetalk( button%,icon%)
  315.  icon%=3 
  316.  ms%=
  317. Wimp_WindowClose(talk_Window%)
  318. User_Mousesize( button%,icon%)
  319. R cls%=
  320. Wimp_IconText(size_Window%,6)):rws%=
  321. Wimp_IconText(size_Window%,9))
  322. 1 mns%=
  323. Wimp_IconText(size_Window%,10)):s%=0
  324.  icon% 
  325.  3  : s%=1                     : 
  326.  'OK'
  327.  4  : 
  328.  cls%<maxcols% cls%+=1 : 
  329. Wimp_IconPutText(size_Window%,6,
  330. cls%) : 
  331.  5  : 
  332.  cls%>2 cls%-=1        : 
  333. Wimp_IconPutText(size_Window%,6,
  334. cls%) : 
  335.  down
  336.  6  :                            
  337.  height box
  338.  7  : 
  339.  rws%>2 rws%-=1        : 
  340. Wimp_IconPutText(size_Window%,9,
  341. rws%) : 
  342.  left
  343.  8  : 
  344.  rws%<maxrows% rws%+=1 : 
  345. Wimp_IconPutText(size_Window%,9,
  346. rws%) : 
  347.  right
  348.  9  :                            
  349.  width box
  350.  10 :                            
  351.  mines box
  352.  s%=1 
  353.  mns%<cls%*rws% 
  354.  gr%<>0 
  355. !C    
  356. Wimp_MenuTick(size_Menu%,gr%):
  357. Wimp_MenuTick(size_Menu%,4)
  358. "G    
  359. Wimp_MenuDisable(main_Menu%,4):
  360. Wimp_WindowClose(high_Window%)
  361. $.   gr%=0:mines%=mns%:cols%=cls%:rows%=rws%
  362. %*   
  363. Wimp_MenuClose:
  364. setwindow:start%=
  365. clock:
  366. minesleft
  367. Event_KeyPress(window%,icon%,key%)
  368.  window% 
  369.  not needed anymore (see comments about mask% in Wimp file)
  370.  WHEN high_Window%       : PROCUser_KeyPresshigh(icon%,key%)
  371. User_KeyPresshigh(icon%,key%)
  372.  icon%=17 
  373.  key% 
  374. 7!   
  375.  8,127 : yn$=
  376. yn$-1)
  377. 8#   
  378.  key%>64 
  379.  key%<123 
  380. 9%                 
  381.  : yn$+=
  382.                  
  383.                 
  384. Wimp_IconPutText(high_Window%,17,yn$)
  385. Event_MenuChoice(menu%)
  386.  menu% 
  387.  Bar_Menu%          : 
  388. User_MenuChoiceBar
  389.  main_Menu%         : 
  390. User_MenuChoicemain
  391. User_MenuChoiceBar
  392. Wimp_MenuChoice(0) 
  393.  1 : 
  394.  info
  395.  2 : finished%=
  396. User_MenuChoicemain
  397. Wimp_MenuChoice(0) 
  398.  1 : 
  399.  info
  400.  2 : ng%=
  401. Wimp_MenuChoice(1)
  402.            
  403.  ng%<4 
  404. WV            
  405.  gr%<>0 
  406. Wimp_MenuTick(size_Menu%,gr%) 
  407. Wimp_MenuTick(size_Menu%,4)
  408. X6            gr%=ng%:
  409. Wimp_MenuTick(size_Menu%,gr%)
  410.             
  411.  gr% 
  412. Z>             
  413.  1 : mines%=35:rows%=maxrows%:cols%=maxcols%
  414. [2             
  415.  2 : mines%=25:rows%=12:cols%=12
  416. \2             
  417.  3 : mines%=17:rows%=10:cols%=10
  418.             
  419. ^.            
  420. Wimp_MenuEnable(main_Menu%,4)
  421. _I            
  422. checkscores(1000,0):
  423. Wimp_WindowBringToTop(high_Window%)
  424. `:            s%=1:
  425. setwindow:start%=
  426. clock:
  427. minesleft
  428.            
  429.  3 : 
  430. setwindow:start%=
  431. c            
  432. clock:
  433. minesleft
  434.  4 : 
  435. Wimp_WindowBringToTop(high_Window%)
  436.  5 : finished%=
  437. Event_LoadFile(file$,type$)
  438. Event_SaveFile(file$,window%)
  439. clock
  440.  done% 
  441. ):t$=
  442. t$-2)
  443. m$=2 
  444. (s$) 
  445.  1 : ten$="0"
  446.            unit$=s$
  447.  2 : ten$=
  448. s$,1)
  449.            unit$=
  450. s$,1)
  451.  m$<>oldm$     
  452. Wimp_IconPutText(main_Window%,203,"digi_"+m$)
  453.  ten$<>oldten$ 
  454. Wimp_IconPutText(main_Window%,204,"digi_"+ten$)
  455. Wimp_IconPutText(main_Window%,205,"digi_"+unit$)
  456.  colon%=1-colon%
  457.  colon% 
  458.  0 : 
  459. Wimp_IconPutText(main_Window%,206,"digi_")
  460.  1 : 
  461. Wimp_IconPutText(main_Window%,206,"digi_:")
  462.  oldm$=m$:oldten$=ten$
  463. minesleft
  464.  lf$=
  465. left%
  466.  1 : mhun$="0":mten$="0":munit$=lf$
  467.  2 : mhun$="0"
  468. +           mten$=
  469. lf$,1):munit$=
  470. lf$,1)
  471.  3 : mhun$=
  472. lf$,1)
  473.            mten$=
  474. lf$,2,1)
  475.            munit$=
  476. lf$,1)
  477. Wimp_IconPutText(main_Window%,198,"digi_"+mhun$)
  478. Wimp_IconPutText(main_Window%,199,"digi_"+mten$)
  479. Wimp_IconPutText(main_Window%,200,"digi_"+munit$)
  480. loadhiscores
  481. # F%=
  482. ("<Scores6$Dir>.MSscores")
  483.  F%=0 
  484. createfile:
  485.      g%=0
  486.   g%+=1:n%=0
  487.    n%+=1
  488. #F%,names$(n%,g%),scores%(n%,g%)
  489.  n%=5
  490.  g%=3
  491. #F%,yn$
  492. checkscores(1000,0)
  493. savehiscores
  494. # F%=
  495. ("<Scores6$Dir>.MSscores")
  496.      g%=0
  497.   g%+=1:n%=0
  498.    n%+=1
  499. #F%,names$(n%,g%),scores%(n%,g%)
  500.  n%=5
  501.  g%=3
  502. #F%,yn$
  503.  new% 
  504. ("SetType <MineData$Dir>.HiScores Data"):new%=
  505. createfile
  506. talk("Creating new hiscore file")
  507.  names$()="Keith Drakard"
  508.  scores%()=599
  509.  yn$="Keith Drakard":new%=
  510. savehiscores
  511. checkscores(1000,0)
  512. checkscores(time%,s%)
  513.  time%=1000 
  514. Wimp_IconPutText(high_Window%,17,yn$) 
  515.  yn$=
  516. Wimp_IconText(high_Window%,17)
  517.  n%=0:nm$=yn$
  518.   n%+=1
  519.  time%<=scores%(n%,gr%) 
  520.  time%,scores%(n%,gr%):
  521.  nm$,names$(n%,gr%):s%=1
  522.  n%=5
  523.      n%=0
  524.   n%+=1
  525. Wimp_IconPutText(high_Window%,5+n%,names$(n%,gr%))
  526. !  ss$=
  527. (scores%(n%,gr%) 
  528. ss$=1 
  529.    ss$="0"+ss$
  530.  IF (VALss$ MOD 10)=0 THEN ss$+="0"
  531. )  sc$=
  532. (scores%(n%,gr%) 
  533.  60)+":"+ss$
  534. Wimp_IconPutText(high_Window%,10+n%,sc$)
  535.  n%=5
  536.  s%=1 
  537. savehiscores
  538. talk(mess$)
  539.  ms%=
  540.  line$="":k%=1
  541.  l%=0:w$=""
  542. Wimp_IconPutText(talk_Window%,2,"")
  543. Wimp_WindowBringToTop(talk_Window%)
  544. )  l%=
  545. mess$," "):
  546.  l%=0 
  547. (mess$)
  548.   w$=
  549. mess$,l%)
  550.   mess$=
  551. mess$,
  552. (mess$)-l%)
  553. (line$+w$)<=34 
  554.    line$+=w$
  555. Wimp_IconPutText(talk_Window%,k%,line$)
  556.    k%+=1:line$=w$
  557.  mess$="" 
  558. Wimp_IconPutText(talk_Window%,k%,line$)
  559.  mess$=""
  560.