2021.5.30笔记 可以按顺序的斗地主牌

基本图解

在这里插入图片描述

代码实现(需要JDK9)

public class NewPractice {
    public static void main(String[] args) {
        HashMap<Integer, String> concret = new HashMap<>();
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        List<String> pokerPat = List.of("♥", "♠", "♣", "♦");
        List<Integer> pokerNum = List.of("3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2");
        int index = 0;
        concret.put(index,"大王");
        pokerIndex.add(index);
        index++;
        concret.put(index,"大王");
        pokerIndex.add(index);
        index++;
        for (String patt : pokerPat) {
            for (Integer numm : pokerNum) {
                concret.put(index,patt + numm);
                pokerIndex.add(index);
                index++;
            }
        }
        Collections.shuffle(pokerIndex);
        ArrayList<Integer> parti01 = new ArrayList<>();
        ArrayList<Integer> parti02 = new ArrayList<>();
        ArrayList<Integer> parti03 = new ArrayList<>();
        ArrayList<Integer> theFinal = new ArrayList<>();
        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer conIndex = pokerIndex.get(i);
            if(i >= 51) {
                theFinal.add(conIndex);
            }else if(i % 3 == 0){
                parti01.add(conIndex);
            }else if(i % 3 == 1){
                parti02.add(conIndex);
            }else if(i % 3 == 2){
                parti03.add(conIndex);
            }
        }
        Collections.sort(parti01);
        Collections.sort(parti02);
        Collections.sort(parti03);
        Collections.sort(theFinal);
        detectPoker("小新", concret, parti01);
        detectPoker("妮妮", concret, parti02);
        detectPoker("风间", concret, parti03);
        detectPoker("底牌", concret, theFinal);
    }
    public static void detectPoker(String name, HashMap<Integer, String> hash, ArrayList<Integer> arr) {
        System.out.println(name + ":");
        Set<Map.Entry<Integer, String>> entries = hash.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            String value = entry.getValue();
            System.out.print(value + " ");
        }
        System.out.println();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值