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.
--- a/src/rps.erl Thu Mar 06 19:39:46 2014 +0900
+++ b/src/rps.erl Sat Mar 08 15:36:49 2014 +0900
-define(BOTS, [fool, copycat, gambler]).
+-define(TIMETOJOIN, 10).
rps_nickserv:start_link(),
[spawn_link(rps_bots, Bot, []) || Bot <- ?BOTS].
+ lobby([], ?TIMETOJOIN).
-lobby(Players) when length(Players) =:= length(?BOTS) ->
Room = spawn_link(rps_room, room, [?RULES, Players]),
lists:foreach(fun(Player) -> Player ! {room, Room, ?RULES} end, Players),
+lobby(Players, Timeout) ->
+ Wait = case length(Players) of
+ lobby([Who|Players], Timeout)
+ io:format("~w players joined, waiting ~w", [length(Players), Timeout]),
+ lobby(Players, Timeout - 1)