Beispiel #1
0
        public Card[] GetRuleCards()
        {
            var cards = new Card[]
            {
                new Card(Kinds.Ace, Suits.Any),
                new Card(Kinds.King, Suits.Any),
                new Card(Kinds.Queen, Suits.Any),
                new Card(Kinds.Jack, Suits.Any),
                new Card(Kinds.Ten, Suits.Any),
                new Card(Kinds.Any, Suits.Any),
            };

            return(_scoringService.GetScoredCards(cards, null).ToArray());
        }
        /// <summary>
        ///     Play the game with the specified number of players.
        /// </summary>
        /// <param name="playerCount">
        ///     The number of players.
        /// </param>
        /// <returns>
        ///     The result of playing the game.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown if the number of players is out of range.
        /// </exception>
        public GameResult PlayGame(int playerCount)
        {
            var deck = _drawingService.DrawDeck();

            var maxPlayerCount = (deck.Count - 1) / PlayerHandSize;

            if (playerCount < MinPlayerCount || playerCount > maxPlayerCount)
            {
                throw new ArgumentOutOfRangeException(nameof(playerCount), playerCount,
                                                      $"Player count must be between {MinPlayerCount} and {maxPlayerCount}.");
            }

            var wildcard = _drawingService.DrawCard(deck);

            var results = new PlayerResult[playerCount];

            for (var playerIndex = 0; playerIndex < playerCount; playerIndex++)
            {
                var cards       = _drawingService.DrawHand(deck, PlayerHandSize);
                var scoredCards = _scoringService.GetScoredCards(cards, wildcard).ToArray();
                results[playerIndex] = new PlayerResult
                {
                    Player = playerIndex + 1,
                    Cards  = scoredCards,
                    Points = scoredCards.Sum(c => c.Points),
                };
            }

            var gameResult = new GameResult()
            {
                Wildcard      = wildcard,
                PlayerResults = results
                                .OrderByDescending(r => r.Points)
                                .ThenBy(r => r.Player)
                                .ToArray()
            };

            return(gameResult);
        }