예제 #1
0
        static void Main(string[] args)
        {
            Player s1 = new Player("Player 1");
            Player s2 = new Player("Player 2");

            Game.playgame(s1, s2);
            Console.ReadLine();
        }
예제 #2
0
 public void Shuffle(Player s, int numofset)
 {
     string[] newArray = new string[26];
     string tmp;
     newArray = s.Deck_card;
     Random rnd = new Random();
     int iCount = numofset;
     int bNum;
     while (iCount < 26)
     {
         bNum = rnd.Next(numofset, 26);
         tmp = newArray[bNum];
         newArray[iCount] = newArray[bNum];
         newArray[bNum] = tmp;
         iCount++;
     }
     s.Deck_card = newArray;
 }
예제 #3
0
 public void DealCard(Player s1, Player s2)
 {
     int j, k;
     j = k = 0;
     for (int i = 0; i < 52; i++)
     {
         if (i % 2 == 0)
         {
             s1.Deck_card[j] = CardArray[i];
             j++;
         }
         else
         {
             s2.Deck_card[k] = CardArray[i];
             k++;
         }
     }
 }
예제 #4
0
        public static void playgame(Player s1, Player s2)
        {
            int indexofdeck = 0;
            int round = 0;
            int sum = 0;

            deck deck_card = new deck();
            deck_card.Deck();
            deck_card.Shuffle();
            deck_card.DealCard(s1, s2);

            Console.WriteLine(" ");

            while (indexofdeck != 26)
            {
                if (card.CardRank(s1.Deck_card[indexofdeck]) < card.CardRank(s2.Deck_card[indexofdeck]))
                {
                    Console.WriteLine(s1._name + " : " + s1.Deck_card[indexofdeck] + " Win " + s2._name + " : " + s2.Deck_card[indexofdeck]);
                    s1.num_of_card += (2 + (2 * sum));
                    indexofdeck++;
                    round = 0;
                    sum = 0;
                }
                else if (card.CardRank(s1.Deck_card[indexofdeck]) > card.CardRank(s2.Deck_card[indexofdeck]))
                {
                    Console.WriteLine(s2._name + " : " + s2.Deck_card[indexofdeck] + " Win " + s1._name + " : " + s1.Deck_card[indexofdeck]);
                    s2.num_of_card += (2 + (2 * sum));
                    indexofdeck++;
                    round = 0;
                    sum = 0;
                }
                else
                {
                    if (round == 0)
                    {
                        Console.WriteLine(s1._name + " : " + s1.Deck_card[indexofdeck] + " Equal " + s2._name + " : " + s2.Deck_card[indexofdeck]);
                        if (indexofdeck + card.CardRank(s1.Deck_card[indexofdeck]) <= 25)
                        {
                            sum = card.CardRank(s1.Deck_card[indexofdeck]);
                            indexofdeck += sum;
                            round = 1;

                        }
                        else
                        {
                            sum = (25 - indexofdeck);
                            indexofdeck = 25;
                            round = 1;
                        }
                    }
                    else
                    {
                        if (indexofdeck < 25)
                        {
                            Console.WriteLine(s1._name + " : " + s1.Deck_card[indexofdeck] + " Equal(again) " + s2._name + " : " + s2.Deck_card[indexofdeck] + "(Shuffle Card)");
                            round = 0;
                            indexofdeck -= sum;
                            sum = 0;
                            deck_card.Shuffle(s1, indexofdeck);
                            deck_card.Shuffle(s2, indexofdeck);
                        }
                        else
                        {
                            indexofdeck++;
                        }

                    }

                }
            }

            Console.WriteLine(" ");

            if (s1.num_of_card < s2.num_of_card)
            {
                Console.WriteLine(s1._name + " get " + s1.num_of_card + " cards Win");
            }
            else if (s2.num_of_card < s1.num_of_card)
            {
                Console.WriteLine(s2._name + " get " + s2.num_of_card + " cards Win");
            }
            else
            {
                Console.WriteLine(s1._name + " and " + s2._name + " get " + s2.num_of_card + " cards Draw");
            }
            Console.WriteLine(" ");
        }