Ejemplo n.º 1
0
        public Deck GenerateDeck(GameSessionConfiguration gameSessionConfiguration)
        {
            var cards = Enumerable.Range(0, gameSessionConfiguration.NumberOfCardsInDeck - 1)
                        .Select(v =>
                                new Card(
                                    v,
                                    v % gameSessionConfiguration.RedCardsFrequency == 0 &&
                                    v / gameSessionConfiguration.RedCardsFrequency != 0 &&
                                    v / gameSessionConfiguration.RedCardsFrequency != gameSessionConfiguration.NumberOfCardsInDeck / gameSessionConfiguration.RedCardsFrequency))
                        .OrderBy(r => random.Next(0, 1000));

            return(new Deck(new Stack <Card>(cards), DeckType.Random));
        }
Ejemplo n.º 2
0
        public async Task <GameSession> CreateGameSessionAsync(
            Player organizer,
            GameSessionConfiguration configuration)
        {
            try
            {
                await semaphoreSlim.WaitAsync();

                var code       = GenerateGameSessionCode();
                var emptyDecks = Enumerable.Range(1, configuration.NumberOfDecks)
                                 .Select(n => new Deck(new Stack <Card>(), n % 2 == 0 ? DeckType.Ascending : DeckType.Descending))
                                 .OrderBy(d => d.Type)
                                 .ToList();

                var gameSession = new GameSession(organizer.PlayerId,
                                                  code,
                                                  new List <Player>()
                {
                    organizer
                },
                                                  new List <Hand>(),
                                                  configuration,
                                                  deckService.GenerateDeck(configuration),
                                                  emptyDecks,
                                                  GameSessionStatus.Created,
                                                  DateTime.Now,
                                                  new List <int>(),
                                                  new List <int>());
                activeSessions.Add(code, gameSession);
                return(gameSession);
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }