programgames/minesweeper/play.xtl

source · imports m: games/minesweeper/Mines.xtl; p: lib/Play.xtl

said : Char

value · line 8
said ← p̲rint! "MINESWEEPER: 9 BY 9, 10 MINES"

ᵘa̲sk : Any a => a -> Int

function · line 12

A command: f (flag) or not, then a row and a column from 1 to 9; anything else is asked for again.

ᵘa̲sk ← { s →
  line ← ᵖl̲ine "OPEN ROW COL, OR F ROW COL ?"
  v ← ᵖn̲umbersIn line
  ok ← (2 = t̲ally v) ∧ '∧ r̲/ (v ≥ 1) ∧ v ≤ 9
  ok ? (('∨ r̲/ line m̲ember? "fF") c̲at v)◆ ᵘa̲sk s
}

ᵘt̲urn : Int -> Char

function · line 19

A turn: the field (as text and as a picture), a command, its result.

ᵘt̲urn ← { s →
  said ← p̲rint! ""
  shown ← p̲rint! ᵐv̲iew s
  pic ← ⎕S̲HOW ᵐp̲icture s
  1 = ᵐs̲tatus s ? "YOU CLEARED THE FIELD!"
  2 = ᵐs̲tatus s ? "BOOM! YOU HIT A MINE."
  c ← ᵘa̲sk s
  1 = f̲irst c ? ᵘt̲urn s ᵐf̲lag 1 d̲rop c◆ ᵘt̲urn s ᵐr̲eveal 1 d̲rop c
}