コード例 #1
0
        public Game()
        {
            deck = new Card();
            deck.Shuffle();
            p1 = new Player();
            p2 = new Player();
            for (int i = 0; i < 26; i++)
            {
                p1.AddCard(deck.Draw());
                p2.AddCard(deck.Draw());
            }

            Play();
        }
コード例 #2
0
        private void Compare(Card p1,Card p2, int time)
        {
            if (time <= 3)
            {
                Console.WriteLine($"{p1} vs {p2} ");
                if (p1.Rank < p2.Rank)
                {
                    player[0].GetCard(player[1].GiveCard(1));
                }
                else if (p1.Rank > p2.Rank)
                {
                    player[1].GetCard(player[0].GiveCard(1));
                }
                else
                {
                    Console.WriteLine("Draw (" + p1 + " , " + p2 + ")");

                    int numberCards = p1.Rank;

                    Card[] p1cards = player[0].PeekCard(numberCards + 1);
                    Card[] p2cards = player[1].PeekCard(numberCards + 1);

                    if (p1cards[p1cards.Length - 1].Rank < p2cards[p2cards.Length - 1].Rank)
                    {
                        player[0].GetCard(player[1].GiveCard(numberCards + 1));
                    }
                    else if (p1cards[p1cards.Length - 1].Rank > p2cards[p2cards.Length - 1].Rank)
                    {
                        player[1].GetCard(player[0].GiveCard(numberCards + 1));
                    }
                    else
                    {
                        Console.WriteLine("Draw (" + p1cards[p1cards.Length - 1] + " , " + p2cards[p2cards.Length - 1] + ") " + time + " round");
                        Console.Write(player[0].Name + " ");
                        player[0].deck.ShuffleDeck();
                        Console.Write(player[1].Name + " ");
                        player[1].deck.ShuffleDeck();
                        Compare(player[0].Draw(), player[1].Draw(), time + 1);
                    }
                }
            }
            else
            {

            }
        }
コード例 #3
0
        public void Play()
        {
            while (true)
            {
                if (p1.isEmpty())
                {
                    Console.WriteLine("END GAME ");
                    Console.WriteLine("Score player 1 : " + p1.sc());
                    Console.WriteLine("Score player 2 : " + p2.sc());
                    Console.ReadLine();
                    break;
                }
                Console.Write("P1 : ");
                p1.Show();
                Console.Write("P2 : ");
                p2.Show();
                a1 = p1.play();
                a2 = p2.play();
                if (a1 > a2)
                {
                    Console.WriteLine("P1 Win");
                    p1.Addscore(1);
                }
                else if (a1 < a2)
                {
                    Console.WriteLine("P2 Win");
                    p2.Addscore(1);
                }
                else if (a1 == a2)
                {
                    Console.WriteLine("Deal");
                    b1 = a1;
                    for (i = 0; i < b1; i++)
                    {
                        if (p1.isEmpty())
                        {
                            break;
                        }
                        a1 = p1.play();
                        a2 = p2.play();

                    }
                    int suit = 0;
                    Console.Write("Play again P1 : ");
                    while (a1 > 13)
                    {
                        a1 -= 13;
                        suit++;
                    }
                    if (a1 > 10)
                    {
                        if (a1 == 11)
                        {
                            Console.Write("J ");
                        }
                        else if (a1 == 12)
                        {
                            Console.Write("Q ");
                        }
                        else if (a1 == 13)
                        {
                            Console.Write("K ");
                        }
                    }
                    else
                    {
                        if (a1 == 1)
                        {
                            Console.Write("A ");
                        }
                        else
                        {
                            Console.Write(a1 + " ");
                        }
                    }
                    if (suit == 0)
                    {
                        Console.WriteLine("Clubs");
                    }
                    else if (suit == 1)
                    {
                        Console.WriteLine("Diamonds");
                    }
                    else if (suit == 2)
                    {
                        Console.WriteLine("Hearts");
                    }
                    else if (suit == 3)
                    {
                        Console.WriteLine("Spades");
                    }
                    Console.Write("Play again P2 : ");
                    suit = 0;
                    while (a2 > 13)
                    {
                        a2 -= 13;
                        suit++;
                    }
                    if (a2 > 10)
                    {
                        if (a2 == 11)
                        {
                            Console.Write("J ");
                        }
                        else if (a2 == 12)
                        {
                            Console.Write("Q ");
                        }
                        else if (a2 == 13)
                        {
                            Console.Write("K ");
                        }
                    }
                    else
                    {
                        if (a2 == 1)
                        {
                            Console.Write("A ");
                        }
                        else
                        {
                            Console.Write(a2 + " ");
                        }
                    }
                    if (suit == 0)
                    {
                        Console.WriteLine("Clubs");
                    }
                    else if (suit == 1)
                    {
                        Console.WriteLine("Diamonds");
                    }
                    else if (suit == 2)
                    {
                        Console.WriteLine("Hearts");
                    }
                    else if (suit == 3)
                    {
                        Console.WriteLine("Spades");
                    }
                    if (a1 > a2)
                    {
                        Console.WriteLine("P1 Win");
                        p1.Addscore(i + 1);
                    }
                    else if (a1 < a2)
                    {
                        Console.WriteLine("P2 Win");
                        p2.Addscore(i + 1);
                    }
                    else if (a1 == a2)
                    {
                        deck = new Card();
                        deck.Shuffle();
                        p1 = new Player();
                        p2 = new Player();
                        for (int i = 0; i < 26; i++)
                        {
                            p1.AddCard(deck.Draw());
                            p2.AddCard(deck.Draw());
                        }
                        Console.WriteLine("----New Game ----");
                        Play();
                    }
                }

                Console.ReadLine();
            }
        }
コード例 #4
0
 public void ReturnCard(Card[] cards)
 {
     foreach (Card card in cards)
         deck.AddCard(card);
 }
コード例 #5
0
 public Player()
 {
     deck = new Card();
 }
コード例 #6
0
 public void AddCard(Card card)
 {
     Cards.Push(card);
 }