Advertisement
Guest User

Hi Liang

a guest
Jul 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. Deck.java :
  2. package Deck;
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. //pages.cs.wisc.edu/~hasti/cs302/examples/Deck/Deck.java
  7.  
  8. public class Deck {
  9. public static final int DECK_SIZE = 52;
  10. public static Card[] cards; // array holding all 52 cards
  11. private int cardsInDeck; // the current number of cards in the deck
  12. public static ArrayList<Integer> pCards = new ArrayList<>();//player cards
  13.  
  14. public Deck() {
  15. cards = new Card[DECK_SIZE];
  16. cardsInDeck = DECK_SIZE;
  17. for (int i = 0; i < 13; i++) {
  18. cards[i] = new Card(i + 1, Card.DIAMONDS);
  19. cards[i + 13] = new Card(i + 1, Card.CLUBS);
  20. cards[i + 26] = new Card(i + 1, Card.HEARTS);
  21. cards[i + 39] = new Card(i + 1, Card.SPADES);
  22. }
  23. }
  24.  
  25. public Card deal() {
  26. if (cardsInDeck>0) {
  27. pCards.add(cards[0].cNumber);
  28. for(int i=0;i<cardsInDeck;i++) {
  29. cards[i] = cards[i+1];
  30. cards[cardsInDeck-1] = new Card(0,0);
  31. cardsInDeck--;
  32. }
  33. return cards[0];
  34. }else
  35. System.out.println("ERROR: No More Cards");
  36. return new Card(0,0);
  37. }
  38.  
  39. public static void swapCards(Card[] a, int i, int swapped) {
  40. Card swapper = a[i];
  41. a[i] = a[swapped];
  42. a[swapped] = swapper;
  43. }
  44.  
  45. public int getpCard(Card[] a) {
  46.  
  47. return 0;
  48. }
  49.  
  50. public void shuffle(Card[] a) {
  51. int n = a.length;
  52. Random random = new Random();
  53. random.nextInt(52);
  54. for (int i = 0; i<n; i++) {
  55. int swapped = i + random.nextInt(n - i);
  56. swapCards(a, i, swapped);
  57. }
  58. }
  59.  
  60.  
  61. }
  62.  
  63. Main.java
  64. package Deck;
  65.  
  66. import java.util.ArrayList;
  67. import java.util.Scanner;
  68.  
  69. public class Main extends Deck{
  70.  
  71. //Player Wallet
  72. public int pWallet = 200;
  73. public int pSum;
  74.  
  75. public int pSum() {
  76. int sum = 0;
  77. for(int i=0;i<pCards.size();i++) {
  78. sum = sum + pCards.get(i);
  79. }
  80. return sum;
  81. }
  82. public void play() {
  83. if
  84. System.out.println("hit? stay?");
  85.  
  86. }
  87.  
  88. public int hitMe (int a) {
  89. deal();
  90. return 0;
  91. }
  92.  
  93. public static void main(String[] args) {
  94. // TODO Auto-generated method stub
  95.  
  96. Deck playingCards = new Deck();
  97.  
  98. /* **************************Testing Testing*************************
  99. shuffles and displays all cards
  100. playingCards.shuffle(cards);
  101. for (Card i : cards) {
  102. System.out.println(i);
  103. }
  104.  
  105. Dealing Tester
  106. int choice = 1;
  107. while(choice==1) {
  108. System.out.println(playingCards.deal());
  109. Scanner yourDeal = new Scanner(System.in);
  110. System.out.println("Deal? 1=Deal");
  111. choice = yourDeal.nextInt();
  112. System.out.println(cardsInDeck);
  113. }
  114. ***************************Testing Testing************************ */
  115. playingCards.shuffle(cards);
  116. System.out.println("Welcome to Black Jack. You start with $200");
  117. System.out.println("How much money would you like to bet?");
  118. Scanner yourBet = new Scanner(System.in);
  119. int Bet = yourBet.nextInt();
  120. System.out.println("your cards are " + playingCards.deal() + " and " + playingCards.deal());
  121. playingCards.play();
  122.  
  123. // Dealing Tester
  124.  
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement