O'Reilly logo

Functional Web Development with Elixir, OTP, and Phoenix by Lance Halvorsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required