Putting the Pieces Together
A player’s own board acts as an interface. It’s the front door to the data and functions that make up the game. Now that we’ve completely defined the Board module, we’re ready to see how all of the work we’ve done so far fits together.
Let’s start a new session with iex -S mix, and alias the Board, Coordinate, and Island modules:
| iex> alias IslandsEngine.{Board, Coordinate, Island} |
| [IslandsEngine.Board, IslandsEngine.Coordinate, IslandsEngine.Island] |
Then we can generate a new board:
| iex> board = Board.new() |
| %{} |
Now let’s generate a new square island and position it on the board:
| iex> {:ok, square_coordinate} = Coordinate.new(1, 1) |
| {:ok, %IslandsEngine.Coordinate{col: ... |
Get Functional Web Development with Elixir, OTP, and Phoenix now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.