斗地主进阶版

斗地主进阶版

package cn.cast.day4;

import java.util.*;

//有序的斗地主
public class DouDiZhu {
    public static void main(String[] args) {
        //准备牌
        //创建一个map集合存储牌的索引和组装好的牌
        HashMap<Integer, String> poker = new HashMap<>();
        //创建一个集合存储牌的索引
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        //定义两个集合存储牌的花色和序号
        List<String> colors = List.of("♠", "♥", "♣", "♦");
        List<String> numbers = List.of("2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3");
        //把大王和小王存储到集合当中
        //定义一个牌的索引
        int Index = 0;
        poker.put(Index, "大王");
        poker.put(++Index, "小王");
        Index++;
        for (int i = 0; i < 54; i++) {
            pokerIndex.add(i);
        }
        for (int i = 0; i < numbers.size(); i++) {
            for (int j = 0; j < colors.size(); j++) {
                String str = numbers.get(i);
                str.concat(colors.get(j));
                poker.put(Index, str);
                Index++;
            }
        }
        //洗牌
        Collections.shuffle(pokerIndex);
        //发牌
        HashSet<Integer> player1 = new HashSet<>();
        HashSet<Integer> player2 = new HashSet<>();
        HashSet<Integer> player3 = new HashSet<>();
        HashSet<Integer> dipai = new HashSet<>();
        for (int i = 0; i < pokerIndex.size(); i++) {
            if (i>51){
                dipai.add(pokerIndex.get(i));
            }else if (i%3==1){
                player1.add(pokerIndex.get(i));
            }else if(i%3==2){
                player2.add(pokerIndex.get(i));
            }else if (i%3==0){
                player3.add(pokerIndex.get(i));
            }
        }
        System.out.println("dipai = " + dipai);
        System.out.println("player1 = " + player1);
        System.out.println("player2 = " + player2);
        System.out.println("player3 = " + player3);


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值