Guest User

Untitled

a guest
Feb 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public class Deck {
  2. private Card[] draw; //draw pile
  3. private Card[] discard; //discard pile
  4. private int numDraw; //how many cards in the draw pile
  5. private int numDiscard; //how many cards in discard pile
  6.  
  7. /**
  8. * Creates a 52 card standard deck, in order.
  9. */
  10. public Deck() {
  11. draw = new Card[52];
  12. discard = new Card[52];
  13. numDraw = 52;
  14. numDiscard = 0;
  15.  
  16. for(int i = 0; i < 4; i++) { //i is the suit
  17. for(int j = 1; j <= 13; j++) { //j is the rank
  18. int x = i*13 + j - 1; //the index where this card goes
  19. draw[x] = new Card(i, j);
  20. }
  21. }
  22. }
  23.  
  24. /**
  25. * Returns a card in the draw pile.
  26. * @param i the index of the card to return
  27. * @return the card at the given index
  28. */
  29. public Card cardAt(int i) {
  30. return draw[i];
  31. }
  32.  
  33. public String toString() {
  34. String ret = "draw pile: ";
  35. for(int q = 0; q < numDraw-1; q++) {
  36. ret = ret + draw[q] + ", ";
  37. }
  38. ret = ret + draw[numDraw-1];
  39. return ret;
  40. }
  41. }
Add Comment
Please, Sign In to add comment