参考文章:
http://www.cnblogs.com/Jax/archive/2008/07/19/1246692.html
http://bbs.csdn.net/topics/80333258
--------------------------------------------------------------------------------------------------------------------------------------------------
桥牌发牌类:
import java.util.*; import java.math.*; //桥牌发牌类 public class Poker { static List<Integer> pokerN=new ArrayList<Integer>(new Integer(13));//北家的牌 static List<Integer> pokerE=new ArrayList<Integer>(new Integer(13));//东家的牌 static List<Integer> pokerS=new ArrayList<Integer>(new Integer(13));//南家的牌 static List<Integer> pokerW=new ArrayList<Integer>(new Integer(13));//西家的牌 static List<Integer> pokerAll=new ArrayList<Integer>(new Integer(52));//52张牌 //洗牌 public static void Shuffle() { for(int i=1;i<=52;i++) { pokerAll.add(i); } Random rd=new Random(); int tmp=0,idx=0; for(int i=0;i<52;i++) { idx=rd.nextInt(52); tmp=pokerAll.get(i); pokerAll.set(i,pokerAll.get(idx)); pokerAll.set(idx, tmp); } } //获取北家的牌 public static List<Integer> getPokerN() { for(int i=0;i<13;i++) { pokerN.add(pokerAll.get(i));//0~12 } return pokerN; } //获取东家的牌 public static List<Integer> getPokerE() { for(int i=0;i<13;i++) { pokerE.add(pokerAll.get(i+13));//13~25 } return pokerE; } //获取南家的牌 public static List<Integer> getPokerS() { for(int i=0;i<13;i++) { pokerS.add(pokerAll.get(i+26));//26~38 } return pokerS; } //获取西家的牌 public static List<Integer> getPokerW() { for(int i=0;i<13;i++) { pokerW.add(pokerAll.get(i+39));//39~51 } return pokerW; } }
测试代码:
import java.util.*; public class main { /** * @param args */ public static void main(String[] args) { Poker.Shuffle();//洗牌 System.out.print("\n北家的牌:"); List<Integer> list=Poker.getPokerN(); for(int i=0;i<list.size();i++) { System.out.printf("%-3d ",list.get(i)); } System.out.print("\n东家的牌:"); list=Poker.getPokerE(); for(int i=0;i<list.size();i++) { System.out.printf("%-3d ",list.get(i)); } System.out.print("\n南家的牌:"); list=Poker.getPokerS(); for(int i=0;i<list.size();i++) { System.out.printf("%-3d ",list.get(i)); } System.out.print("\n西家的牌:"); list=Poker.getPokerW(); for(int i=0;i<list.size();i++) { System.out.printf("%-3d ",list.get(i)); } System.out.println(); } }
效果截图:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
您的十分满意是我追求的宗旨。
您的一点建议是我后续的动力。