Creating a deck of cards in java?
ok, i'm not actually looking for an answer here, just hints to the answer, i'm not going to really learn anything if somebody just gives me the answer.
Also, i'm not posting code because yahoo answers will remove most of it.
I have 1 class named Cards.
This class creates the card object. This object contains
int value;
string suit;
string name;
Name is just a save space until we start doing some GUI stuff.
In a second class named deck i have created an object array for the cards.
the array is of 54 cards (52 normal cards, 2 jokers)
however, my problem is creating the cards to put in the array, i could easily create each card individually, but i want to keep the code to a minimum.
cards tempCard = new cards(1, "clubs", "ace of clubs"
What i need really is some way of creating a loop which'd increment the value of the card until i reaches a value of 13. and once value = 13, changes to the next suit. And adding the jokers after this loop has completed.
Right now the best thing i can think of for increasing the value is a for loop, however i'm just wondering if i can implament the suit changing bit inside of the same loop, instead of doing a loop within a loop.
I'm probably not making any sense but if somebody has a clue about what i'm on about and can give me hints (not hte exact answer i still wanna work this out myself) it'd be appreciated.
ok, i've settled on a method for creating this. Or rather remembered a method >.>
basically, its a for loop with if statments inside
for count < 52
count++
if count < 14
suit = Spades
value = count
if count < 27 && >= 14
suit = Hearts
value = count - 13
and it goes on like that till all 4 suits are filled in and added to an array which is used to represent the deck. Seems simple enough.
|