/*public void StartGame() * { * this.gameTask = Task.Factory.StartNew(() => * { * this.State = States.Running; * try * { * Debug.Print("Start Game"); * * var gameData = GameInitializationDataBuilder.Build(this.gameManager.Board); * foreach (var client in this.clients) * { * client.InitializeGame(gameData); * } * * // Clients confirming that they have completed game initialization. * var awaitingGameInitializationConfirmation = new HashSet<IServiceProviderCallback>(this.clients); * GameSessionMessage message = null; * while (awaitingGameInitializationConfirmation.Count > 0) * { * this.cancellationToken.ThrowIfCancellationRequested(); * * if (this.messagePump.TryDequeue(GameSessionMessage.Types.ConfirmGameInitialized, out message)) * { * awaitingGameInitializationConfirmation.Remove(message.Client); * Debug.Print("Received: " + awaitingGameInitializationConfirmation.Count + " left."); * continue; * } * * Thread.Sleep(50); * } * * // Clients have all confirmed they received game initialization data * // Now ask each client to place a town in dice roll order. * this.PlaceTownsInFirstPassOrder(this.gameManager.GetFirstSetupPassOrder()); * * // Do second pass of setup * this.PlaceTownsInSecondPassOrder(); * } * catch (OperationCanceledException) * { * // Shutting down - ignore exception * this.State = States.Stopping; * } * finally * { * this.State = States.Stopped; * } * }); * }*/ private Boolean AddPlayer(IClientCallback client, String username) { for (var i = 0; i < this.clients.Length; i++) { if (this.clients[i] != null) { continue; } this.clients[i] = client; client.ConfirmGameSessionJoined(this.GameSessionToken, GameStates.Lobby); var playerCard = this.playerCardRepository.GetPlayerData(username); this.currentPlayerCount++; if (this.currentPlayerCount > 1) { this.SendPlayerDataToPlayers(i, client, playerCard); } this.playerCards.Add(client, playerCard); return(this.currentPlayerCount == this.clients.Length); } return(true); }