Ejemplo n.º 1
0
        public bool TakeTurn(ICentralPile centralPile, ICardTransport transport)
        {
            if (Hand.IsEmpty)
            {
                return(false);
            }

            transport.Transfer(Hand, centralPile);
            return(true);
        }
Ejemplo n.º 2
0
        public void Deal(ICardDeck cardDeck, IEnumerable <IPlayer> players)
        {
            var playerCount = players.Count();

            while (cardDeck.Count >= playerCount)
            {
                foreach (var player in players)
                {
                    cardTransport.Transfer(cardDeck, player.Hand);
                }
            }
        }
Ejemplo n.º 3
0
        private async Task ProcessPlayerSnaps(IEnumerable <IPlayer> players, ICentralPile centralPile, ICardTransport transport)
        {
            var results = (from p in players
                           select p)
                          .ToDictionary(k => k, v => v.CheckForMatchAsync(centralPile));

            var checkTask = await Task.WhenAny(Timeout(), Task.WhenAny(results.Values));

            var snappers = results.Where(o => o.Value.IsCompletedSuccessfully && o.Value.Result);

            if (snappers.Any())
            {
                var player = snappers.First().Key;
                transport.Transfer(centralPile, player.Hand);
                DumpState($"Snap ({player.Name})", players, centralPile.GetAll());
            }

            async Task <bool> Timeout()
            {
                await Task.Delay(3000);

                return(false);
            }
        }