Exemplo n.º 1
0
        public void CountCrib(int playerId, int score)
        {
            var validation = new CribCountedEventValidation();
            var @event = new CribCountedEvent { GameId = State.Id, PlayerId = playerId, CountedScore = score };
            validation.Validate(State, @event);
            Stream.Add(@event);

            Stream.Add(new RoundStartedEvent { GameId = State.Id });
            _deck.Shuffle(3);
            Stream.Add(new DeckShuffledEvent { Deck = _deck.ToList(), GameId = State.Id });
            var playerHands = _dealer.CreatePlayerHands(_deck, State.PlayerIds, State.PlayerIds.NextOf(State.PlayerIds.NextOf(playerId)), State.GameRules.HandSizeToDeal);
            Stream.Add(new HandsDealtEvent { GameId = State.Id, Hands = playerHands });
        }
Exemplo n.º 2
0
        public void Handle(CribCountedEvent cribCountedEvent, GameState gameState)
        {
            var currentRound = gameState.GetCurrentRound();
            var cutCard = currentRound.Starter;
            var crib = currentRound.Crib;

            var calculatedCribShowScore = _scoreCalculator.CountShowScore(cutCard, crib);

            var calculatedCribScore = calculatedCribShowScore.Score;
            //penalty for overcounting
            var applicableScore = 0;
            if (cribCountedEvent.CountedScore == calculatedCribScore)
            {
                applicableScore = calculatedCribScore;
            }
            else if (cribCountedEvent.CountedScore > calculatedCribScore)
            {
                //todo: fix
                //var score = calculatedCribScore - ScorePenalty;
                //applicableScore = score < 0 ? 0 : score;
            }
            else
            {
                applicableScore = cribCountedEvent.CountedScore;
            }

            var playerScore = gameState.IndividualScores.Single(ps => ps.Player == cribCountedEvent.PlayerId);
            var teamScore = gameState.TeamScores.Single(ps => ps.Players.Contains(cribCountedEvent.PlayerId));
            playerScore.Score += applicableScore;
            teamScore.Score += applicableScore;

            var playerShowScore = gameState.GetCurrentRound().ShowScores.Single(pss => pss.Player == cribCountedEvent.PlayerId);
            playerShowScore.CribScore = calculatedCribScore;
            playerShowScore.HasShowedCrib = true;
            playerShowScore.Complete = true;

            currentRound.Complete = true;
        }