public async Task <PlayerTurnResult> StoreTurnOutcomeAsync(TurnWinner turnWinner)
        {
            var result = new PlayerTurnResult();

            await UpdateNextComputerMoveAsync();

            result.NextMoveReady = true;

            if (turnWinner == TurnWinner.Tie)
            {
                var previousStreak = await StateManager.TryGetStateAsync <int>(PreviousStreakStateName);

                if (previousStreak.HasValue)
                {
                    result.CurrentStreak = result.PreviousStreak = previousStreak.Value;
                }

                return(result);
            }

            var previousWinner = await StateManager.TryGetStateAsync <TurnWinner>(
                PreviousWinnerStateName);

            if (previousWinner.HasValue)
            {
                result.PreviousStreak = await StateManager.GetStateAsync <int>(
                    PreviousStreakStateName);
            }

            if (previousWinner.Value != turnWinner)
            {
                result.CurrentStreak = 1;
            }
            else
            {
                result.CurrentStreak = result.PreviousStreak + 1;
            }

            await StateManager.SetStateAsync(PreviousStreakStateName, result.CurrentStreak);

            await StateManager.SetStateAsync(PreviousWinnerStateName, turnWinner);

            return(result);
        }
예제 #2
0
        public string GetResponseSentence(GameOption playerMove, GameOption computerMove, TurnWinner winner,
                                          PlayerTurnResult playerTurnResult)
        {
            if (!playerTurnResult.NextMoveReady)
            {
                throw new ValidationException("Next move must be ready.");
            }

            return("Ready for your next move.");
        }
        private async Task SetStateAsync(TurnWinner previousWinner, int previousStreak)
        {
            await _target.StateManager.SetStateAsync("previousWinner", previousWinner);

            await _target.StateManager.SetStateAsync("previousStreak", previousStreak);
        }
예제 #4
0
        public string GetResponseSentence(GameOption playerMove, GameOption computerMove, TurnWinner winner,
                                          PlayerTurnResult playerTurnResult)
        {
            if (winner == TurnWinner.Tie && playerTurnResult.CurrentStreak == playerTurnResult.PreviousStreak)
            {
                if (playerTurnResult.CurrentStreak == 0)
                {
                    return(null);
                }

                return($"Your current streak is {playerTurnResult.CurrentStreak}.");
            }

            if (playerTurnResult.CurrentStreak == 1) // reset
            {
                return($"Your previous streak was {playerTurnResult.PreviousStreak}.");
            }

            if (playerTurnResult.CurrentStreak > playerTurnResult.PreviousStreak)
            {
                return($"Your streak increased to {playerTurnResult.CurrentStreak}.");
            }

            throw new InvalidConstraintException("Streak did not update in a consistent manner.");
        }
        public string GetResponseSentence(GameOption playerMove, GameOption computerMove, TurnWinner winner,
            PlayerTurnResult playerTurnResult)
        {
            var winSentence = winner switch
            {
                TurnWinner.Human => $"{playerMove} beat {computerMove}.",
                TurnWinner.Computer => $"{playerMove} lost to {computerMove}.",
                TurnWinner.Tie => $"Tie!",
                _ => throw new ValidationException(
                    $"Input {winner} not recognized.")
            };

            return winSentence;
        }
    }