2 people like it.

Minesweeper Kata 2

Solution to Minesweeper Kata second challenge at Goto Copenhagen 2012 conference "Programming with the Stars" track. Runnable at http://tryfsharp.org.

Show minesweeper board

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
type GameControl() =
  inherit UserControl(Width = 300.0, Height = 400.0)
  let board = Game.view
  let grid = Grid()  
  do  board |> Array.iteri (fun y line ->
        grid.RowDefinitions.Add(RowDefinition())
        if y = 0 then
            for i = 1 to line.Length do
                grid.ColumnDefinitions.Add(ColumnDefinition())
        line.ToCharArray() |> Array.iteri (fun x c ->
            let button = Button()
            button.Content <- c.ToString()
            Grid.SetColumn(button,x)
            Grid.SetRow(button,y)
            grid.Children.Add button
        )
      )
  do  base.Content <- grid
Multiple items
type GameControl =
  inherit obj
  new : unit -> GameControl

Full name: Script.GameControl

--------------------
new : unit -> GameControl
module Game

from Script
val view : string []

Full name: Script.Game.view
type Array =
  member Clone : unit -> obj
  member CopyTo : array:Array * index:int -> unit + 1 overload
  member GetEnumerator : unit -> IEnumerator
  member GetLength : dimension:int -> int
  member GetLongLength : dimension:int -> int64
  member GetLowerBound : dimension:int -> int
  member GetUpperBound : dimension:int -> int
  member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
  member Initialize : unit -> unit
  member IsFixedSize : bool
  ...

Full name: System.Array
val iteri : action:(int -> 'T -> unit) -> array:'T [] -> unit

Full name: Microsoft.FSharp.Collections.Array.iteri
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/cc
Posted:12 years ago
Author:Phillip Trelford
Tags: kata , silverlight , game