File tree 3 files changed +22
-6
lines changed
3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 1
1
# Tetris
2
2
3
- To start your new Phoenix application :
3
+ To start tetris :
4
4
5
5
1 . Install dependencies with ` mix deps.get `
6
- 2 . Start Phoenix endpoint with ` mix phoenix.server `
6
+ 2 . Start Phoenix endpoint with ` mix phoenix.server ` or interactively with `iex
7
+ -S mix phoenix.server`
7
8
8
9
Now you can visit ` localhost:4000 ` from your browser.
10
+
11
+ To start a new game, from iex:
12
+
13
+ ``` elixir
14
+ Tetris .restart_game
15
+ ```
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ defmodule Tetris do
18
18
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
19
19
# for other strategies and supported options
20
20
opts = [ strategy: :one_for_one , name: Tetris.Supervisor ]
21
+ start_game
21
22
Supervisor . start_link ( children , opts )
22
23
end
23
24
@@ -27,4 +28,14 @@ defmodule Tetris do
27
28
Tetris.Endpoint . config_change ( changed , removed )
28
29
:ok
29
30
end
31
+
32
+ def restart_game do
33
+ Process . unregister ( :game )
34
+ start_game
35
+ end
36
+
37
+ def start_game do
38
+ { :ok , game } = Tetris.Game . start
39
+ Process . register ( game , :game )
40
+ end
30
41
end
Original file line number Diff line number Diff line change @@ -8,14 +8,12 @@ defmodule Tetris.GameChannel do
8
8
9
9
def handle_in ( "event" , % { "event" => event_name } , socket ) do
10
10
# NOTE: Don't use String.to_atom like this folks
11
- Tetris.Game . handle_input ( socket . assigns [ :game ] , String . to_atom ( event_name ) )
11
+ Tetris.Game . handle_input ( :game , String . to_atom ( event_name ) )
12
12
{ :noreply , socket }
13
13
end
14
14
15
15
def handle_info ( :after_join , socket ) do
16
- { :ok , game } = Tetris.Game . start
17
- spawn ( fn ( ) -> Tetris.Websocket . run ( game , socket ) end )
18
- socket = assign ( socket , :game , game )
16
+ spawn ( fn ( ) -> Tetris.Websocket . run ( :game , socket ) end )
19
17
{ :noreply , socket }
20
18
end
21
19
end
You can’t perform that action at this time.
0 commit comments