With the player model, we try to make the player process run.
A playersupervisor is required to initiate and monitor the player process.
defmodule playersupervisor do and Supervisor def Start_link (_opts) do Supervisor.start_link (__module____module__) end def Init (: OK) do supervisor.init ([Playerserver], strategy:: Simple_one_for_one) end def start_player (player) do supervisor.start_child (__module__, [player]) EndEnd
Player_supervisor.ex
Get a playerserver to take charge of the player process.
defmodule playerserver do use genserver, restart:: temporary, start: {__module__,: Start_ Link, []} def Start_link (player) do Genserver.start_link (__module____ module__) end def Init (player) do {: OK, player} endend
Player_server.ex
Test code for Plyaer_supervisor
defmodule playersupervisortest do and exunit.case doctest playersupervisor setup do Start_ Supervised playersupervisor %{} end " test playersupervisor start Playerserver "Doassert {: OK, _player_pid} = playersupervisor.start_player ( Player.init) EndEnd
Player_supervisor_test.exs
In the next chapter, we will solve the player process registration problem (now only 1 players), if only a single service can be used with elixir registry.
Cross-serve words with SYN or GPROC.
Because it's just for demonstration (work easy), I'll use registry.
At the same time Game_server is the time to modify the app to launch.
Simple Elixir Game Suit design-player process run up