View Single Post
  #3 (permalink)  
Old 09-11-2008, 05:34 PM
serjant's Avatar
serjant serjant is offline
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 356
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
Code:
static void cardList(int numHands,int cardsPerHand){ List<String> deck,hand; //52-card deck Srting[] suit=new String[]{"S","H","D","C"}; String[] rank=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; deck=new ArrayList<String>(); for(int i=0;i<deck.length;i++){ for(int j=i;j<deck.length;j++){ deck.add(rank[i]+"-"+suit[j]); } } Collections.shuffle(deck);//shuffles the heap of the crads //dealing the cards for(int i=0;i<numHands;i++){ hand=deck.subList(deck.size()-cardsPerHand,deck.size()); System.out.println(hand); //hand.clear();//removes the sub-list from the list } }
Look, the parameter numHands is how much people are playing the card game,and parameter cardsPerHand indicates the amount the cards to deal to each player.
Reply With Quote