package Poker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class Poker {
public static void main(String[] args) {
List<Integer> ls=new ArrayList<>();
Map<Integer, String> m=new HashMap<Integer, String>();
// String[] s1={"♔","♛"};
String[] s2={"♦","♣","♥","♠"};
String[] s3={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
int num=0;
for (String sss : s3) {
for (String ss : s2) {
m.put(num, ss.concat(sss));
ls.add(num);
num++;
}
}
m.put(num,"♛" );
ls.add(num);
num++;
m.put(num, "♔");
ls.add(num);
//洗牌
Collections.shuffle(ls);
//定义玩家
Set<Integer> kcj=new TreeSet<>();
Set<Integer> wd=new TreeSet<>();
Set<Integer> yyy=new TreeSet<>();
Set<Integer> dipai=new TreeSet<>();
//发牌
for (int i = 0; i < ls.size(); i++) {
if(i>=ls.size()-3){
dipai.add(ls.get(i));
}else if(i%3==0){
kcj.add(ls.get(i));
}else if(i%3==1){
wd.add(ls.get(i));
}else if(i%3==2){
yyy.add(ls.get(i));
}
}
//看牌
kanpai("张飞",m, kcj);
kanpai("关羽",m, wd);
kanpai("刘备",m, yyy);
kanpai("底牌",m, dipai);
}
private static void kanpai(String name,Map<Integer, String> m, Set<Integer> ts) {
System.out.print(name+"的牌是:"+"\t");
for (Integer key : ts) {
String value=m.get(key);
System.out.print(value+" ");
}
System.out.println();
}
}
|