- package doudizhu1;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.TreeSet;
- public class Test {
- 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> hs=new HashMap<Integer, String>();
- ArrayList<Integer> list=new ArrayList<Integer>();
- int index=0;
- for(String a:num){
- for (String b:color){
- list.add(index);
- hs.put(index++, b.concat(a));
- }
- }
- list.add(index);
- hs.put(index++, "小王");
- list.add(index);
- hs.put(index, "大王");
-
- TreeSet<Integer> dipai= new TreeSet<Integer>();
- TreeSet<Integer> wo= new TreeSet<Integer>();
- TreeSet<Integer> ni= new TreeSet<Integer>();
- TreeSet<Integer> ta= new TreeSet<Integer>();
- Collections.shuffle(list);
- for(int i=0;i<list.size();i++){
- if(i>=list.size()-3){
- dipai.add(list.get(i));
- }else if(i%3==1){
- wo.add(list.get(i));
- }else if(i%3==0){
- ni.add(list.get(i));
- }else{
- ta.add(list.get(i));
- }
- }
- lookpork("小明",hs,wo);
- lookpork("小高",hs,ni);
- lookpork("小亮",hs,ta);
- lookpork("底牌",hs,dipai);
-
-
- }
- public static void lookpork(String name,HashMap<Integer, String> hs,TreeSet<Integer> di){
- System.out.print(name+"牌是 ");
- for(Integer i:di){
- System.out.print(hs.get(i)+" ");
- }
- System.out.println();
- }
- }
复制代码 |
|