Download:
child 46:1514111fb94a
parent 44:8d400faca258
45:0bbe9c057774
Anton Shestakov <engored@ya.ru>, Sat, 08 Mar 2014 15:36:49 +0900
Now lobby waits for other players to join or starts without them. Before it waited for a fixed number of players.

1 файлов изменено, 14 вставок(+), 5 удалений(-) [+]
src/rps.erl file | annotate | diff | comparison | revisions
--- a/src/rps.erl Thu Mar 06 19:39:46 2014 +0900
+++ b/src/rps.erl Sat Mar 08 15:36:49 2014 +0900
@@ -5,6 +5,7 @@
-define(BOTS, [fool, copycat, gambler]).
-define(RULES, rps5).
+-define(TIMETOJOIN, 10).
go() ->
rps_nickserv:start_link(),
@@ -16,17 +17,25 @@
[spawn_link(rps_bots, Bot, []) || Bot <- ?BOTS].
lobby() ->
- lobby([]).
+ lobby([], ?TIMETOJOIN).
-lobby(Players) when length(Players) =:= length(?BOTS) ->
+lobby(Players, 0) ->
Room = spawn_link(rps_room, room, [?RULES, Players]),
lists:foreach(fun(Player) -> Player ! {room, Room, ?RULES} end, Players),
- lobby([]);
+ lobby();
-lobby(Players) ->
+lobby(Players, Timeout) ->
+ Wait = case length(Players) of
+ 0 -> infinity;
+ _ -> 1000
+ end,
receive
{join, Who} ->
- lobby([Who|Players])
+ lobby([Who|Players], Timeout)
+ after
+ Wait ->
+ io:format("~w players joined, waiting ~w", [length(Players), Timeout]),
+ lobby(Players, Timeout - 1)
end.
counter() ->