aspose file tools*
The moose likes Game Development and the fly likes Card game using Collection and map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Card game using Collection and map" Watch "Card game using Collection and map" New topic
Author

Card game using Collection and map

Madhawi Maurya
Ranch Hand

Joined: Aug 22, 2007
Posts: 42
Help me in Java program that hands out playing cards to the players. It should take as input the numberOfPlayers and the numberOfCards to be dealt to each player. Each player will get an equal number of cards.


SCJP1.5 with 90%
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
I am working (well currently its on hold) on a card game, what you are asking is the easy part of the card game, the hard part I am finding is implementing the games rules.

I dont have the code to hand:

You create an enum of card suits,
Then you create a card class.

Then from there your options expand, your first choice is how you handle Ace, Jack, Queen, King. I am currently considering doing this as a second enum.

you then create a collection, I think I used a list as it has a shuffle functions. The collection is your deck of cards.

After that how players get cards and the number they get is standard java code stuff, loops and if's.

The one thing I did was create a player class, with the player holding their own cards so to speak.

Oh also, if you check out the java tutorial for Colelctions on the sun java site you will find a card game example.

G
[ September 13, 2007: Message edited by: Gavin Tranter ]
Tamas Jano
Ranch Hand

Joined: Feb 21, 2007
Posts: 55
Here's the link Gavin said: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Card game using Collection and map