public class Demo {
public static void main(String[] args) {
//创建一副扑克牌
String[] arr = {"黑桃","红桃","方片","梅花"};
String[] arr2 = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
ArrayList<String> al = new ArrayList<String>();
al.add("大王");
al.add("小王");
for(String x : arr){
for(String y : arr2){
al.add(x.concat(y));
}
}
System.out.println(al);
//洗牌
Collections.shuffle(al);
System.out.println(al);
//发牌
ArrayList<String> player01 = new ArrayList<String>();
ArrayList<String> player02 = new ArrayList<String>();
ArrayList<String> player03 = new ArrayList<String>();
for(int x = 0; x<al.size()-3; x++){
if(x%3==0){
player01.add(al.get(x));
}else if(x%3==1){
player02.add(al.get(x));
}else if(x%3==2){
player03.add(al.get(x));
}
}
System.out.println("玩家1:"+player01);
System.out.println("玩家2:"+player02);
System.out.println("玩家3:"+player03);
for(int x = al.size()-3;x<al.size();x++){
System.out.print(al.get(x)+" ");
}
}
}
|
|