Java斗地主洗牌+发牌+排序功能实现

package Shuo_homework.Landlords;

import java.util.*;

/**
 * @description: some desc
 * @author: Shuoliu
 * @date: 2022/9/13 15:24
 */
public class Homework {
    public static void main(String[] args) {
        final String[] identity = {"方块", "梅花", "红桃", "黑桃"};
        final String[] idSum = {"3","4","5","6", "7", "8", "9", "10", "J", "Q", "K""A","2"};
        final String[] Boss = {"大王", "小王"};
        List<Integer> cards = new ArrayList<Integer>(); 
        Map<Integer,String>map = new HashMap<Integer,String>();
        List<Integer> A = new ArrayList<Integer>();
        List<Integer> A1 = new ArrayList<Integer>();
        List<Integer> A2 = new ArrayList<Integer>();
        List<Integer> A3 = new ArrayList<Integer>();
        Integer id = 0;
//字符串组合
        for (String i : identity) {
            for (String j : idSum) {
                map.put(id,i + j);
                cards.add(id);
                id++;
            }
        }
        map.put(52,Boss[0]);
        map.put(53,Boss[1]);
        cards.add(52);
        cards.add(53);
//洗牌:排序打乱
        Collections.shuffle(cards);
//发牌
        for (int n = 0; n < cards.size(); n++) {
            if (n > 50) {
                A.add(cards.get(n));
            }
            if (n % 3 == 0) {
                A1.add(cards.get(n));
            } else if (n % 3 == 1) {
                A2.add(cards.get(n));
            } else if (n % 3 == 2) {
                A3.add(cards.get(n));
            }
        }
//排序
        Collections.sort(A1);
        Collections.sort(A2);
        Collections.sort(A3);
        Collections.sort(A);
//输出信息
        System.out.print("A1"+":   ");
        for(Integer in:A1){
            String value = map.get(in);
            System.out.print(value+"  ");
        }
        System.out.println();
        System.out.print("A2"+":   ");
        for(Integer in:A2){
            String value = map.get(in);
            System.out.print(value+"  ");
        }
        System.out.println();
        System.out.print("A3"+":   ");
        for(Integer in:A3){
            String value = map.get(in);
            System.out.print(value+"  ");
        }
        System.out.println();
        System.out.print("底牌"+":   ");
        for(Integer in:A){
            String value = map.get(in);
            System.out.print(value+"  ");
        }
        System.out.println();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值