Exemple #1
0
        private int RankCalc(PlayingCard p)
        {
            string[] values = new string[] { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
            string   pval   = p.Rank;

            for (int i = 0; i < values.Length; i++)
            {
                if (pval == values[i])
                {
                    return(i);
                }
            }
            return(0);
        }
        private void InitCards(List <PlayingCard> deck)
        {
            string[] values = new string[] { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };

            foreach (string s in values)
            {
                PlayingCard p1 = new PlayingCard(CardSuit.Clubs, s);
                PlayingCard p2 = new PlayingCard(CardSuit.Diamonds, s);
                PlayingCard p3 = new PlayingCard(CardSuit.Hearts, s);
                PlayingCard p4 = new PlayingCard(CardSuit.Spades, s);

                deck.Add(p1);
                deck.Add(p2);
                deck.Add(p3);
                deck.Add(p4);
            }
        }
Exemple #3
0
        public void NextCard()
        {
            PlayingCard p1pc = (_p1.CurrentCards[0]);
            PlayingCard p2pc = (_p2.CurrentCards[0]);

            Console.WriteLine("[{0}], {1} {2} - [{3}], {4} {5}", _p1.Name, p1pc.Rank, p1pc.Suit, _p2.Name, p2pc.Rank, p2pc.Suit);

            if (RankCalc(p1pc) > RankCalc(p2pc))
            {
                //p1 win
                _p1.AddCard(p2pc);
                Console.WriteLine("{0} got the cards", _p1.Name);
                _p2.CurrentCards.Remove(p2pc);
            }
            else if (RankCalc(p1pc) == RankCalc(p2pc))
            {
                //Draw
                //_p2.AddCard(p2pc);
                _p2.CurrentCards.RemoveAt(0);
                Console.WriteLine("Draw");
                //_p1.AddCard(p1pc);
                _p1.CurrentCards.RemoveAt(0);
            }
            else
            {
                //p2 win
                _p2.AddCard(p1pc);
                Console.WriteLine("{0} got the cards", _p2.Name);
                _p1.CurrentCards.Remove(p1pc);
            }

            if (_p1.CurrentCards.Count <= 5 || _p2.CurrentCards.Count <= 5)
            {
                Console.WriteLine("[{0}] has {1} cards left - [{2}] has {3} cards left", _p1.Name, _p1.CurrentCards.Count, _p2.Name, _p2.CurrentCards.Count);
            }
        }
 public void AddCard(PlayingCard card)
 {
     _currentCards.Add(card);
 }