import java.util.ArrayList;
import java.util.Collections;
public class DouDiZhuDemo {
public static void main(String[] args) {
String[] flowers = {"♠", "♥", "♣", "♦"};
String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
ArrayList<String> box = new ArrayList<>();
for (String flower : flowers) {
for (String number : numbers) {
String poke = flower + number;
box.add(poke);
}
}
box.add("joker");
box.add("JOKER");
box.add("赖子");
Collections.shuffle(box);
ArrayList<String> 地主牌 = new ArrayList<>();
ArrayList<String> 周润发 = new ArrayList<>();
ArrayList<String> 周星驰 = new ArrayList<>();
ArrayList<String> 刘德华 = new ArrayList<>();
地主牌.add(box.get(box.size() - 1));
地主牌.add(box.get(box.size() - 2));
地主牌.add(box.get(box.size() - 3));
地主牌.add(box.get(box.size() - 4));
for (int i = 0; i < box.size() - 4; i++) {
if (i % 3 == 0) {
周润发.add(box.get(i));
}
if (i % 3 == 1) {
周星驰.add(box.get(i));
}
if (i % 3 == 2) {
刘德华.add(box.get(i));
}
}
OrderDemo od = new OrderDemo();
Collections.sort(周润发, od);
Collections.sort(周星驰, od);
Collections.sort(刘德华, od);
Collections.sort(地主牌, od);
System.out.println("周润发 = " + 周润发);
System.out.println("周星驰 = " + 周星驰);
System.out.println("刘德华 = " + 刘德华);
System.out.println("地主牌 = " + 地主牌);
}
}
import java.util.Comparator;
import java.util.List;
public class OrderDemo implements Comparator<String> {
List<String> order = List.of("3", "4", "5", "6", "7", "8", "9", "1", "J", "Q", "K", "A", "2", "o", "O", "子");
@Override
public int compare(String o1, String o2) {
char c1 = o1.charAt(1);
char c2 = o2.charAt(1);
int i1 = order.indexOf(c1 + "");
int i2 = order.indexOf(c2 + "");
return i1 - i2;
}
}