minesweeper: code golfing.
parent
ffb42c913e
commit
61df87db07
|
@ -81,7 +81,7 @@ DEFER: click-cell-at
|
||||||
neighbors [
|
neighbors [
|
||||||
first2 [ row + ] [ col + ] bi* :> ( row' col' )
|
first2 [ row + ] [ col + ] bi* :> ( row' col' )
|
||||||
cells row' col' cell-at [
|
cells row' col' cell-at [
|
||||||
{ [ mined?>> ] [ state>> +flagged+ = ] } 1|| [
|
mined?>> [
|
||||||
cells row' col' click-cell-at drop
|
cells row' col' click-cell-at drop
|
||||||
] unless
|
] unless
|
||||||
] when*
|
] when*
|
||||||
|
@ -167,34 +167,31 @@ M: grid-gadget pref-dim*
|
||||||
[ "vocab:minesweeper/_resources/smiley.gif" ]
|
[ "vocab:minesweeper/_resources/smiley.gif" ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
: cached-texture ( path gadget -- texture )
|
: draw-cached-texture ( path gadget -- )
|
||||||
textures>> [ load-image { 0 0 } <texture> ] cache ;
|
textures>> [ load-image { 0 0 } <texture> ] cache
|
||||||
|
[ dim>> [ 2 /i ] map ] [ draw-scaled-texture ] bi ;
|
||||||
|
|
||||||
:: draw-mines ( n gadget -- )
|
:: draw-mines ( n gadget -- )
|
||||||
n "%03d" sprintf [
|
n "%03d" sprintf [
|
||||||
26 * 3 + 6 2array [
|
26 * 3 + 6 2array [
|
||||||
digit-image-path gadget cached-texture
|
digit-image-path gadget draw-cached-texture
|
||||||
{ 26 46 } swap draw-scaled-texture
|
|
||||||
] with-translation
|
] with-translation
|
||||||
] each-index ;
|
] each-index ;
|
||||||
|
|
||||||
:: draw-smiley ( gadget -- )
|
:: draw-smiley ( gadget -- )
|
||||||
gadget pref-dim first :> width
|
gadget pref-dim first :> width
|
||||||
width 2/ 26 - 3 2array [
|
width 2/ 26 - 3 2array [
|
||||||
gadget cells>> won?
|
gadget cells>> [ won? ] [ lost? ] bi
|
||||||
gadget cells>> lost?
|
|
||||||
hand-buttons get-global empty? not
|
hand-buttons get-global empty? not
|
||||||
gadget hand-click-rel second 58 >= and
|
gadget hand-click-rel second 58 >= and
|
||||||
smiley-image-path
|
smiley-image-path gadget draw-cached-texture
|
||||||
gadget cached-texture { 52 52 } swap draw-scaled-texture
|
|
||||||
] with-translation ;
|
] with-translation ;
|
||||||
|
|
||||||
:: draw-timer ( n gadget -- )
|
:: draw-timer ( n gadget -- )
|
||||||
gadget pref-dim first :> width
|
gadget pref-dim first :> width
|
||||||
n "%03d" sprintf [
|
n "%03d" sprintf [
|
||||||
3 swap - 26 * width swap - 3 - 6 2array [
|
3 swap - 26 * width swap - 3 - 6 2array [
|
||||||
digit-image-path gadget cached-texture
|
digit-image-path gadget draw-cached-texture
|
||||||
{ 26 46 } swap draw-scaled-texture
|
|
||||||
] with-translation
|
] with-translation
|
||||||
] each-index ;
|
] each-index ;
|
||||||
|
|
||||||
|
@ -203,8 +200,7 @@ M: grid-gadget pref-dim*
|
||||||
gadget cells>> [| row col cell |
|
gadget cells>> [| row col cell |
|
||||||
col row [ 32 * ] bi@ 58 + 2array [
|
col row [ 32 * ] bi@ 58 + 2array [
|
||||||
cell game-over? cell-image-path
|
cell game-over? cell-image-path
|
||||||
gadget cached-texture
|
gadget draw-cached-texture
|
||||||
{ 32 32 } swap draw-scaled-texture
|
|
||||||
] with-translation
|
] with-translation
|
||||||
] each-cell ;
|
] each-cell ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue