コード例 #1
0
 public Deck()
 {
     for (int i = 1; i <= 13; i++)
     {
         Cards c = new Cards();
         c.Suit = "Clubs";
         c.Rank = i;
         acard.Add(c);
     }
     for (int j = 1; j <= 13; j++)
     {
         Cards c = new Cards();
         c.Suit = "Diamonds";
         c.Rank = j;
         acard.Add(c);
     }
     for (int k = 1; k <= 13; k++)
     {
         Cards c = new Cards();
         c.Suit = "Hearts";
         c.Rank = k;
         acard.Add(c);
     }
     for (int l = 1; l <= 13; l++)
     {
         Cards c = new Cards();
         c.Suit = "Spades";
         c.Rank = l;
         acard.Add(c);
     }
 }
コード例 #2
0
 public Cards DealCard()
 {
     Cards c = new Cards();
     int a = card.Next(acard.Count());
     c =acard[a];
     acard.Remove(c);
     CountCards--;
     return c;
 }
コード例 #3
0
        public void CompareCards(Cards c1,Cards c2)
        {
            int sum = 2;
            Cards c11 = new Cards();
            Cards c21 = new Cards();

            while(c1.Rank == c2.Rank)
            {
                int count;
                if (c1.Rank > _gameCard.CountCards)
                {
                    count = _gameCard.CountCards;
                }
                else count = c1.Rank;

                Console.ReadKey();
                Console.WriteLine("{0} and {1} Draw!! ", _p1.Name, _p2.Name);
                //Console.WriteLine("Score {0}: {1} and Score {2}: {3}  ", _p1.Name,_p1.Score, _p2.Name,_p2.Score);
                //Console.WriteLine("Amount of remained cards in Player's Deck: {0}", _gameCard.CountCards/2);
                if (_gameCard.CountCards != 0)
                {
                    c11 = _gameCard.DealCard();
                    c21 = _gameCard.DealCard();
                    Console.WriteLine("{0} has {1}\n{2} has {3}", _p1.Name, c11,_p2.Name, c21);

                    if (c11.Rank == c21.Rank)
                    {
                        _gameCard.ReturnCard(c1, c2, c11, c21);

                        Console.WriteLine("{0} and {1} Draw Again!! ", _p1.Name, _p2.Name);
                       // Console.WriteLine("Score {0}: {1} and Score {2}: {3}  ", _p1.Name, _p1.Score, _p2.Name, _p2.Score);
                       // Console.WriteLine("Amount of remained cards in Player's Deck: {0}", _gameCard.CountCards/2);
                        if (_gameCard.CountCards != 0)
                        {
                            c1 = _gameCard.DealCard();
                            c2 = _gameCard.DealCard();

                            Console.WriteLine("{0} has {1}\n{2} has {3}", _p1.Name, c11, _p2.Name, c21);
                        }
                        else _isEnd = true;
                    }
                    else if (c11.Rank < c21.Rank)
                    {
                        _p1.Score += (c1.Rank + 1) * 2;
                        Console.WriteLine("{0} Win!! Score: {1} ", _p1.Name, _p1.Score);
                        Console.WriteLine("{0} Lose!! Score: {1} ", _p2.Name, _p2.Score);

                        for(int i=1;i<count*2;i++)
                        {
                            c11 = _gameCard.DealCard();
                        }
                        Console.WriteLine("Amount of remained cards in Player's Deck: {0}", _gameCard.CountCards / 2);
                        break;

                    }
                    else if (c11.Rank > c21.Rank)
                    {
                        _p2.Score += (c1.Rank+1)*2;
                        Console.WriteLine("{0} Win!! Score: {1} ", _p2.Name, _p2.Score);
                        Console.WriteLine("{0} Lose!! Score: {1} ", _p1.Name, _p1.Score);

                        for (int i = 1; i < count*2; i++)
                        {
                            c11 = _gameCard.DealCard();
                        }
                        Console.WriteLine("Amount of remained cards in Player's Deck: {0}", _gameCard.CountCards / 2);
                        break;
                    }
                }
                else _isEnd = true;
            }
            if (c1.Rank < c2.Rank)
            {
                _p1.Score+=sum;
                Console.WriteLine("{0} Win!! Score: {1} ", _p1.Name, _p1.Score);
                Console.WriteLine("{0} Lose!! Score: {1} ", _p2.Name, _p2.Score);
                Console.WriteLine("Amount of remained cards in Player's Deck: {0}", _gameCard.CountCards/2);

            }
            else if (c1.Rank > c2.Rank)
            {
                _p2.Score+=sum;
                Console.WriteLine("{0} Win!! Score: {1} ", _p2.Name, _p2.Score);
                Console.WriteLine("{0} Lose!! Score: {1} ", _p1.Name, _p1.Score);
                Console.WriteLine("Amount of remained cards in Player's Deck: {0}", _gameCard.CountCards/2);

            }
        }
コード例 #4
0
 public void ReturnCard(Cards a,Cards b,Cards c,Cards d)
 {
     acard.Add(a);
     acard.Add(b);
     acard.Add(c);
     acard.Add(d);
     CountCards+=4;
 }
コード例 #5
0
        public void PlayGame()
        {
            Console.Write("First Player: ");
            _p1.Name = Console.ReadLine();
            Console.Write("Second Player: ");
            _p2.Name = Console.ReadLine();
            Cards c1 = new Cards();
            Cards c2 = new Cards();
            while (!_isEnd)
            {

                if (_gameCard.CountCards != 0)
                {
                    c1 = _gameCard.DealCard();
                    c2 = _gameCard.DealCard();
                    Console.WriteLine("{0} has {1}\n{2} has {3}", _p1.Name, c1, _p2.Name, c2);
                    CompareCards(c1, c2);
                    Console.ReadKey();
                    Console.WriteLine("\n");
                }
                else _isEnd = true;
            }
            EndGame();
        }