main.bend fails
raw source on the hub · import 0x3b876eed3a748ea7fba8a7834d3c610b/main.bend as Main
main.bend: Minesweeper in a window. ===================================
Build and run it:
bend main.bend -o minesweeper ./minesweeper
Left-click opens a square. Right-click flags one. Middle-click, or a
left-click on a number that already has all its flags, opens every
square around it at once. r deals a new board.
The status line is the window title, because the playfield fills the window: a 16x16 board of 32x32 tiles is exactly 512x512 pixels, and an Image is a quadtree over a square.
2 imports
import Base import ./game.bend as GM
Definitions
def Main.mix source · line 22 · raw
@bs:List<&2, U32> -> @acc:U32 -> U32
The seed comes from /dev/urandom, so each run lays a different board. If that file is not there, the game falls back to a fixed board.
def Main.seed.take source · line 29 · raw
@r:Result<&1, &1, Pair(U32, String), List<&2, U32>> -> U32
def Main.seed.close source · line 36 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), List<&2, U32>>) -> IO(U32)
def Main.seed.open source · line 44 · raw
@r:Result<&1, &1, Pair(U32, String), File> -> IO(U32)
def Main.seed source · line 52 · raw
IO(U32)
def Main.turn.go source · line 60 · raw
@pair:Pair(0x3b876eed3a748ea7fba8a7834d3c610b/game.Game, Bool) -> @w:Window -> @rest:(@_:Window -> @_:Bool -> @_:0x3b876eed3a748ea7fba8a7834d3c610b/game.Game -> IO(Unit)) -> IO(Unit)
One frame: drop the image the window handed back, fold this frame's
events into the state, refresh the title, and hand the loop on.
rest is a closure, not a name, because two functions may not call
each other in Bend.
def Main.turn source · line 71 · raw
@shown:Pair(Window, Pair(Image, List<&1, Event>)) -> @g:0x3b876eed3a748ea7fba8a7834d3c610b/game.Game -> @rest:(@_:Window -> @_:Bool -> @_:0x3b876eed3a748ea7fba8a7834d3c610b/game.Game -> IO(Unit)) -> IO(Unit)
def Main.loop source · line 81 · raw
@fuel:Nat -> @alive:Bool -> @w:Window -> @g:0x3b876eed3a748ea7fba8a7834d3c610b/game.Game -> IO(Unit)
def main source · line 93 · raw
IO(Unit)