Exemplo n.º 1
0
        public void CheckForValidIndexes(int handId, int trumpSuitId, int?leadSuitId, string expectedResultString)
        {
            var cards     = _getCards(handId).OrderBySuitsAndRanks();
            var trumpSuit = _getSuit(trumpSuitId);
            var leadSuit  = _getSuit(leadSuitId);

            Assert.AreEqual(5, cards.Count);

            System.Console.WriteLine($"Trump: {trumpSuit?.Name}");
            System.Console.WriteLine($"Lead: {leadSuit?.Name}");

            _dumpCardsToConsole(cards);

            var result         = _inputHelper.GetValidIndexes(leadSuit, trumpSuit, cards).OrderBy(x => x.ToString());
            var expectedResult = _getExpectedResultAsCharList(expectedResultString).OrderBy(x => x.ToString());

            Assert.AreEqual(expectedResult.Count(), result.Count());

            foreach (var item in expectedResult)
            {
                var actualItem = result.FirstOrDefault(x => x.ToString() == item.ToString());

                Assert.AreEqual(item, actualItem);
            }
        }
Exemplo n.º 2
0
        private ICard _chooseHumanCard()
        {
            var renderedCards = _cardRenderer.RenderCards(_gameState.CurrentPlayer.Cards, new CardRenderingOptions
            {
                ShowIndexes = true
            });

            System.Console.WriteLine(renderedCards);

            System.Console.WriteLine($"Ordering up player: {_gameState.OrderingUpPlayer.Name}");

            if (_gameState.LeadSuit != null)
            {
                System.Console.WriteLine($"Lead: {_gameState.LeadSuit.Name}");
            }
            else
            {
                System.Console.WriteLine($"Lead: TBD");
            }

            System.Console.WriteLine($"Trump: {_gameState.Trump.Name}");

            foreach (var player in _gameState.Players)
            {
                System.Console.WriteLine($"{player.Name} (Team {player.TeamNumber}) Tricks: {player.TricksTaken}");
            }

            var keyPressed =
                _inputHelper.GetValidInput(
                    "It is your turn, which card would you like to play?",
                    _inputHelper.GetValidIndexes(_gameState.LeadSuit, _gameState.Trump, _gameState.CurrentPlayer.Cards)
                    );

            var indexOfCard = int.Parse(keyPressed.ToString()) - 1;

            var chosenCard = _gameState.CurrentPlayer.Cards[indexOfCard];

            System.Console.WriteLine($"You played the {chosenCard.Rank.Name} of {chosenCard.Rank.Name}:");

            renderedCards = _cardRenderer.RenderCards(new List <ICard> {
                chosenCard
            }, new CardRenderingOptions());

            System.Console.WriteLine(renderedCards);

            return(chosenCard);
        }