Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public class Deck {
  2. //The single deck of cards for play
  3. static Card[] deckOfCards = new Card[52];
  4. //A check for whether the cards are assigned or not
  5. static boolean assigned = false;
  6.  
  7. //Assigns the properties of the cards in the deck
  8. public static void assignCardProperties(){
  9. int suit = 0;
  10. int value = 0;
  11. String name = "";
  12. String location = "";
  13. Image cardImage = null;
  14. ImageIcon cardIcon = null;
  15.  
  16.  
  17.  
  18. for(int i = 0; i < 52; i++){
  19.  
  20. suit = i / 13;
  21. value = i % 13;
  22. assigned = true;
  23.  
  24. switch(value){
  25. case 0: name = "2"; break;
  26. case 1: name = "3"; break;
  27. case 2: name = "4"; break;
  28. case 3: name = "5"; break;
  29. case 4: name = "6"; break;
  30. case 5: name = "7"; break;
  31. case 6: name = "8"; break;
  32. case 7: name = "9"; break;
  33. case 8: name = "10"; break;
  34. case 9: name = "j"; break;
  35. case 10: name = "q"; break;
  36. case 11: name = "k"; break;
  37. case 12: name = "a"; break;
  38. default: name = "Error"; break;
  39. }
  40.  
  41. name += " of ";
  42.  
  43. switch(suit){
  44. case 0: name += "Clubs"; break;
  45. case 1: name+= "Diamonds"; break;
  46. case 2: name += "Hearts"; break;
  47. case 3: name += "Spades"; break;
  48. }
  49. location = "images/" + (i + 1) + ".gif";
  50. cardImage = createImage(location);
  51. cardIcon = createImageIcon(location);
  52. deckOfCards[i] = new Card(value, suit, name, cardImage, cardIcon);
  53. }
  54. }
  55. protected static Image createImage(String path) {
  56. Toolkit tk = Toolkit.getDefaultToolkit();
  57. java.net.URL imgURL = gamescreen.class.getResource(path);
  58. if (imgURL != null) {
  59. return tk.getImage(imgURL);
  60. } else {
  61. System.err.println("Couldn't find file: " + path);
  62. return null;
  63. }
  64. }
  65. protected static ImageIcon createImageIcon(String path) {
  66. java.net.URL imgURL = gamescreen.class.getResource(path);
  67. if (imgURL != null) {
  68. return new ImageIcon(imgURL);
  69. } else {
  70. System.err.println("Couldn't find file: " + path);
  71. return null;
  72. }
  73. }
Add Comment
Please, Sign In to add comment