home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1998-08-03 | 13.0 KB | 560 lines |
- !Minesweeper v1.41
- by Keith Drakard
- 11/04/94
- Wimp_WindowAlert("ERROR!","at line "+
- ):finished%=
- "<MineData$Dir>.Wimp"
- Wimp_Start("Minesweeper",9248,3351)
- User_SetInitialData
- Create_Windows
- Create_Menus
- Wimp_WaitForEvent
- Wimp_CloseDown
- User_SetInitialData
- done%=
- :start%=
- :new%=
- : maxcols%=16:maxrows%=12:cols%=maxcols%:rows%=maxrows%
- mines%=35:ms%=
- :gr%=1
- square%(maxcols%,maxrows%)
- bnum%(maxcols%,maxrows%)
- grid%(maxcols%,maxrows%)
- state%(maxcols%,maxrows%)
- scores%(5,3),names$(5,3)
- dum%=
- reset
- " done%=
- :oldm$="x":oldten$="x"
- bnum%()=0:left%=mines%
- wrong%=0:colon%=0
- Wimp_IconPutText(main_Window%,194,"happy")
- n%=1
- (maxrows%*maxcols%)
- x%=((n%-1)
- maxcols%)+1
- y%=((n%-1)
- maxcols%)+1
- square%(x%,y%)<>0
- grid%(x%,y%)=2
- Wimp_IconPutText(main_Window%,n%,"blank")
- state%(x%,y%)=1
- s%=1
- Wimp_IconPutText(main_Window%,n%,"blank")
- state%(x%,y%)=0
- s%=1
- Wimp_IconPutText(main_Window%,n%,"off")
- square%()=0:grid%()=0:s%=0
- m%=1
- mines%
- -$ x%=
- (maxcols%):y%=
- (maxrows%)
- grid%(x%,y%)=0
- state%(x%,y%)=1
- grid%(x%,y%)=1
- Create_Windows
- Wimp_SpritesLoad
- 7* main_Window%=
- Wimp_WindowLoad("main")
- 8* info_Window%=
- Wimp_WindowLoad("info")
- 9* high_Window%=
- Wimp_WindowLoad("high")
- :* talk_Window%=
- Wimp_WindowLoad("talk")
- ;* size_Window%=
- Wimp_WindowLoad("size")
- <* Bar_Icon%=
- Wimp_IconBar("!Minesweep")
- Wimp_WindowBringToTop(main_Window%)
- loadhiscores
- Wimp_WindowBringToTop(high_Window%)
- Event_Save(window%)=
- Event_Sprites(window%)=sprites%
- Create_Menus
- JE Bar_Menu%=
- Wimp_MenuCreate("Minesweeper\Info>info_Window%\Quit")
- Ke main_Menu%=
- Wimp_MenuCreate("Minesweeper\Info>info_Window%\Grid size\New game\Hiscores...\Quit")
- LY size_Menu%=
- Wimp_MenuCreate("Grid size\16 x 12\12 x 12\10 x 10\Custom>size_Window%")
- Wimp_MenuGlue(main_Menu%,2,size_Menu%)
- Wimp_MenuTick(size_Menu%,1)
- Wimp_MenuDottedLine(main_Menu%,4)
- Event_Menu(window%)
- window%
- Bar_Window% : =Bar_Menu%
- main_Window% : =main_Menu%
- : =
- Event_WindowClose(window%,buttons%)
- window%
- main_Window% :
- Wimp_WindowClose(high_Window%)
- Event_Draw(window%,x_origin%,y_origin%)
- window%
- main_Window% :
- User_DrawmainWindow
- info_Window% :
- User_DrawinfoWindow
- high_Window% :
- User_DrawhighWindow
- talk_Window% :
- User_DrawtalkWindow
- User_DrawmainWindow
- User_DrawinfoWindow
- User_DrawhighWindow
- User_DrawtalkWindow
- setwindow
- state%()=1
- maxcols%-cols%=0
- xmod%=0
- xmod%=
- ((maxcols%-cols%)/2)
- maxrows%-rows%=0
- ymod%=0
- ymod%=
- ((maxrows%-rows%)/2)
- n%=1
- (maxrows%*maxcols%)
- x%=((n%-1)
- maxcols%)+1
- y%=((n%-1)
- maxcols%)+1
- x%<=xmod%
- x%>(cols%+xmod%)
- y%<=ymod%
- y%>(rows%+ymod%)
- state%(x%,y%)=0
- reset
- Event_MouseClick(window%,icon%,button%,x%,y%)
- window%
- Bar_Window% :
- User_MouseBar
- main_Window% :
- User_Mousemain( button%,icon%)
- info_Window% :
- User_Mouseinfo( button%,icon%)
- high_Window% :
- User_Mousehigh( button%,icon%)
- talk_Window% :
- User_Mousetalk( button%,icon%)
- size_Window% :
- User_Mousesize( button%,icon%)
- User_MouseBar
- Wimp_WindowBringToTop(main_Window%):
- Wimp_WindowBringToTop(high_Window%)
- User_Mousemain( button%,icon%)
- icon%=194
- ms%=
- setwindow:start%=
- clock:
- minesleft
- start%=
- icon%>=1
- icon%<=192
- done%=
- ms%=
- ! x%=((icon%-1)
- maxcols%)+1
- ! y%=((icon%-1)
- maxcols%)+1
- state%(x%,y%)=1
- button%
- #
- 1 :
- square%(x%,y%)>=0
- X
- (left%>0
- square%(x%,y%)>0)
- square%(x%,y%)=(square%(x%,y%)+1)
- %
- square%(x%,y%)
- E
- Wimp_IconPutText(main_Window%,icon%,"blank")
- M
- Wimp_IconPutText(main_Window%,icon%,"flag"):left%-=1
- M
- Wimp_IconPutText(main_Window%,icon%,"mark"):left%+=1
-
-
- minesleft
-
- left%=0
- time%=
-
-
- wrong%>0
- =
- Wimp_IconPutText(main_Window%,194,"sad")
- P
- talk("Sorry, you have "+
- wrong%+" wrongly placed flag(s)!")
-
- B
- Wimp_IconPutText(main_Window%,194,"laughing")
- S
- talk("Well done! You have located and defused all the mines!")
- )
- checkscores(time%,0)
-
-
-
- "
- 4 :
- square%(x%,y%)=0
- ( numb%=
- around(x%,y%,0)
-
- numb%=-2
- ?
- Wimp_IconPutText(main_Window%,icon%,"mine")
- <
- Wimp_IconPutText(main_Window%,194,"sad")
-
-
-
-
- wrong%=0
- n%=1
- (maxrows%*maxcols%)
- x%=((n%-1)
- maxcols%)+1
- y%=((n%-1)
- maxcols%)+1
- square%(x%,y%)>0
- grid%(x%,y%)=0
- Wimp_IconPutText(main_Window%,n%,"wrong")
- wrong%+=1
- square%(x%,y%)=0
- grid%(x%,y%)=1
- Wimp_IconPutText(main_Window%,n%,"mine"):grid%(x%,y%)=2
- done%=
- Wimp_IconPutText(main_Window%,206,"digi_:")
- around(x2%,y2%,f%)
- cnt%,p%,q%
- (x2%<xmod%
- x2%>cols%+xmod%
- y2%<ymod%
- y2%>rows%+ymod%)
- square%(x2%,y2%)<>0
- f%=0
- bnum%()=0
- grid%(x2%,y2%)=1
- f%=0
- cnt%=
- count(x2%,y2%)
- cnt%=0
- Wimp_IconPutText(main_Window%,((y2%-1)*maxcols%)+x2%,"safe")
- square%(x2%,y2%)=-1
- p%=x2%-2
- p%+=1:q%=y2%-2
- q%+=1
- G
- (p%>xmod%
- p%<=cols%+xmod%)
- (q%>ymod%
- q%<=rows%+ymod%)
- U
- (p%=x2%
- q%=y2%)
- bnum%(p%,q%)=0
- bnum%(p%,q%)=1:cnt%=
- around(p%,q%,1)
-
- q%=y2%+1
- p%=x2%+1
- Wimp_IconPutText(main_Window%,((y2%-1)*maxcols%)+x2%,"num"+
- cnt%)
- square%(x2%,y2%)=-1
- =cnt%
- DEF FNoldcount(x3%,y3%)
- LOCAL c%,u%,v%
- c%=0:u%=x3%-2
- REPEAT
- u%+=1:v%=y3%-2
- REPEAT
- v%+=1
- 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%)
- UNTIL v%=y3%+1
- UNTIL u%=x3%+1
- count(x3%,y3%)
- c%,u%,v%
- c%=0
- M u%=x3%-1:v%=y3%-1:
- u%>xmod%
- v%>ymod%
- c%+=grid%(u%,v%)
- O u%=x3% :v%=y3%-1:
- v%>ymod%
- c%+=grid%(u%,v%)
- M u%=x3%+1:v%=y3%-1:
- u%<=cols%+xmod%
- v%>ymod%
- c%+=grid%(u%,v%)
- O u%=x3%-1:v%=y3% :
- u%>xmod%
- c%+=grid%(u%,v%)
- O u%=x3%+1:v%=y3% :
- u%<=cols%+xmod%
- c%+=grid%(u%,v%)
- M u%=x3%-1:v%=y3%+1:
- u%>xmod%
- v%<=rows%+ymod%
- c%+=grid%(u%,v%)
- O u%=x3% :v%=y3%+1:
- v%<=rows%+ymod%
- c%+=grid%(u%,v%)
- M u%=x3%+1:v%=y3%+1:
- u%<=cols%+xmod%
- v%<=rows%+ymod%
- c%+=grid%(u%,v%)
- User_Mouseinfo( button%,icon%)
- User_Mousehigh( button%,icon%)
- User_Mousetalk( button%,icon%)
- icon%=3
- ms%=
- Wimp_WindowClose(talk_Window%)
- User_Mousesize( button%,icon%)
- R cls%=
- Wimp_IconText(size_Window%,6)):rws%=
- Wimp_IconText(size_Window%,9))
- 1 mns%=
- Wimp_IconText(size_Window%,10)):s%=0
- icon%
- 3 : s%=1 :
- 'OK'
- 4 :
- cls%<maxcols% cls%+=1 :
- Wimp_IconPutText(size_Window%,6,
- cls%) :
- 5 :
- cls%>2 cls%-=1 :
- Wimp_IconPutText(size_Window%,6,
- cls%) :
- down
- 6 :
- height box
- 7 :
- rws%>2 rws%-=1 :
- Wimp_IconPutText(size_Window%,9,
- rws%) :
- left
- 8 :
- rws%<maxrows% rws%+=1 :
- Wimp_IconPutText(size_Window%,9,
- rws%) :
- right
- 9 :
- width box
- 10 :
- mines box
- s%=1
- mns%<cls%*rws%
- gr%<>0
- !C
- Wimp_MenuTick(size_Menu%,gr%):
- Wimp_MenuTick(size_Menu%,4)
- "G
- Wimp_MenuDisable(main_Menu%,4):
- Wimp_WindowClose(high_Window%)
- $. gr%=0:mines%=mns%:cols%=cls%:rows%=rws%
- %*
- Wimp_MenuClose:
- setwindow:start%=
- clock:
- minesleft
- Event_KeyPress(window%,icon%,key%)
- window%
- not needed anymore (see comments about mask% in Wimp file)
- WHEN high_Window% : PROCUser_KeyPresshigh(icon%,key%)
- User_KeyPresshigh(icon%,key%)
- icon%=17
- key%
- 7!
- 8,127 : yn$=
- yn$-1)
- 8#
- key%>64
- key%<123
- 9%
- : yn$+=
-
-
- Wimp_IconPutText(high_Window%,17,yn$)
- Event_MenuChoice(menu%)
- menu%
- Bar_Menu% :
- User_MenuChoiceBar
- main_Menu% :
- User_MenuChoicemain
- User_MenuChoiceBar
- Wimp_MenuChoice(0)
- 1 :
- info
- 2 : finished%=
- User_MenuChoicemain
- Wimp_MenuChoice(0)
- 1 :
- info
- 2 : ng%=
- Wimp_MenuChoice(1)
-
- ng%<4
- WV
- gr%<>0
- Wimp_MenuTick(size_Menu%,gr%)
- Wimp_MenuTick(size_Menu%,4)
- X6 gr%=ng%:
- Wimp_MenuTick(size_Menu%,gr%)
-
- gr%
- Z>
- 1 : mines%=35:rows%=maxrows%:cols%=maxcols%
- [2
- 2 : mines%=25:rows%=12:cols%=12
- \2
- 3 : mines%=17:rows%=10:cols%=10
-
- ^.
- Wimp_MenuEnable(main_Menu%,4)
- _I
- checkscores(1000,0):
- Wimp_WindowBringToTop(high_Window%)
- `: s%=1:
- setwindow:start%=
- clock:
- minesleft
-
- 3 :
- setwindow:start%=
- c
- clock:
- minesleft
- 4 :
- Wimp_WindowBringToTop(high_Window%)
- 5 : finished%=
- Event_LoadFile(file$,type$)
- Event_SaveFile(file$,window%)
- clock
- done%
- ):t$=
- t$-2)
- m$=2
- (s$)
- 1 : ten$="0"
- unit$=s$
- 2 : ten$=
- s$,1)
- unit$=
- s$,1)
- m$<>oldm$
- Wimp_IconPutText(main_Window%,203,"digi_"+m$)
- ten$<>oldten$
- Wimp_IconPutText(main_Window%,204,"digi_"+ten$)
- Wimp_IconPutText(main_Window%,205,"digi_"+unit$)
- colon%=1-colon%
- colon%
- 0 :
- Wimp_IconPutText(main_Window%,206,"digi_")
- 1 :
- Wimp_IconPutText(main_Window%,206,"digi_:")
- oldm$=m$:oldten$=ten$
- minesleft
- lf$=
- left%
- 1 : mhun$="0":mten$="0":munit$=lf$
- 2 : mhun$="0"
- + mten$=
- lf$,1):munit$=
- lf$,1)
- 3 : mhun$=
- lf$,1)
- mten$=
- lf$,2,1)
- munit$=
- lf$,1)
- Wimp_IconPutText(main_Window%,198,"digi_"+mhun$)
- Wimp_IconPutText(main_Window%,199,"digi_"+mten$)
- Wimp_IconPutText(main_Window%,200,"digi_"+munit$)
- loadhiscores
- # F%=
- ("<Scores6$Dir>.MSscores")
- F%=0
- createfile:
- g%=0
- g%+=1:n%=0
- n%+=1
- #F%,names$(n%,g%),scores%(n%,g%)
- n%=5
- g%=3
- #F%,yn$
- checkscores(1000,0)
- savehiscores
- # F%=
- ("<Scores6$Dir>.MSscores")
- g%=0
- g%+=1:n%=0
- n%+=1
- #F%,names$(n%,g%),scores%(n%,g%)
- n%=5
- g%=3
- #F%,yn$
- new%
- ("SetType <MineData$Dir>.HiScores Data"):new%=
- createfile
- talk("Creating new hiscore file")
- names$()="Keith Drakard"
- scores%()=599
- yn$="Keith Drakard":new%=
- savehiscores
- checkscores(1000,0)
- checkscores(time%,s%)
- time%=1000
- Wimp_IconPutText(high_Window%,17,yn$)
- yn$=
- Wimp_IconText(high_Window%,17)
- n%=0:nm$=yn$
- n%+=1
- time%<=scores%(n%,gr%)
- time%,scores%(n%,gr%):
- nm$,names$(n%,gr%):s%=1
- n%=5
- n%=0
- n%+=1
- Wimp_IconPutText(high_Window%,5+n%,names$(n%,gr%))
- ! ss$=
- (scores%(n%,gr%)
- ss$=1
- ss$="0"+ss$
- IF (VALss$ MOD 10)=0 THEN ss$+="0"
- ) sc$=
- (scores%(n%,gr%)
- 60)+":"+ss$
- Wimp_IconPutText(high_Window%,10+n%,sc$)
- n%=5
- s%=1
- savehiscores
- talk(mess$)
- ms%=
- line$="":k%=1
- l%=0:w$=""
- Wimp_IconPutText(talk_Window%,2,"")
- Wimp_WindowBringToTop(talk_Window%)
- ) l%=
- mess$," "):
- l%=0
- (mess$)
- w$=
- mess$,l%)
- mess$=
- mess$,
- (mess$)-l%)
- (line$+w$)<=34
- line$+=w$
- Wimp_IconPutText(talk_Window%,k%,line$)
- k%+=1:line$=w$
- mess$=""
- Wimp_IconPutText(talk_Window%,k%,line$)
- mess$=""
-