Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Deck {
- //The single deck of cards for play
- static Card[] deckOfCards = new Card[52];
- //A check for whether the cards are assigned or not
- static boolean assigned = false;
- //Assigns the properties of the cards in the deck
- public static void assignCardProperties(){
- int suit = 0;
- int value = 0;
- String name = "";
- String location = "";
- Image cardImage = null;
- ImageIcon cardIcon = null;
- for(int i = 0; i < 52; i++){
- suit = i / 13;
- value = i % 13;
- assigned = true;
- switch(value){
- case 0: name = "2"; break;
- case 1: name = "3"; break;
- case 2: name = "4"; break;
- case 3: name = "5"; break;
- case 4: name = "6"; break;
- case 5: name = "7"; break;
- case 6: name = "8"; break;
- case 7: name = "9"; break;
- case 8: name = "10"; break;
- case 9: name = "j"; break;
- case 10: name = "q"; break;
- case 11: name = "k"; break;
- case 12: name = "a"; break;
- default: name = "Error"; break;
- }
- name += " of ";
- switch(suit){
- case 0: name += "Clubs"; break;
- case 1: name+= "Diamonds"; break;
- case 2: name += "Hearts"; break;
- case 3: name += "Spades"; break;
- }
- location = "images/" + (i + 1) + ".gif";
- cardImage = createImage(location);
- cardIcon = createImageIcon(location);
- deckOfCards[i] = new Card(value, suit, name, cardImage, cardIcon);
- }
- }
- protected static Image createImage(String path) {
- Toolkit tk = Toolkit.getDefaultToolkit();
- java.net.URL imgURL = gamescreen.class.getResource(path);
- if (imgURL != null) {
- return tk.getImage(imgURL);
- } else {
- System.err.println("Couldn't find file: " + path);
- return null;
- }
- }
- protected static ImageIcon createImageIcon(String path) {
- java.net.URL imgURL = gamescreen.class.getResource(path);
- if (imgURL != null) {
- return new ImageIcon(imgURL);
- } else {
- System.err.println("Couldn't find file: " + path);
- return null;
- }
- }
Add Comment
Please, Sign In to add comment