File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Spring in Action
this week in the
Card game using Collection and map
Joined: Aug 22, 2007
Sep 12, 2007 12:54:00
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%
Joined: Jan 01, 2007
Sep 13, 2007 05:41:00
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
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.
[ September 13, 2007: Message edited by: Gavin Tranter ]
Joined: Feb 21, 2007
Sep 19, 2007 09:02:00
Here's the link Gavin said:
I agree. Here's the link:
subject: Card game using Collection and map
psycho killer poker
Generic Card Program
create a hand of cards
[Error] Can only iterate over an array or an instance of java.lang.Iterable
Poker Challenge of the Day
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014