import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class Poker_GameDemo {
public static void main(String[] args) {
String[] num = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q",
"K", "A", "2" };
String[] color = { "♠", "♥", "♣", "♦" };
HashMap<Integer, String> poker = new HashMap<>();
ArrayList<Integer> list = new ArrayList<>();
TreeSet<Integer> one = new TreeSet<>();
TreeSet<Integer> two = new TreeSet<>();
TreeSet<Integer> three = new TreeSet<>();
TreeSet<Integer> other = new TreeSet<>();
int x = 0;
for (int j = 0; j < num.length; j++) {
for (int i = 0; i < color.length; i++) {
list.add(x);
poker.put(x, color[i] + num[j]);
x++;
}
}
poker.put(x, "小王");
list.add(x);
x++;
poker.put(x, "大王");
list.add(x);
Collections.shuffle(list);
for (int i = 0; i < list.size(); i++) {
if (i >= list.size() - 3) {
other.add(list.get(i));
} else if (i % 3 == 1) {
one.add(list.get(i));
} else if (i % 3 == 2) {
two.add(list.get(i));
} else {
three.add(list.get(i));
}
}
showpoker(poker, one, "我");
showpoker(poker, two, "你");
showpoker(poker, three, "他");
showpoker(poker, other, "底面");
}
public static void showpoker(HashMap<Integer, String> hm,
TreeSet<Integer> tr, String s) {
if (s == "我" || s == "你" || s == "他" || s == "底面") {
System.out.print(s + "的牌是:");
for (Integer t : tr) {
System.out.print(hm.get(t)+" ");
}
} else {
System.out.println("没有此人");
}
System.out.println();
}
} |
|