import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* Author:danagao
* java 发牌程序,
* 不含大王,小王
* 可设定发牌人数
*/
public class Pai {
HashMap<String, String> map = new HashMap<String, String>();
private static final String[] colors = {"红桃", "方块", "梅花", "黑桃"};
private static final String[] values = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
private String[] newpai; private int len;
//初始化52张牌
public Pai() {
len = colors.length * values.length;
newpai = new String[len];
int k = 0;
for (int i = 0; i < colors.length; i++) {
for (int j = 0; j < values.length; j++) {
newpai[k] = colors[i] + values[j];
k++;
}
}
}
//洗牌(把牌打乱)
private void getNums() {
Random r = new Random();
int i = r.nextInt(len);
String s;
if (i >= 0 && !map.containsKey(String.valueOf(i))) {
s = String.valueOf(i);
map.put(s, newpai[i]);
} else {
getNums();
}
}
//发牌
public void showResult(int p) {
for (int i = 0; i < len; i++) {
getNums();
}
int l = len/p; //每人发几张牌
int j=1;//计人数
int |
|