Exemplo n.º 1
0
        //MAIN
        static void Main(string[] args)
        {
            Console.Write("Input Player1's name : ");
            Player player1 = new Player(Console.ReadLine());
            Console.Write("Input Player2's name : ");
            Player player2 = new Player(Console.ReadLine());

            List<Card> allcard = new List<Card>();
            for (int i = 1; i <= 13; i++)
            {
                for (int j = 1; j <= 4; j++)
                {
                    allcard.Add(new Card(i,j));
                }
            }
            allcard = ShuffleList(allcard);

            for(int i=0;i<52;i+=2)
            {
                player1.addCard(allcard[i]);
                player2.addCard(allcard[i+1]);
            }

            do
            {
                Console.WriteLine("\nNew Round, Each player has " + Convert.ToString(player1.getNumdeck()) + " cards");
                Card c1 = player1.draw();
                Console.WriteLine(player1.getName() + " Draw : " + c1.nameRank() + c1.nameSuit());
                Card c2 = player2.draw();
                Console.WriteLine(player2.getName() + " Draw : " + c2.nameRank() + c2.nameSuit());

                if (c1.getRank() < c2.getRank())
                {
                    Console.WriteLine(player1.getName() + " Win!!!");
                    player1.addPile(c2);
                    player1.addPile(c1);
                }
                else if (c1.getRank() > c2.getRank())
                {
                    Console.WriteLine(player2.getName() + " Win!!!");
                    player2.addPile(c2);
                    player2.addPile(c1);
                }
                else
                {
                    Console.WriteLine("Card is equal at rank " + Convert.ToString(c1.getRank()) + "\nEach players draw " + Convert.ToString(c1.getRank()) + " cards");
                    int i,round;
                    List<Card> temp1 = new List<Card>();
                    List<Card> temp2 = new List<Card>();

                    temp1.Add(c1);
                    temp2.Add(c2);

                    if (player1.getNumdeck() < c1.getRank())
                    {
                        round = player1.getNumdeck();
                    }
                    else round = c1.getRank();

                    for (i = 0; i < round; i++)
                    {
                        temp1.Add(player1.draw());
                        temp2.Add(player2.draw());
                    }

                    Console.WriteLine(player1.getName() + " Draw : " + temp1[i - 1].nameRank() + temp1[i - 1].nameSuit());
                    Console.WriteLine(player2.getName() + " Draw : " + temp2[i - 1].nameRank() + temp2[i - 1].nameSuit());

                    if (temp1[i - 1].getRank() < temp2[i - 1].getRank())
                    {
                        Console.WriteLine(player1.getName() + " Win " + Convert.ToString((round + 1) * 2) + " cards!!!");
                        for (i = 0; i < round + 1; i++)
                        {
                            player1.addPile(temp2[i]);
                            player1.addPile(temp1[i]);
                        }
                    }
                    else if(temp1[i - 1].getRank() > temp2[i - 1].getRank())
                    {
                        Console.WriteLine(player2.getName() + " Win " + Convert.ToString((round + 1) * 2) + " cards!!!");
                        for (i = 0; i < round + 1; i++)
                        {
                            player2.addPile(temp2[i]);
                            player2.addPile(temp1[i]);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Equal again!!! Return all cards to your deck, Then shuffle it.");
                        for (i = 0; i < round + 1; i++)
                        {
                            player1.addCard(temp1[i]);
                            player2.addCard(temp2[i]);
                        }
                        player1.shuffleDeck();
                        player2.shuffleDeck();
                    }
                }
                Console.WriteLine(player1.getName() + " : " + Convert.ToString(player1.getNumpile()) + " & " + player2.getName() + " : " + Convert.ToString(player2.getNumpile()));
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            } while (player1.getNumdeck() > 0);
            if (player1.getNumpile() > player2.getNumpile())
            {
                Console.WriteLine("\n\n" + player1.getName() + " is the Winner!!!");
            }
            else if (player1.getNumpile() < player2.getNumpile())
            {
                Console.WriteLine("\n\n" + player2.getName() + " is the Winner!!!");
            }
            else
            {
                Console.WriteLine("\n\nDraw!!!");
            }
            Console.ReadKey();
        }