Пример #1
0
        public Deck()
        {
            _cards = new List<Card>();

            for (int i = 1; i <= 52; i++)
            {
                var suit = 1;
                var rank = i;

                if(i>13 && i<=26)
                {
                    suit = 2;
                    rank = i - 13;
                }
                else if(i>26 && i<=39)
                {
                    suit = 3;
                    rank = i - 26;
                }
                else if(i > 39)
                {
                    suit = 4;
                    rank = i - 39;
                }

                var card = new Card { Suit = (Suit)(suit), Rank = (Rank)(rank) };
                _cards.Add(card);
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int suitNumber = random.Next(4);
            int valueNumber = random.Next(1, 14);

            Suit suit = (Suit)suitNumber;
            Value value = (Value)valueNumber;

            Card myCard = new Card(suit, value);

            MessageBox.Show(myCard.name);
        }
Пример #3
0
 public Form1()
 {
     InitializeComponent();
     for (int i = 0; i <= 3; i++)
     {
         for (int y = 1; y <= 13; y++)
         {
             cards[count] = new Card((Suits)i, (Values)y);
             count++;
             Console.WriteLine(count);
         }
     }
 }
        private Random randomNumbers; // random number generator

        #endregion Fields

        #region Constructors

        //constructor fills deck of Cards
        public DeckOfCards()
        {
            string[] faces = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
            string[] suits = { "Hearts", "Diamonds", "Clubs", "Spades" };

            deck = new Card[NUMBER_OF_CARDS]; // create array of Card objects
            currentCard = 0; // set currentCard so deck[0] is dealt first
            randomNumbers = new Random(); // create random number generator

            // Populate deck with Card objects

            for (int count = 0; count < deck.Length; ++count)
                deck[count] = new Card(faces[count % 13], suits[count / 13]);
        }
Пример #5
0
        internal void PlayCard(PlayerMetadata playerMeta, Card card)
        {
            if (IsCardPlayable(playerMeta, card) == false)
            {
                throw new Exception(playerMeta.Player.PlayerName + " is Cheating and playing cards that are not playable!");
            }

            if (PlayedCards.Any() == false)
            {
                LeadSuit = card.Suit;
            }

            PlayedCards.Add(playerMeta, card);
        }
Пример #6
0
 public void Push(Card c)
 {
     this.cards.Add(c);
 }
Пример #7
0
 public void Insert(Card c)
 {
     this.cards.Insert(this.random.Next(this.cards.Count), c);
 }
Пример #8
0
        public bool IsCardPlayable(PlayerMetadata player, Card card)
        {
            if (card.Suit == Suit.Spades && _hand.SpadesHaveBeenBroken == false) return false; //And the player has a suit other than spades

            return true;
        }