Functional Web Development with Elixir, OTP, and Phoenix: Rethink the Modern Web App by Lance Halvorsen

Functional Web Development with Elixir, OTP, and Phoenix: Rethink the Modern Web App by Lance Halvorsen

Author:Lance Halvorsen [Halvorsen, Lance]
Language: eng
Format: epub, pdf
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf
Published: 2018-01-25T00:00:00+00:00


iex> state_data = :sys.replace_state(game, fn data ->

...> %{state_data | rules: %Rules{state: :player1_turn}}

...> end)

. . .

iex> state_data.rules.state

:player1_turn

Let’s have :player1 guess a wrong coordinate. The response we get should be {:miss, :none, :no_win}:

iex> Game.guess_coordinate(game, :player1, 5, 5)

{:miss, :none, :no_win}

That’s perfect.

If :player1 tries to guess again, the rules should catch that and return :error:

iex> Game.guess_coordinate(game, :player1, 3, 1)

:error

Excellent! That was just what we expected.

If :player2 guesses the single coordinate in :dot island, he should win the game:

iex> Game.guess_coordinate(game, :player2, 1, 1)

{:hit, :dot, :win}

That’s exactly what happens.

With that, we’ve defined the interface and all the behavior we’ll need from the Game module. The last thing we’ll need is to be able to address each game process by name in the system.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.