Connection problem in Enum
enum Cards {
ENERGY(6),
CORVETE(2),
BATTLE_HAMMER(2),
BATTLE_CRUISER(2),
BATTLE_AXE(2),
COLONY_SHIP(2),
CONSTRUCTOR(2),
DEFENDER(2),
FRIGATE(2),
SCOUT(2),
STAR_FIGHTER(2),
STAR_HAWK(2),
SURVEY_SHIP(2),
TRANSPORT(2);
private int count;
public int deckRand;
Cards(int count) {
this.count = count;
}
public int getCount() {return count;}
}
class Card {
public Cards type;
Card(Cards type){
this.type = type;
}
public Cards getType() {
return type;
}
}
class CardDeck { // construct a deck
List<Card> deck;
CardDeck() { // constructor
deck = new ArrayList<Card>();
for (Cards type : Cards.values()) {
for(int i=0;i<type.getCount();i++){
deck.add(new Card(type));
}
}
System.out.println(deck);
Collections.shuffle(deck);
for (Card element : deck)
System.out.println(element);
}
}
public class GalCivMain extends JFrame {.......................
I have here an enum. In main class I need to find out if the card on FE. 12th place is ENERGY or not. And I also don't know, how to write it (I mean how to write if the card on 12th place is ENERGY, do sth.. Could anyone help me pls? Thanks for reacting.
Re: Connection problem in Enum
Which part of this is giving you trouble? Seeing what is stored in a specific index? Comparing two emum values for equality? Something else?
Re: Connection problem in Enum
I don't know how to reffer to the enum. For example, I have one chosen card and in my main class I need to find out, which type is chosen. FE if card chosen is ENERGY, do sth. If not, do sth else. But I don't know how to reffer to the enum.
Re: Connection problem in Enum
ok, I'll give you an example. I wrote there Collections.shuffle. I just need to check if the deck is shuffled. I wanted to write System.out.println(" and here is written the name of the card, but sth like "galciv.Card@7a3570b0" but I need to see here just "ENERGY" - the concrete name of the card"). Do you understand?
Re: Connection problem in Enum
ok, I'll give you an example. I wrote there Collections.shuffle. I just need to check if the deck is shuffled. I wanted to write System.out.println(" and here is written the name of the card, but sth like "galciv.Card@7a3570b0" but I need to see here just "ENERGY" - the concrete name of the card"). Do you understand? :-)
Re: Connection problem in Enum
ok, I'll give you an example. I wrote there Collections.shuffle. I just need to check if the deck is shuffled. I wanted to write System.out.println(" and here is written the name of the card, but sth like "galciv.Card@7a3570b0" but I need to see here just "ENERGY" - the concrete name of the card"). Do you understand?
Re: Connection problem in Enum
Does it work?
--- Update ---
I have there Collections.shuffle. I need to check, if the deck is really suffled, so I want to add there System.out.println("and here the name of the each cards"). But if I do it, I just get value like "galciv.Card@6627e353". But I need there value like "ENERGY" - the real name of the card.
Re: Connection problem in Enum
You're already referring to the enum, when you iterate over its values:
for (Cards type : Cards.values()) {
To refer to a specific enum instance, you just use the enum name followed by the enum instance name: Cards.ENERGY, for example.
For more info, check out the enum tutorial: Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
--- Update ---
I'm really not sure what you're trying to do. I suggest you put together an SSCCE that demonstrates exactly, and only, what you're trying to do. Posting your whole program without the code you're actually confused about makes it harder to give you good answers.
Re: Connection problem in Enum
I just put only the beginning of the program, the program itself has over 400 lines. I have there Collection.shuffle - I want to shuffle the deck. To check out, if it is really shuffled, I want to add there System.out.println("here the name of each card"). I got value like "galciv.Card@6627e353" but I in fact want sth like "ENERGY" - the real name of the card.
Re: Connection problem in Enum
OMG, I can't even send a message here: it write "Thank you for posting! Your post will not be visible until a moderator has approved it for posting.
Re: Connection problem in Enum
I just put only the beginning of the program, the program itself has over 400 lines. I have there Collection.shuffle - I want to shuffle the deck. To check out, if it is really shuffled, I want to add there System.out.println("here the name of each card"). I got value like "galciv.Card@6627e353" but I in fact want sth like "ENERGY" - the real name of the card.
Re: Connection problem in Enum
I just put only the beginning of the program, the program itself has over 400 lines. I have there Collection.shuffle - I want to shuffle the deck. To check out, if it is really shuffled, I want to add there System.out.println("here the name of each card"). I got value like "galciv.Card@6627e353" but I in fact want sth like "ENERGY" - the real name of the card. :-)
Re: Connection problem in Enum
Like I said, it's pretty hard to help you without an SSCCE. Keep in mind that an SSCCE should be as short as possible and only contain the relevant code.