java开发斗地主发牌功能

**

排序思想

**
在这里插入图片描述

在这里插入代码片package test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test03 {
	public static void main(String[] args) {
		Map<Integer, String> pokerMap = new HashMap<Integer, String>();
		List<Integer> pookerList = new ArrayList<Integer>();
		int count=0;
		String[] colors = {"♠","♣","♥","♦"};
		//数组存储点数
		String[] numbers = {"3","4","5","6","7","8","9","10","j","q","k","A","2"};
		for (int i = 0; i < numbers.length; i++) {
			for (int j = 0; j < colors.length; j++) {
				pokerMap.put(count, colors[j]+numbers[i]);//得到了一副扑克牌
				pookerList.add(count);
				count++;
			}
		}
		pokerMap.put(52, "😀");
		pokerMap.put(53, "👴");
		pookerList.add(52);
		pookerList.add(53);
		List<Integer> player1 = new ArrayList<Integer>();
		List<Integer> player2 = new ArrayList<Integer>();
		List<Integer> player3 = new ArrayList<Integer>();
		List<Integer> bottom = new ArrayList<Integer>();
		Collections.shuffle(pookerList);
		//System.out.println(pookerList);
		for (int i = 0; i < pookerList.size(); i++) {
			if (i < 3 ) {
				bottom.add(pookerList.get(i));
			}else if (i%3 == 0) {
				player1.add(pookerList.get(i));
			}else if (i%3 == 1) {
				player2.add(pookerList.get(i));
			}else if (i%3 == 2 ) {
				player3.add(pookerList.get(i));
			}
		}
		Collections.sort(player1);
		Collections.sort(player2);
		Collections.sort(player3);
		Collections.sort(bottom);
		look("张三", pokerMap, player1);
		look("李四", pokerMap, player2);
		look("王五", pokerMap, player3);
		look("底牌", pokerMap, bottom);
	
	}
	
	public static void look(String name,Map<Integer, String> pokerMap,List<Integer> player ) {
		System.out.println(name+":");
		for(Integer p:player) {
			String value = pokerMap.get(p);
			System.out.print(value +"   ");
			
		}
		System.out.println("");
	
	}
}

效果图
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值