首页 > 其他 > 详细

斗地主的需求分析案列

时间:2020-05-10 19:50:18      阅读:55      评论:0      收藏:0      [点我收藏+]

 

 

 技术分享图片

public class Demo_Fight {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List<String> colors =new ArrayList<>();
        Collections.addAll(colors, "♦","♥","♠","♣");
        List<String> numbers = new ArrayList<>();
        Collections.addAll(numbers, "2","A","K","Q","J","10","9","8","7","6","5","4","3");
        //创建一个List集合,存储牌的索引
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        Map<Integer,String> map = new HashMap<>() ;
        int index=0;
        pokerIndex.add(index);
        map.put(index++, "大王");
        pokerIndex.add(index);
        map.put(index++, "小王");
        
        for(String num:numbers) {
            for(String s:colors) {
                pokerIndex.add(index);
                map.put(index++, s+num);
            }
        }
        //System.out.println(map);
        //System.out.println(pokerIndex);
        
        //根据牌的索引来洗牌
        Collections.shuffle(pokerIndex);
        
        //发牌
        ArrayList<Integer> deep = new ArrayList<>();
        ArrayList<Integer> player1 = new ArrayList<>();
        ArrayList<Integer> player2 = new ArrayList<>();
        ArrayList<Integer> player3 = new ArrayList<>();
        for(int i=0;i<54;i++) {
            if(i>=51) {
                deep.add(pokerIndex.get(i));
            }
            else if(i%3==0) {
                player1.add(pokerIndex.get(i));
            }
            else if(i%3==1) {
                player2.add(pokerIndex.get(i));
            }
            else if(i%3==2) {
                player3.add(pokerIndex.get(i));
            }
        }
        //System.out.println(player1);
        
        //分别排序
        Collections.sort(deep);
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);
        //System.out.println(player1);
        
        //获取牌索引对应的牌
        lookPoker("小明",player1,map);
        lookPoker("小光",player2,map);
        lookPoker("小强",player3,map);
        lookPoker("底牌",deep,map);
        
    }
    public static void lookPoker(String name,List<Integer> player,Map<Integer,String> map) {
        System.out.print(name+"的牌是:"); 
        for(int i=0;i<player.size();i++) {
            System.out.print(map.get(player.get(i))+" "); 
        }
        System.out.println();
    }

 

斗地主的需求分析案列

原文:https://www.cnblogs.com/cocobear9/p/12864216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!