Пример #1
0
        public static string DeckCardsToString(Deck deck)
        {
            var sb = new StringBuilder();
            foreach (var card in deck.Cards)
            {
                sb.Append(string.Format("{0},", card.Name()));
            }

            return sb.ToString();
        }
Пример #2
0
        public Card Deal(Deck deck)
        {
            var c = deck.Cards.FirstOrDefault(x => x.State == Card.States.Available);
            if (c == null)
            {
                throw new NoAvailableCardsException();
            }

            c.State = Card.States.Dealt;
            return c;
        }
Пример #3
0
        public Deck Build()
        {
            var deck = new Deck();

            for (var s = 1; s < 5; s++)
            {
                for (var v = 1; v < 14; v++)
                {
                    deck.Cards.Add(new Card { Suite = (Card.Suites)s, Color = (Card.Colors)(s % 2), State = Card.States.Available, Value = v });
                }
            }

            return deck;
        }
Пример #4
0
        public void Serialize_Deck_And_Deserialize()
        {
            var deck = new Deck();
            var card = new Card
            {
                Color = Card.Colors.Black,
                Suite = Card.Suites.Clubs,
                State = Card.States.Available,
                Value = 2
            };
            deck.Cards = new List<Card> {card};

            var serializedDeck = Util.Serialize(deck);
            var deserializedDeck = Util.DeSerialize<Deck>(serializedDeck);

            Assert.IsNotNull(deserializedDeck);
            Assert.IsNotNull(deserializedDeck.Cards);
            Assert.AreEqual(1, deserializedDeck.Cards.Count());
            Assert.AreEqual(card.Color, deserializedDeck.Cards[0].Color);
            Assert.AreEqual(card.Suite, deserializedDeck.Cards[0].Suite);
            Assert.AreEqual(card.State, deserializedDeck.Cards[0].State);
            Assert.AreEqual(card.Value, deserializedDeck.Cards[0].Value);
        }
Пример #5
0
 private void TestDeckCardsValues(Deck deck, Card.Suites suite)
 {
     for (var v = 1; v < 14; v++)
     {
         Assert.IsTrue(deck.Cards.Any(x => x.Suite == suite && x.Value == v), string.Format("Card value {0}, suite: {1} does not exist.", v, suite));
     }
 }
Пример #6
0
 public Deck Shuffle(Deck deck)
 {
     deck.Cards = deck.Cards.OrderBy(x => Guid.NewGuid()).ToList();
     return deck;
 }