package com.hehe.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class Doudizhu {
public static void main(String[] args) {
String[] num={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
String[] color={"方片","梅花","红桃","黑桃"};
String[] joker={"joker","Joker"};
ArrayList<Integer> a=new ArrayList<>();
HashMap<Integer, String> hm=new HashMap<Integer, String>();
int index=0;
for (String i : num) {
for (String j : color) {
hm.put(index, j+i);
a.add(index);
index++;
}
}
a.add(index);
hm.put(index, joker[0]);
index++;
a.add(index);
hm.put(index, joker[1]);
Collections.shuffle(a);
TreeSet<Integer> di=new TreeSet<Integer>();
TreeSet<Integer> p1=new TreeSet<Integer>();
TreeSet<Integer> p2=new TreeSet<Integer>();
TreeSet<Integer> p3=new TreeSet<Integer>();
for (int i = 0; i < a.size(); i++) {
if (i>=a.size()-3) {
di.add(a.get(i));
}else if (i%3==0) {
p1.add(a.get(i));
}else if (i%3==1) {
p2.add(a.get(i));
}else {
p3.add(a.get(i));
}
}
look(hm,p1,"p1");
look(hm,p2,"p2");
look(hm,p3,"p3");
look(hm,di,"di");
}
private static void look(HashMap<Integer, String> hm,
TreeSet<Integer> p1, String string) {
System.out.println(string+"的牌是:");
for (Integer i : p1) {
System.out.print(hm.get(i)+" ");
}
System.out.println();
}
} |
|