public void CountHand(int playerId, int score) { var validation = new HandCountedEventValidation(); var @event = new HandCountedEvent { GameId = State.Id, PlayerId = playerId, CountedScore = score }; validation.Validate(State, @event); Stream.Add(@event); }
public void Handle(HandCountedEvent cardPlayedEvent, GameState gameState) { var roundState = gameState.GetCurrentRound(); var cutCard = roundState.Starter; var playerHand = roundState.Hands.First(ph => ph.Id == cardPlayedEvent.PlayerId); var calculatedShowScore = _scoreCalculator.CountShowScore(cutCard, playerHand.Hand); //penalty for overcounting var applicableScore = 0; if (cardPlayedEvent.CountedScore == calculatedShowScore.Score) { applicableScore = calculatedShowScore.Score; } else if (cardPlayedEvent.CountedScore > calculatedShowScore.Score) { //todo: //var score = calculatedShowScore.Score - ScorePenalty; //applicableScore = score < 0 ? 0 : score; } else { applicableScore = cardPlayedEvent.CountedScore; } var playerScore = gameState.IndividualScores.Single(ps => ps.Player == cardPlayedEvent.PlayerId); var teamScore = gameState.TeamScores.Single(ps => ps.Players.Contains(cardPlayedEvent.PlayerId)); playerScore.Score += applicableScore; teamScore.Score += applicableScore; var playerShowScore = gameState.GetCurrentRound().ShowScores.Single(pss => pss.Player == cardPlayedEvent.PlayerId); playerShowScore.ShowScore = calculatedShowScore.Score; playerShowScore.HasShowed = true; playerShowScore.Complete = cardPlayedEvent.PlayerId != roundState.PlayerCrib; playerShowScore.PlayerCountedShowScore = cardPlayedEvent.CountedScore; }