Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _ms_h = 9 // board height
- _ms_w = 9 // board width
- _ms_m = 10 // board mines
- _ms_th = 9 // temp H
- _ms_tw = 9 // temp W
- _ms_tm = 10 // temp M
- _ms_tu = 1 // temp U
- _ms_fc = 0 // placed flags counter
- _ms_hc = 0 // hit mines counter
- _ms_bt = 0 // board tiles (total)
- _ms_t1 = 0 // timer start (ms)
- _ms_t2 = 0 // timer end (ms)
- _ms_ua = 1 // undo toggle
- _ms_u = 0 // undo counter
- _ms_pc = 0 // completion percentage
- _ms_gm = 0 // game mode: 0 waiting; 1 active; 2 failure ; 3 victory
- _ms_mf = "" // board containing mine placement
- _ms_nf = "" // board containing tile numbers
- _ms_cf = "" // board of completion (displayed)
- _ms_mp = "" // supplementary list with mine positions
- _ms_hp = "" // supplementary list with hit mine positions
- _ms_fp = "" // supplementary list with flag positions
- _ms_tq = "" // supplementary list with tile reveal queue
- // ----------------------------------------- //
- // ---------------- Tile ID ---------------- //
- // ----------------------------------------- //
- // 0 = blank tile
- // 1-8 = number tiles
- // H = hidden tile
- // X = mine tile (failure)
- // HX = mine tile (victory)
- // R = hit mine tile
- // F = flagged tile
- // FX = flagged mine tile (success)
- // FF = flagged mine tile (failure)
- append = [ $arg1 = (concat (getalias $arg1) $arg2) ]
- _ms_clock = [
- local n
- n = (mod $arg1 1000)
- format "%1:%2%3" (div $arg1 1000) (? (< $n 100) (? (< $n 10) "00" "0")) $n
- ]
- _ms_set_options = [
- local n
- n = (* $_ms_th $_ms_tw)
- // calculate board sizes/mines and apply limits
- if $arg1 [ _ms_th = (max (min $arg1 24) 9) ]
- if $arg2 [ _ms_tw = (max (min $arg2 30) 9) ]
- _ms_tm = (max (min (div $n 3) $_ms_tm) (div $n 10))
- ]
- _ms_set_markers = [
- // in case of failure, update flag markers
- if (= $_ms_gm 2) [
- looplist i $_ms_fp [
- if (=s (at $_ms_nf $i) "X") [
- _ms_tile_open "FX" $i 0
- ] [ _ms_tile_open "FF" $i 0 ]
- ]
- ]
- // update mine markers, discounting flagged ones
- looplist i $_ms_mp [
- case $_ms_gm 2 [
- if (< (indexof "R FX FF" (at $_ms_cf $i)) 0) [
- _ms_tile_open "X" $i 0
- ]
- ] 3 [
- if (< (indexof "R F" (at $_ms_cf $i)) 0) [
- _ms_tile_open "HX" $i 0
- ]
- ]
- ]
- ]
- _ms_tile_open = [
- // start the game if still in waiting phase
- if (= $_ms_gm 0) [
- _ms_gm = 1
- _ms_t1 = (getmillis)
- ]
- // reveal # tile at given position and add to completion counter if needed
- _ms_cf = (listsplice $_ms_cf $arg1 $arg2 1)
- if $arg3 [ _ms_pc = (+ $_ms_pc 1) ]
- ]
- _ms_tile_find = [
- local n c1 c2 c3 c4 c5 c6 c7 c8
- n = 0
- c1 = (- $arg9 $_ms_w) // UP
- c2 = (+ $arg9 $_ms_w) // DN
- c3 = (- $arg9 1) // LT
- c4 = (+ $arg9 1) // RT
- c5 = (- $arg9 (+ $_ms_w 1)) // UP-LT
- c6 = (- $arg9 (- $_ms_w 1)) // UP-RT
- c7 = (+ $arg9 (- $_ms_w 1)) // DN-LT
- c8 = (+ $arg9 (+ $_ms_w 1)) // DN-RT
- if (> $c1 -1) $arg1 // UP
- if (< $c2 $_ms_bt) $arg2 // DN
- if (> (mod $arg9 $_ms_w) 0) $arg3 // LT
- if (< (mod $arg9 $_ms_w) (- $_ms_w 1)) $arg4 // RT
- if (&& [> $c5 -1] [> (mod $arg9 $_ms_w) 0]) $arg5 // UP-LT
- if (&& [> $c6 -1] [< (mod $arg9 $_ms_w) (- $_ms_w 1)]) $arg6 // UP-RT
- if (&& [< $c7 $_ms_bt] [> (mod $arg9 $_ms_w) 0]) $arg7 // DN-LT
- if (&& [< $c8 $_ms_bt] [< (mod $arg9 $_ms_w) (- $_ms_w 1)]) $arg8 // DN-RT
- arg10
- ]
- _ms_tile_view = [
- local n t
- n = (at $_ms_nf $arg1)
- cases $n "X" [
- // mark the mine as hit
- _ms_tile_open "R" $arg1 0
- append _ms_hp $arg1
- _ms_hc = (+ $_ms_hc 1)
- // if lives are enabled, reduce by one, otherwise
- if (&& $_ms_ua $_ms_u) [ _ms_u = (- $_ms_u 1) ] [
- // game over, board is populated by hit and undiscovered mines and flag marks
- _ms_gm = 2
- _ms_t2 = (getmillis)
- _ms_set_markers
- ]
- ] "0" [
- _ms_tile_open "0" $arg1 1
- append _ms_tq $arg1
- // explore all surrounding tiles until number border
- while [listlen $_ms_tq] [
- do [ _ms_tile_find @(
- loopconcat i 8 [result [[
- n = $c@@(+ $i 1)
- // make sure the tile is not revealed, otherwise skip tile
- if (=s (at $_ms_cf $n) "H") [
- // ensure tile is blank and not in work queue, then add it
- if (&& [=s (at $_ms_nf $n) "0"] [< (indexof $_ms_tq $n) 0]) [
- append _ms_tq $n
- ]
- // reveal the tile around the blank tile and add to completion percentage
- _ms_tile_open (at $_ms_nf $n) $n 1
- ]
- ]]]
- ) (at $_ms_tq 0) ]
- // remove used tile from work queue
- _ms_tq = (sublist $_ms_tq 1)
- ]
- ] () [ _ms_tile_open $n $arg1 1 ]
- // in case of board completion, victory
- if (= $_ms_pc (- $_ms_bt $_ms_m)) [
- _ms_gm = 3 ; _ms_t2 = (getmillis)
- _ms_set_markers
- ]
- ]
- _ms_make_board = [
- local i n r
- i = 0
- // initialise board variables
- _ms_th = $arg1
- _ms_tw = $arg2
- _ms_m = $arg3
- _ms_h = $_ms_th
- _ms_w = $_ms_tw
- _ms_tm = $_ms_m
- // initialise game variables
- _ms_ua = $_ms_tu
- if $_ms_ua [ _ms_u = (+ (div $_ms_m 20) 1) ]
- _ms_bt = (* $_ms_h $_ms_w)
- _ms_pc = 0
- _ms_t1 = 0
- _ms_t2 = 0
- _ms_gm = 0
- _ms_hc = 0
- _ms_fc = 0
- // initialise boards
- _ms_nf = ""
- _ms_mf = (loopconcat i $_ms_bt [result "0"])
- _ms_cf = (loopconcat i $_ms_bt [result "H"])
- // initialise supplementary lists
- _ms_tq = ""
- _ms_mp = ""
- _ms_hp = ""
- _ms_fp = ""
- // generate the mines board
- while [< $i $_ms_m] [
- r = (rnd $_ms_bt)
- // avoid writing to a previously picked spot
- if (! (at $_ms_mf $r)) [
- _ms_mf = (listsplice $_ms_mf "1" $r 1)
- append _ms_mp $r
- i = (+ $i 1)
- ]
- ]
- // generate the numbers board
- loop y $_ms_bt [
- if (at $_ms_mf $y) [ append _ms_nf "X" ] [
- do [ _ms_tile_find @(
- loopconcat i 8 [result [[
- n = (+ (at $_ms_mf $c@@(+ $i 1)) $n)
- ]]]
- ) $y [ append _ms_nf $n ] ]
- ]
- ]
- ]
- a = [exec scripts/minesweeper.cfg; showui minesweeper]
- _ms_ui_diff = [
- uimodcolor 0xEEEEEE 0.22 0.03 [
- uialign 0 1
- uihold [ uimodvgradient $arg3 $arg2 ] [
- uialthold [ uimodvgradient $arg3 $arg2 ] [
- uihover [ uimodvgradient $arg2 $arg3 ]
- ]
- ]
- uirelease [ arg4 ]
- uioutline 0x181818
- uiclamp* 1 1 1 1
- uispace 0.01 0.002 [
- uitext $arg1 0.6
- ]
- ]
- ]
- newui minesweeper [
- uicolor 0x60444444 0 0 [
- uioutline 0x181818 0 0 [ uiclamp 1 1 1 1 ]
- uispace 0.005 0.005 [
- uihlist 0.01 [
- uivlist 0 [
- uihlist 0 [
- uiclamp 1 1 0 0
- uispace 0.015 0.002 [
- uialign -1 0
- uihlist 0.01 [
- uiimage "media/texture/minesweeper/globe.png" 0.04 0.04
- uitext (format "^f%1%2%%" (case $_ms_gm 2 3 3 0 () 7) (
- absf (precf (*f (divf $_ms_pc (- $_ms_bt $_ms_m)) 100) 1))
- ) 0.8
- ]
- ]
- uispace 0.015 0.002 [
- uialign 1 0
- uihlist 0.01 [
- uitext (_ms_clock (case $_ms_gm 0 0 1 (- $getmillis $_ms_t1) () (- $_ms_t2 $_ms_t1))) 0.8
- uiimage "media/texture/minesweeper/clock.png" 0.04 0.04
- ]
- ]
- ]
- loop y $_ms_h [
- uihlist 0 [
- loop x $_ms_w [
- n = (+ (* $y $_ms_w) $x)
- uiimage (format "media/texture/minesweeper/tiles/%1.png" (at $_ms_cf $n)) 0.045 0.045 [
- if (&& [< $_ms_gm 2] [|| [=s (at $_ms_cf $n) "H"] [=s (at $_ms_cf $n) "F"]]) [
- uihover [ uimodvgradient 0xCCCCCC 0xBBBBBB ]
- uihold [ uimodvgradient 0xCCCCCC 0xEEEEEE ] [
- uialthold [ uimodvgradient 0xEEEEEE 0xDDDDDD ]
- ]
- if (=s (at $_ms_cf $n) "H") [
- uirelease [ _ms_tile_view $n ]
- ]
- uialtrelease [
- cases (at $_ms_cf $n) "H" [
- _ms_tile_open "F" $n 0
- append _ms_fp $n
- _ms_fc = (+ $_ms_fc 1)
- ] "F" [
- _ms_tile_open "H" $n 0
- _ms_fp = (listdel $_ms_fp $n)
- _ms_fc = (- $_ms_fc 1)
- ]
- ]
- uiclamp* 1 1 1 1
- ]
- ]
- ]
- ]
- ]
- ]
- uioutline 0x181818 0 0 [ uiclamp 1 1 1 1 ]
- uivlist 0 [
- uiclamp 0 0 1 1
- uivlist 0.03 [
- uimodcolor (? (> $_ms_gm 1) 0xCCFFCC 0xEEEEEE) 0.22 0 [
- uialign 0 -1
- uihold [ uimodvgradient 0xCCCCCC 0xFFFFFF ] [
- uialthold [ uimodvgradient 0xCCCCCC 0xFFFFFF ] [
- uihover [ uimodvgradient 0xFFFFFF 0xCCCCCC ]
- ]
- ]
- uirelease [ _ms_make_board $_ms_th $_ms_tw $_ms_tm ]
- uioutline 0x181818
- uiclamp* 1 1 1 1
- uispace 0.01 0.002 [
- uihlist 0.01 [
- uialign 0 0
- uiimage "media/texture/minesweeper/new.png" 0.04 0.04
- uitext "New Game" 0.8
- ]
- ]
- ]
- uihlist 0 [
- uialign -1 -1
- uispace 0.01 0.002 [
- uihlist 0.01 [
- uialign 0 0
- uiimage "media/texture/minesweeper/life.png" 0.04 0.04
- uitext (concatword (? $_ms_u "^f7" "^f3") (? $_ms_ua $_ms_u 0)) 0.8
- ]
- ]
- uispace 0.01 0.002 [
- uihlist 0.01 [
- uialign 0 0
- uiimage "media/texture/minesweeper/flag.png" 0.04 0.04
- uitext (- (- $_ms_m $_ms_fc) $_ms_hc) 0.8
- ]
- ]
- ]
- ]
- uivlist 0.02 [
- uihlist 0 [
- uialign -1 -1
- uivlist 0 [
- uispace 0.01 0.002 [
- uihlist 0.01 [
- uialign 0 0
- uiimage "media/texture/minesweeper/height.png" 0.03 0.03
- uimodcolor 0xEEEEEE 0 0 [
- uihover [ uimodvgradient 0xFFFFFF 0xCCCCCC ]
- uiclamp- 1 1 1 1
- uifield _ms_th 2 [ _ms_set_options $_ms_th 0 ] 0.6 [
- uioutline 0x181818
- uiclamp- 1 1 1 1
- ]
- ]
- ]
- ]
- uispace 0.01 0.002 [
- uihlist 0.01 [
- uialign 0 0
- uiimage "media/texture/minesweeper/width.png" 0.03 0.03
- uimodcolor 0xEEEEEE 0 0 [
- uihover [ uimodvgradient 0xFFFFFF 0xCCCCCC ]
- uiclamp- 1 1 1 1
- uifield _ms_tw 2 [ _ms_set_options 0 $_ms_tw ] 0.6 [
- uioutline 0x181818
- uiclamp- 1 1 1 1
- ]
- ]
- ]
- ]
- ]
- uispace 0 0.002 [
- uivlist 0.004 [
- uialign 0 0
- uiimage "media/texture/minesweeper/mine.png" 0.03 0.03
- uimodcolor 0xEEEEEE 0 0 [
- uihover [ uimodvgradient 0xFFFFFF 0xCCCCCC ]
- uiclamp- 1 1 1 1
- uifield _ms_tm 3 [ _ms_set_options 0 0 ] 0.6 [
- uioutline 0x181818
- uiclamp- 1 1 1 1
- ]
- ]
- ]
- ]
- ]
- uitext "Difficulty" 0.8
- uivlist 0.003 [
- uialign 0 1
- _ms_ui_diff "Easy" 0x4DFF00 0x279900 [ _ms_make_board 9 9 10 ]
- _ms_ui_diff "Normal" 0xFFD800 0x997400 [ _ms_make_board 16 16 40 ]
- _ms_ui_diff "Hard" 0xFF2010 0x991008 [ _ms_make_board 16 30 80 ]
- uispace 0 0.005
- uimodcolor 0xEEEEEE 0.22 0.03 [
- uialign 0 -1
- uihold [ uimodvgradient 0xCCCCCC 0xFFFFFF ] [
- uialthold [ uimodvgradient 0xCCCCCC 0xFFFFFF ] [
- uihover [ uimodvgradient 0xFFFFFF 0xCCCCCC ]
- ]
- ]
- uirelease [
- _ms_tu = (! $_ms_tu)
- if (! $_ms_gm) [ _ms_ua = $_ms_tu ]
- ]
- uioutline 0x181818
- uiclamp* 1 1 1 1
- uispace 0.01 0.002 [
- uihlist 0.01 [
- uialign 0 0
- uiimage (concatword "media/texture/minesweeper/check_" (
- case (+ $_ms_tu $_ms_ua) 0 [ result "off" ] 1 [ result "sel" ] 2 [ result "on" ]
- ) ".png") 0.025 0.025
- uitext "Use Lives" 0.6
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ] [ _ms_make_board $_ms_th $_ms_tw $_ms_tm ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement