public async Task <Game> JoinAsync(Game passedGame) { await _repository.AddOrUpdatePlayerGameAsync(_playerIdentity.Id, Player.Game.From(_playerIdentity.Id, passedGame)); if (passedGame.MaxPlayers == passedGame.Players.Count) { var playerOrders = _uniqueRandomRangeCreator.CreateArrayWithAllNumbersFromRange(passedGame.Players.Count); var game = await _repository.StartGameAsync(passedGame.Id !, playerOrders); if (game != null) { foreach (var player in game.Players) { await _repository.AddOrUpdatePlayerGameAsync(player.Id, Player.Game.From(player.Id, game)); } await _gameHub.GameStartedAsync(game); return(game); } } else { await _gameHub.PlayerAddedAsync(passedGame); } return(passedGame); }
private IEnumerable <UniqueRandomRange> GenerateUniqueRandomRangesToCache(int rangeMinToGenerate, int rangeMaxToGenerate) { for (var rangeMax = rangeMinToGenerate; rangeMax < rangeMaxToGenerate; rangeMax++) { for (var trial = 0; trial < rangeMax * 2; trial++) { var values = _rangeCreator.CreateArrayWithAllNumbersFromRange(rangeMax); yield return(new UniqueRandomRange(rangeMax, values)); } } }