码迷,mamicode.com
首页 > 编程语言 > 详细

java用集合实现斗地主有序排列

时间:2020-07-02 13:45:45      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:class   map   layer   span   sys   div   imp   import   排列   

import java.util.*;

public class NewDouDiZhu {
    public static void main(String[] args) {
        HashMap<Integer,String> poker= new HashMap<>();
        //1.组装牌
        ArrayList<Integer> suoyin = new ArrayList<>();
        List<String> color =  new ArrayList<>();
        color.add("红桃");
        color.add("方块");
        color.add("黑桃");
        color.add("梅花");
        String[] number = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
        int index = 0;
        for (String n:number){

            for (String c:color){
                poker.put(index,c+n);
                suoyin.add(index);
                index++;
            }
        }
        poker.put(index++,"大王");
        poker.put(index++,"小王");
        System.out.println(poker);
        System.out.println(suoyin);
        //2.洗牌
        Collections.shuffle(suoyin);
        System.out.println(suoyin);
        //3.发牌

        ArrayList<Integer> player1 = new ArrayList<>();
        ArrayList<Integer> player2 = new ArrayList<>();
        ArrayList<Integer> player3 = new ArrayList<>();
        ArrayList<Integer> dipai = new ArrayList<>();
        for (int n =0;n<suoyin.size();n++) {
            Integer in = suoyin.get(n);
            if (n>=50){
                dipai.add(in);
            }else if (n%3==0){
                player1.add(in);
            }else if (n%3==1){
                player2.add(in);
            }else if(n%3==2){
                player3.add(in);
            }
        }
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);
        System.out.println("底牌是: "+dipai);
        System.out.println(player1);
        System.out.println(player3);
        System.out.println(player2);
        //看牌
        for (Integer s:player1){

            String pai =poker.get(s);
            System.out.print(pai+" ");
        }

    }


}

 

java用集合实现斗地主有序排列

标签:class   map   layer   span   sys   div   imp   import   排列   

原文地址:https://www.cnblogs.com/yeqingyun/p/13223946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!