Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5. namespace Blackjack
  6. {
  7. public class Card
  8. {
  9.  
  10. public string suit;
  11. public int value;
  12. public bool isBlackJack;
  13.  
  14. public Card(string _suit, int _value, bool isBJ)
  15. {
  16. suit = _suit;
  17. value = _value;
  18. isBlackJack = isBJ;
  19. }
  20. }
  21.  
  22. public class CardMaking
  23. {
  24. public static List<Card> Deck = new List<Card>();
  25. public static List<Card> playerCards = new List<Card>();
  26. public static List<Card> dealerCards = new List<Card>();
  27.  
  28.  
  29.  
  30. public static void Main()
  31. {
  32. GreetUser();
  33.  
  34. MakeCards();
  35.  
  36. DrawPlayerCard();
  37.  
  38. Console.ReadKey();
  39.  
  40. DrawPlayerCard();
  41.  
  42. Console.ReadKey();
  43.  
  44. PlayerCardValue();
  45.  
  46. Console.ReadKey();
  47.  
  48. DrawDealerCard();
  49.  
  50. Console.ReadKey();
  51.  
  52. DrawDealerCard();
  53.  
  54. Console.ReadKey();
  55.  
  56. DealerCardValue();
  57.  
  58. Console.ReadKey();
  59.  
  60.  
  61. Console.Clear();
  62.  
  63.  
  64.  
  65.  
  66. Console.ReadKey();
  67.  
  68. }
  69.  
  70. public static void GreetUser()
  71. {
  72. Console.WriteLine("VVelcome to blaccjacc.");
  73. Console.WriteLine("Press the enter button to start/Draw a card.");
  74.  
  75. Console.ReadKey();
  76. Console.Clear();
  77.  
  78. }
  79.  
  80.  
  81.  
  82. public static void MakeCards()
  83. {
  84. for (int i = 1; i < 5; i++)
  85. {
  86. string suits;
  87. if (i == 1)
  88. {
  89. suits = "Spades";
  90. }
  91. else if (i == 2)
  92. {
  93. suits = "Diamonds";
  94. }
  95. else if (i == 3)
  96. {
  97. suits = "Clubs";
  98. }
  99. else
  100. {
  101. suits = "Hearts";
  102. }
  103.  
  104. int cardNumber = 1;
  105.  
  106.  
  107. for (int a = 1; a < 14; a++)
  108. {
  109.  
  110. bool isBlackJack = false;
  111. if (cardNumber > 10)
  112. {
  113. cardNumber = 10;
  114. }
  115.  
  116. if (cardNumber == 11)
  117. {
  118. if (suits == "Clubs")
  119. {
  120. isBlackJack = true;
  121. }
  122. if (suits == "Spades")
  123. {
  124. isBlackJack = true;
  125. }
  126. }
  127.  
  128. Card cardContainer = new Card(suits, cardNumber, isBlackJack);
  129. Deck.Add(cardContainer);
  130.  
  131. cardNumber++;
  132.  
  133.  
  134. }
  135. }
  136. }
  137. public static void DrawPlayerCard()
  138. {
  139.  
  140. Random random = new Random();
  141. int r = random.Next(Deck.Count);
  142. Card randomCard = Deck[r];
  143.  
  144. playerCards.Add(randomCard);
  145. Deck.Remove(randomCard);
  146.  
  147. Console.WriteLine("Player drew a " + randomCard.value + " of " + randomCard.suit);
  148.  
  149. }
  150. public static void PlayerCardValue()
  151. {
  152. int playerTotalValue = 0;
  153.  
  154. foreach (Card c in playerCards)
  155. {
  156. playerTotalValue += c.value;
  157. }
  158.  
  159. Console.WriteLine("Player has a total of " + playerTotalValue + " value." );
  160. }
  161. public static void DrawDealerCard()
  162. {
  163.  
  164. Random random = new Random();
  165. int r = random.Next(Deck.Count);
  166. Card randomCard = Deck[r];
  167.  
  168. dealerCards.Add(randomCard);
  169. Deck.Remove(randomCard);
  170.  
  171. Console.WriteLine("Dealer drew a " + randomCard.value + " of " + randomCard.suit);
  172.  
  173. }
  174. public static void DealerCardValue()
  175. {
  176. int dealerTotalValue = 0;
  177.  
  178. foreach (Card c in dealerCards)
  179. {
  180. dealerTotalValue += c.value;
  181. }
  182. }
  183.  
  184.  
  185. }
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement