Example #1
0
        public void Handle(CardsThrownEvent cardsThrownEvent, GameState gameState)
        {
            var currentRound = gameState.GetCurrentRound();

            //remove thrown cards from hand
            var playerId = cardsThrownEvent.PlayerId;
            var playerHand = currentRound.DealtCards.Single(ph => ph.Id == playerId).Hand.Except(cardsThrownEvent.Thrown, CardValueEquality.Instance);
            currentRound.Hands.Add(new PlayerIdHand(playerId, playerHand.ToList()));

            currentRound.Crib.AddRange(cardsThrownEvent.Thrown);

            var playersDoneThrowing = gameState.GetCurrentRound().Crib.Count == GameRules.HandSize;
            currentRound.ThrowCardsComplete = playersDoneThrowing;
        }
Example #2
0
        public void ThrowCards(int playerId, IEnumerable<Card> cribCards)
        {
            var validation = new CardsThrownEventValidation();
            var @event = new CardsThrownEvent { GameId = State.Id, Thrown = cribCards.ToList(), PlayerId = playerId, };
            validation.Validate(State, @event);

            Stream.Add(@event);
            var currentRound = State.GetCurrentRound();
            if (currentRound.ThrowCardsComplete)
            {
                var cardsNotDealt = _deck.Except(currentRound.Crib, CardValueEquality.Instance).Except(currentRound.Hands.SelectMany(s => s.Hand), CardValueEquality.Instance).ToList();
                var randomIndex = RandomProvider.GetThreadRandom().Next(0, cardsNotDealt.Count - 1);
                var startingCard = cardsNotDealt[randomIndex];
                Stream.Add(new StarterCardSelectedEvent { GameId = State.Id, Starter = startingCard });
                Stream.Add(new PlayStartedEvent { GameId = State.Id, Round = currentRound.Round });
            }
        }