[Java] 纯文本查看 复制代码
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class PokerDemo {
public static void main(String[] args) {
HashMap<Integer,String> hm = new HashMap<>();
ArrayList<Integer> array = new ArrayList<>();
String[] colors = {"♠","♣","♦","♥"};
String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
int index = 0;
for (String number : numbers) {
for (String color : colors) {
hm.put(index,color+number);
array.add(index);
index++;
}
}
hm.put(index,"大王");
array.add(index);
index++;
hm.put(index,"小王");
array.add(index);
//洗牌
Collections.shuffle(array);
TreeSet<Integer> s1 = new TreeSet<>();
TreeSet<Integer> s2 = new TreeSet<>();
TreeSet<Integer> s3 = new TreeSet<>();
TreeSet<Integer> dp = new TreeSet<>();
for (int i = 0; i < array.size(); i++) {
int s = array.get(i);
if(i >= array.size()-3){
dp.add(s);
}else if(i % 3 == 2 ){
s1.add(s);
}else if(i % 3 == 1){
s2.add(s);
}else if(i % 3 == 0){
s3.add(s);
}
}
lookPoker("s1",s1,hm);
lookPoker("s2",s2,hm);
lookPoker("s3",s3,hm);
lookPoker("底牌",dp,hm);
}
private static void lookPoker(String name, TreeSet<Integer> ts,HashMap<Integer,String> hm) {
System.out.println(name+"的牌是");
for (Integer t : ts) {
String poker = hm.get(t);
System.out.print(poker);
}
System.out.println();
}
}