예제 #1
0
        public void Play()
        {
            Player roundWinner = null;
            var    roundCards  = new List <Card>();

            while (Player1.Hand.Count > 20 && Player2.Hand.Count > 20)
            {
                while (roundWinner == null)
                {
                    roundCards.Add(Player1.DrawCard());
                    roundCards.Add(Player2.DrawCard());
                    roundWinner = _winnerService.DetermineWinner(Player1, Player2);
                    _outputProvider($"{Player1} drew {Player1.CurrentCard}");
                    _outputProvider($"{Player2} drew {Player2.CurrentCard}");
                    if (roundWinner == null)
                    {
                        _outputProvider("There was a draw");
                        GoToWar(roundCards);
                    }
                }

                roundWinner.Score++;
                roundWinner.Hand.AddRange(roundCards);
                _outputProvider($"{roundWinner} won this round, they gained {roundCards.Count} cards and have " +
                                $"{roundWinner.Score} wins and {roundWinner.Hand.Count} cards in their hand");
                roundCards.Clear();
                roundWinner = null;
                _inputProvider();
            }

            var finalWinner = FindWinner(Player1, Player2);

            _outputProvider($"{finalWinner} won with a total of {finalWinner.Score} wins" +
                            $" and a hand of {finalWinner.Hand.Count} cards");
        }
예제 #2
0
        private Player FindRoundWinner(ICollection <Card> roundCards, List <Player> players)
        {
            AddRoundCards(roundCards, players);
            var roundWinner = _winnerService.DetermineWinner(players);

            OutputCardsDrawn(players);
            return(roundWinner);
        }