Java笔记010-斗地主案例

import java.util.*;

public class DouDiZhu {

    public static void main(String[] args) {
        // 1.准备牌
        Map<Integer, String> poker = new HashMap<>();
        List<String> colors = List.of("♠","♥","♣","♦");
        List<String> numbers = List.of("2","A","K","Q","J","10","9","8","7","6","5","4","3");
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        int index = 0;
        poker.put(index, "大王");
        index++;
        poker.put(index, "小王");
        index++;
        for (String number : numbers) {
            for (String color : colors) {
                poker.put(index, color + number);
                index++;
            }
        }
        // System.out.println(poker);
        // 2.洗牌
        for(int i = 0; i <= 53; i++) {
            pokerIndex.add(i);
        }
        // System.out.println(pokerIndex);
        Collections.shuffle(pokerIndex);
        // System.out.println(pokerIndex);
        // 3.发牌
        ArrayList<Integer> player01 = new ArrayList<>();
        ArrayList<Integer> player02 = new ArrayList<>();
        ArrayList<Integer> player03 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();
        for (Integer i : pokerIndex) {
            if(i >= 51) {
                int pI = pokerIndex.get(i);
                diPai.add(pI);
            } else if(i % 3 == 0) {
                int pI = pokerIndex.get(i);
                player01.add(pI);
            } else if(i % 3 == 1) {
                int pI = pokerIndex.get(i);
                player02.add(pI);
            } else {
                int pI = pokerIndex.get(i);
                player03.add(pI);
            }
        }
        // 4.将牌从大到小排序
        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(diPai);
        // 5.看牌
        lookPoker("周润发",player01,poker);
        lookPoker("刘德华",player02,poker);
        lookPoker("周星驰",player03,poker);
        lookPoker("底牌",diPai,poker);
    }
    public static void lookPoker(String name, ArrayList<Integer> player, Map<Integer, String> poker) {
        System.out.print(name + ":");
        for (Integer i : player) {
            String value = poker.get(i);
            System.out.print(value);
        }
        System.out.println();
    }
}
/*
周润发:♠2♥K♣K♦K♣J♣10♠9♥9♦9♠8♦8♠7♦7♦6♠4♦4♠3
刘德华:大王♦2♠A♣A♦A♠K♠Q♣Q♠J♥J♦10♣9♣8♣7♠6♠5♥3
周星驰:小王♥2♣2♥Q♦J♠10♥10♥8♥6♣6♥5♣5♦5♥4♣4♣3♦3
底牌:♥A♦Q♥7
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值