Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package oving3;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import acm.graphics.GImage;
  6.  
  7. import acm.program.GraphicsProgram;
  8.  
  9.  
  10. /*
  11. * @startuml
  12. * class Card {
  13. * String suit
  14. * int face
  15. * }
  16. * class CardDeck {
  17. * +Card getCard(int i)
  18. * }
  19. * CardDeck --> "*" Card : cards
  20. * @enduml
  21. */
  22.  
  23. public class CardDeck extends GraphicsProgram {
  24.  
  25. ArrayList<Card> cards;
  26.  
  27. public void init(){
  28. final String suits = "SHDC";
  29. cards = new ArrayList<Card>();
  30. for (int i = 0; i <= suits.length(); i++) {
  31. for(int face = 1; face <= 13; face++){
  32. Card card = new Card();
  33. if (i == 0) card.suit = "S";
  34. else if (i == 1) card.suit = "H";
  35. else if (i == 2) card.suit = "D";
  36. else if (i == 3) card.suit = "C";
  37. card.face = face;
  38. cards.add(card);
  39. }
  40. }
  41. }
  42. public void run(){
  43. for (int i = 0; i <= 3; i++) {
  44. for (int j = 1; j <= 13; j++) {
  45. if(i==0){
  46. GImage image = createGImage(getCard(i).suit, getCard(j).face);
  47. image.setLocation(j*100,25);
  48. add(image);
  49. }
  50. if(i==1){
  51. GImage image = createGImage(getCard(i+12).suit, getCard(j).face);
  52. image.setLocation(j*100,250);
  53. add(image);
  54. }
  55. if(i==2){
  56. GImage image = createGImage(getCard(i+24).suit, getCard(j).face);
  57. image.setLocation(j*100,450);
  58. add(image);
  59. }
  60. if(i==3){
  61. GImage image = createGImage(getCard(i+36).suit, getCard(j).face);
  62. image.setLocation(j*100,650);
  63. add(image);
  64. }
  65. }
  66. }
  67. }
  68.  
  69.  
  70. GImage createGImage(String suit, int value) {
  71. String name="";
  72. switch(suit.charAt(0)){
  73. case 'H':
  74. name+="hearts";
  75. break;
  76. case 'D':
  77. name+="diamonds";
  78. break;
  79. case 'C':
  80. name+="clubs";
  81. break;
  82. case 'S':
  83. name+="spades";
  84. break;
  85. }
  86. name+="-";
  87. switch(value) {
  88. case 1:
  89. name+="a";
  90. break;
  91. case 11:
  92. name+="j";
  93. break;
  94. case 12:
  95. name+="q";
  96. break;
  97. case 13:
  98. name+="k";
  99. break;
  100. default:
  101. name+="" + value;
  102. }
  103.  
  104. name+="-150.png";
  105. return new GImage("oving3/img/" + name);
  106. }
  107. public Card getCard(int i) {
  108. return cards.get(i);
  109. }
  110.  
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement