Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Card game using Collection and map

 
Madhawi Maurya
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the link Gavin said: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic