I just started out trying to make a simple card game as of last night.
My problem is on line 16 and 17 of the first file. I have successfully created the 52 objects with variables for the cards, and once created they are placed into a Vector (the deck). Just to test it worked I used the below code, but the name is underlined and I get the error
name cannot be resolved or is not a field.
Does anyone know why this may be? The objects are deffinately in the Vector, I just can't get to the variables they contain.
Thanks.
Code:
Object ob = (Object) Cards.deck.get(i);
System.out.println(ob.name);
****head.java
PHP Code:
import javax.swing.JOptionPane;
public class ****head {
public ****head() {
int p = 0;
for (int i = 0; i < Cards.allCards.length; i++) {
p = p != 13 ? p : 0;
Cards card = new Cards();
card.name = Cards.allCards[i];
card.cardValue = p + 1;
card.imgPath = "images\\cards\\" + card.name + ".gif";
Cards.deck.add(card);
Object ob = (Object) Cards.deck.get(i);
System.out.println(ob.name);
p++;
}
}
public static void main(String[] args) {
****head sh = new ****head();
}
}
Cards.java
PHP Code:
import java.util.Vector;
public class Cards {
static String[] allCards = {
"A-Hearts", "2-Hearts", "3-Hearts", "4-Hearts", "5-Hearts",
"6-Hearts", "7-Hearts", "8-Hearts", "9-Hearts", "10-Hearts",
"J-Hearts", "Q-Hearts", "K-Hearts",
"A-Dimonds", "2-Dimonds", "3-Dimonds", "4-Dimonds", "5-Dimonds",
"6-Dimonds", "7-Dimonds", "8-Dimonds", "9-Dimonds", "10-Dimonds",
"J-Dimonds", "Q-Dimonds", "K-Dimonds",
"A-Clubs", "2-Clubs", "3-Clubs", "4-Clubs", "5-Clubs",
"6-Clubs", "7-Clubs", "8-Clubs", "9-Clubs", "10-Clubs",
"J-Clubs", "Q-Clubs", "K-Clubs",
"A-Spades", "2-Spades", "3-Spades", "4-Spades", "5-Spades",
"6-Spades", "7-Spades", "8-Spades", "9-Spades", "10-Spades",
"J-Spades", "Q-Spades", "K-Spades"
};
static String name;
static int cardValue;
static String imgPath;
static Vector <Object> deck = new Vector<Object>(allCards.length);
public Cards() { }
}