示例#1
0
        public async Task <string> CreateGameAsync([FromBody] CreateGameOptions options, [FromServices] StateClient state)
        {
            // TODO: Verify user owns the deck.

            string id = Guid.NewGuid().ToString();

            var deck = DeckActorProxy.CreateProxy(options.DeckId);

            var deckDetails = await deck.GetDetailsAsync();

            var cards = await Task.WhenAll(
                deckDetails.Cards.Select(
                    async deckCard =>
            {
                var card = CardActorProxy.CreateProxy(deckCard.CardId);

                var cardDetails = await card.GetDetailsAsync();

                return(new GameCard
                {
                    CardId = deckCard.CardId,
                    Value = cardDetails.Value
                });
            }));

            var game = GameActorProxy.CreateProxy(id);

            await game.SetDetailsAsync(
                new GameDetails
            {
                Players =
                    new[]
                {
                    new GamePlayer
                    {
                        Cards  = cards,
                        UserId = options.UserId
                    },
                    CreateComputerPlayer(cards.Length)
                }
            });

            var games = await state.GetStateAsync <HashSet <string> >("games");

            games ??= new HashSet <string>();

            games.Add(id);

            await state.SaveStateAsync("games", games);

            var user = UserActorProxy.CreateProxy(options.UserId);

            await user.AddGameAsync(id);

            return(id);
        }
示例#2
0
        public async Task SetDeckAsync(string id, [FromBody] DeckDetails details, [FromServices] StateClient state)
        {
            var deck = DeckActorProxy.CreateProxy(id);

            await deck.SetDetailsAsync(details);

            var decks = await state.GetStateAsync <HashSet <string> >("decks");

            decks ??= new HashSet <string>();

            decks.Add(id);

            await state.SaveStateAsync("decks", decks);
        }
示例#3
0
        public Task <DeckDetails> GetDeckAsync(string id)
        {
            var deck = DeckActorProxy.CreateProxy(id);

            return(deck.GetDetailsAsync());
        }