Skip to content

Component Game Boardλ︎

Now we have experiment with the board design, lets put our results into a component.

(defn game-board
  "Create a data structure to represent the values of cells in the game board.
  A vector is used to hold the overall game board
  Each nested vector represents a line of the game board.
  Dimension specifies the size of the game board."
  (vec (repeat dimension (vec (repeat dimension :empty)))))

Lets create a default dimension for the board (width & height)

As the game board is square, we only use one value for height and width

(def board-dimension 3)

Update the app-state so that it doesn't get over-written on reload

(defonce app-state
               {:title "Lets Play TicTacToe"
                :message "Do you want to play a game?"}
                (game-board board-dimension)}))