package com.heima.poker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class Poker {
public static void main(String[] args) {
// 创建扑克
ArrayList<Integer> list = new ArrayList<>();
String[] num = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q",
"K", "A", "2" };
String[] color = { "黑桃", "红桃", "梅花", "方片" };
HashMap<Integer, String> hs = new HashMap<>();
int index = 0;
for (String s1 : num) {
for (String s2 : color) {
hs.put(index, s2.concat(s1));
list.add(index);
index++;
}
}
list.add(index);
hs.put(index, "小王");
index++;
list.add(index);
hs.put(index, "大王");
// System.out.println(list);
// 洗牌
Collections.shuffle(list);
// 创建玩家
ArrayList<Integer> zhengkai = new ArrayList<>();
ArrayList<Integer> sukaihua = new ArrayList<>();
ArrayList<Integer> wo = new ArrayList<>();
ArrayList<Integer> dipai = new ArrayList<>();
// 发牌
for (int i = 0; i < list.size(); i++) {
if (i >= list.size() - 3) {
dipai.add(list.get(i));
} else if (i % 3 == 0) {
zhengkai.add(list.get(i));
} else if (i % 3 == 1) {
sukaihua.add(list.get(i));
} else {
wo.add(list.get(i));
}
}
// 看牌"
System.out.print("郑凯的手牌:\t");
lookPoker(zhengkai, hs);
System.out.print("苏凯华的手牌:\t");
lookPoker(sukaihua, hs);
System.out.print("窦继瑶的手牌:\t");
lookPoker(wo, hs);
System.out.print("底牌:");
lookPoker(dipai, hs);
}
// 显示牌
public static void lookPoker(ArrayList<Integer> wanjia,HashMap<Integer, String> poker) {
TreeSet<Integer> ts = new TreeSet<>();
for (int i = 0; i < wanjia.size(); i++) {
ts.add(wanjia.get(i));
}
for(Integer i : ts) {
System.out.print(poker.get(i) + " ");
}
System.out.println("共有" + ts.size() + "张牌");
}
}
|
|