コード例 #1
0
        public void AddPlayer(TriviaPlayer player)
        {
            _players.Enqueue(player);

            if (_players.Count >= PlayersPerGame)
            {
                var readyPlayers = new List<TriviaPlayer>();

                lock (_gameStartLock)
                {
                    for (int i = 0; i < PlayersPerGame; i++)
                    {
                        _players.TryDequeue(out var readyPlayer);
                        readyPlayers.Add(readyPlayer);
                    }
                }

                var game = new TriviaGame(readyPlayers, _loggerFactory);
                Games[game.ID] = game;

                foreach (var readyPlayer in readyPlayers)
                {
                    readyPlayer.StartGame(game);
                }

                Task.Run(() => game.PlayGameAsync());
            }
        }
コード例 #2
0
ファイル: TriviaPlayer.cs プロジェクト: shirhatti/Trivia
 public void StartGame(TriviaGame game)
 {
     Game = game;
     _readyTcs.SetResult(null);
 }