public Deck() { cardsInDeck = 51; cards = new Card[52]; int x = 0; int val; for (int a = 0; a <= 3; a++) { for (int b = 0; b <= 12; b++) { switch (b) { case 0: val = 1; break; case 10: val = 10; break; case 11: val = 10; break; case 12: val = 10; break; default: val = b+1; break; } cards[x] = new Card(a, b, val); x++; } } }
public Card[] DrawTwoFromDeck() { Card[] hand = new Card[2]; for (int i = 0; i < 2; i++) { Random generator = new Random(); int index = 0; do { index = generator.Next(52); } while (cards[index] == null); cardsInDeck--; Card temp = cards[index]; cards[index] = null; hand[i] = temp; } return hand; }
public void Suit_Value4_ReturnsR() { var card = new Card(1, 4); Assert.AreEqual('R', card.Suit); }
public void Suit_Value3_ReturnsK() { var card = new Card(1, 3); Assert.AreEqual('K', card.Suit); }
public void Suit_Value2_ReturnsH() { var card = new Card(1, 2); Assert.AreEqual('H', card.Suit); }
public void Suit_Value1_ReturnsS() { var card = new Card(1, 1); Assert.AreEqual('S', card.Suit); }
public int handCount(Card[] hand, Card[] extras) { int total = hand.Sum(card => card.value); total += extras.Where(card => card != null).Sum(card => card.value); return total; }
public string CheckBlackJack(Card[] hand) { if(hand[0].value == 1 ) { hand[0].value = 11; } else if(hand[1].value == 1 && hand[0].value != 11) { hand[1].value = 11; } if (hand.Length == 2) { if((hand[0].value + hand[1].value) == 21) return $"BackJack {hand[0].value + hand[1].value}"; return $"Normal Hand {hand[0].value+ hand[1].value}"; } return "This is not a two card hand."; }
public string TwoCardHandToString(Card[] hand) { if (hand.Length == 2) { return $"{hand[0]}, {hand[1]}"; } return "This is not a two card hand."; }