Ejemplo n.º 1
0
        //War Method
        private void War(Player player1, Player player2, Queue<PlayingCard> pot)
        {
            if (player1.cardsInHand.Count < 4 || player2.cardsInHand.Count < 4)
            {
                int p1Count = player1.cardsInHand.Count();
                int p2Count = player2.cardsInHand.Count();
                int hand;

                if (p1Count > p2Count) hand = p2Count;
                else hand = p1Count;

                for (int i = 0; i < (hand - 1); i++)
                {
                    GetCard(player1.cardsInHand, pot);
                    GetCard(player2.cardsInHand, pot);
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    GetCard(player1.cardsInHand, pot);
                    GetCard(player2.cardsInHand, pot);
                }
            }

            PlayingCard p1Card = GetCard(player1.cardsInHand, pot);
            PlayingCard p2Card = GetCard(player2.cardsInHand, pot);
            ShowWarringCards(player1, p1Card, player2, p2Card);

            _result.AppendFormat(EvaluateWinner(player1, p1Card, player2, p2Card, pot));
        }
Ejemplo n.º 2
0
 private void ShowWarringCards(Player player1, PlayingCard p1Card, Player player2, PlayingCard p2Card)
 {
     _result.AppendFormat("<h4>Warring Cards.....{0} cards in the pot!</h4>", _pot.Count());
     _result.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
     _result.AppendFormat("{0} drew {1} of {2}</br>", player1.Name, p1Card.CardName, p1Card.Suit);
     _result.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
     _result.AppendFormat("{0} drew {1} of {2}</br>", player2.Name, p2Card.CardName, p2Card.Suit);
 }
Ejemplo n.º 3
0
        private string declareWinner(Player _player1, Player _player2)
        {
            Player winner;
            if (_player1.cardsInHand.Count() > _player2.cardsInHand.Count()) winner = _player1;
            else winner = _player2;

            string result = $"</br><h2>{winner.Name} is the winner with {winner.cardsInHand.Count()} cards.</h2>";

            return result;
        }
Ejemplo n.º 4
0
        public string PlayRound(Player player1, Player player2)
        {
            _pot = new Queue<PlayingCard>();
            _result = new StringBuilder();

            PlayingCard p1Card = GetCard(player1.cardsInHand, _pot);
            PlayingCard p2Card = GetCard(player2.cardsInHand, _pot);

            ShowWarringCards(player1, p1Card, player2, p2Card);

            _result.Append(EvaluateWinner(player1, p1Card, player2, p2Card, _pot));

            return _result.ToString();
        }
Ejemplo n.º 5
0
        public string Deal(Player player1, Player player2)
        {
            player1.cardsInHand = new Queue<PlayingCard>();

            player2.cardsInHand = new Queue<PlayingCard>();

            for (int i = 0; i < _shuffledDeck.Count - 1; i += 2)
            {
                player1.cardsInHand.Enqueue(_shuffledDeck[i]);
                player2.cardsInHand.Enqueue(_shuffledDeck[i + 1]);
            }

            _result.Append("<h2>Dealing Cards...</h2>").AppendLine();
            for (int i = 0; i < 26; i++)
            {
                _result.AppendFormat("{0} is dealt {1} of {2}</br>", player1.Name, player1.cardsInHand.ElementAt(i).CardName, player1.cardsInHand.ElementAt(i).Suit);
                _result.AppendFormat("{0} is dealt {1} of {2}</br>", player2.Name, player2.cardsInHand.ElementAt(i).CardName, player2.cardsInHand.ElementAt(i).Suit);
            }

            return _result.ToString();
        }
Ejemplo n.º 6
0
        private string EvaluateWinner(Player player1, PlayingCard p1Card, Player player2, PlayingCard p2Card,
            Queue<PlayingCard> pot)
        {
            string winnerName = "";

            if (p1Card.Value == p2Card.Value)
            {
                _result.Append("<strong>*******This is War!*******</strong>");
                War(player1, player2, pot);
            }
            else if (p1Card.Value < p2Card.Value)
            {
                winnerName = String.Format("<span style='color:blue'>{0} wins pot of {1} cards!</span>",
                    player2.Name, pot.Count());
                Winner(player2);
            }
            else
            {
                winnerName = String.Format("<span style='color:blue'>{0} wins pot of {1} cards!</span>",
                    player1.Name, pot.Count());
                Winner(player1);
            }
            return winnerName;
        }
Ejemplo n.º 7
0
 private void Winner(Player player)
 {
     foreach (var item in _pot)
     {
         player.cardsInHand.Enqueue(item);
     }
     _pot.Clear();
 }
Ejemplo n.º 8
0
        public PlayWar(string player1Name, string player2Name)
        {
            _player1 = new Player {Name = player1Name};

            _player2 = new Player {Name = player2Name};
        }