public void SetCardValues()
 {
     Card card = new Card(Suit.Spades, Value.Seven);
     CardValuesTest(card, Value.Seven, Suit.Spades, "7S");
     card = new Card(Suit.Diamonds, Value.Jack);
     CardValuesTest(card, Value.Jack, Suit.Diamonds, "JD");
 }
Exemple #2
0
 public static List<Card> Sort(Card[] cards)
 {
     List<Card> result = new List<Card>();
     if (cards != null)
         result = cards.OrderByDescending(q => (int)q.value).ToList();
     return result;
 }
 public void Sort()
 {
     Card[] cards = new Card[5] { new Card(Suit.Spades, Value.Queen), new Card(Suit.Diamonds, Value.Four), new Card(Suit.Clubs, Value.Five), new Card(Suit.Spades, Value.Ace), new Card(Suit.Hearts, Value.Queen) };
     List<Card> sorted = Card.Sort(cards);
     Assert.NotNull(sorted);
     Assert.AreEqual(5, sorted.Count);
     Card firstCard = sorted[0];
     Assert.AreEqual(Value.Ace, firstCard.Value);
     Assert.AreEqual(Suit.Spades, firstCard.Suit);
 }
Exemple #4
0
 void Initialize()
 {
     this.cards = new Dictionary<string, Card>();
     foreach (Value value in Enum.GetValues(typeof(Value))) {
         foreach (Suit suit in Enum.GetValues(typeof(Suit))) {
             Card card = new Card(suit, value);
             this.cards.Add(card.Name, card);
         }
     }
 }
 void PlayerValuesTest(Player player, string name, Card[] cards)
 {
     Assert.AreEqual(name, player.Name);
     if (cards == null) {
         Assert.IsNull(player.Cards);
     }
     else {
         Assert.IsNotNull(player.Cards);
         foreach (Card card in cards) {
             Card playerCard = player.Cards.FirstOrDefault(q => q.Name.Equals(card.Name));
             Assert.IsNotNull(playerCard);
         }
     }
 }
Exemple #6
0
 /// <summary>
 /// Give current card to a player. Player become an owner of the card until the game ends or reset.
 /// </summary>
 /// <param name="card">card</param>
 /// <param name="player">player which become an owner</param>
 /// <returns>Card which was given</returns>
 internal Card GiveCardToPlayer(Card card, Player player)
 {
     Card deckCard = cards[card.Name];
     if (deckCard != null) {
         if (deckCard.Owner == null)
             deckCard.Owner = player;
         else
             throw new Exception(String.Format("The card {0} is already have an owner ({1}) for this game.", deckCard.Name, deckCard.Owner.Name));
     }
     else {
         throw new Exception(String.Format("There is no {0} card in a deck.", card.Name));
     }
     return deckCard;
 }
 void CardValuesTest(Card card, Value value, Suit suit, string name)
 {
     Assert.AreEqual(value, card.Value);
     Assert.AreEqual(suit, card.Suit);
     Assert.AreEqual(name, card.Name);
 }