模拟一副扑克牌洗牌发牌
模拟一副扑克牌(不包括大小王),然后写一个方法,模拟洗牌行为。再写一个方法,将扑克牌发给4个玩家,最后输出每个玩家手里拿到的12张扑克牌。
public class MyTest02 {
public static void main(String[] args) {
List xiPai = xi_pai();
System.out.println(xiPai);
System.out.println("==================");
// 洗牌
Collections.shuffle(xiPai);
System.out.println("洗牌后:" + xiPai);
// 四个玩家
ArrayList<Object> A = new ArrayList<>();
ArrayList<Object> B = new ArrayList<>();
ArrayList<Object> C = new ArrayList<>();
ArrayList<Object> D = new ArrayList<>();
//发牌
for (int i = 0; i < xiPai.size(); i ++){
if (i % 4 == 0){
A.add(xiPai.get(i));
}else if (i % 4 == 1){
B.add(xiPai.get(i));
}else if (i % 4 == 2){
C.add(xiPai.get(i));
}else if (i % 4 == 3){
D.add(xiPai.get(i));
}
}
// 输出玩家的底牌
System.out.println("玩家1" + A);
System.out.println("玩家2" + B);
System.out.println("玩家3" + C);
System.out.println("玩家4" + D);
}
private static List xi_pai() {
List list = new ArrayList<>();
String[] huase = {"梅花","方块","红心","黑桃"};
String[] num = {"A","1","2","3","4","5","6","8","9","10","J","Q","K"};
for (String h : huase) {
for (String n : num) {
list.add(h + n);
}
}
return list;
}
}


浙公网安备 33010602011771号