package com.map;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
//斗地主
public class Test_Game {
public static void main(String[] args) {// TODO Auto-generated method stubString[] num = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2" };String[] color = { "梅花", "方片", "黑桃", "红心" };HashMap<Integer, String> hm = new HashMap<>();ArrayList<Integer> list = new ArrayList<>(); // 存储索引int index = 0;for (String s1 : num) {for (String s2 : color) {hm.put(index, s2.concat(s1)); // 连接两个字符串并添加到hm中list.add(index);index++;}}hm.put(index, "大王");list.add(index);index++;hm.put(index, "小王");list.add(index);// 洗牌Collections.shuffle(list); //随机置换// 发牌TreeSet<Integer> gaojin = new TreeSet<>();TreeSet<Integer> longwu = new TreeSet<>();TreeSet<Integer> me = new TreeSet<>();TreeSet<Integer> dipai = new TreeSet<>();for (int i = 0; i < list.size(); i++) {if (i >= list.size() - 3) { //底牌dipai.add(list.get(i));} else if (i % 3 == 0) { //高进gaojin.add(list.get(i));} else if (i % 3 == 1) { //龙五longwu.add(list.get(i));} else if (i % 3 == 2) { //我me.add(list.get(i));}}//看牌
lookpoker(hm,gaojin,"高进");
lookpoker(hm,longwu,"龙五");
lookpoker(hm,me,"我");
lookpoker(hm,dipai,"底牌");
}
public static void lookpoker(HashMap<Integer, String>hm,TreeSetts,String name) {
System.out.println(name+“的牌是”);
for (Integer i : ts) {
System.out.println(hm.get(i));
}
System.out.println();
}
}