标签:sort ade shuff 排序 pad arraylist 图片 dex rgs
代码:
package com.oracle.demo02; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; public class DouDiZhu { //斗地主(发牌) public static void main(String[] args) { //定义扑克牌Map HashMap<Integer, String> pooker=new HashMap<Integer,String>(); //定义装有扑克牌号的集合 ArrayList<Integer> pookerNumber=new ArrayList<Integer>(); //封装数据 String[] color={"♠","♦","♥","♣"}; String[] number={"2","A","K","Q","J","10","9","8","7","6","5","4","3"}; int index=2; for (String n : number) { for (String c : color) { pooker.put(index, c+n); pookerNumber.add(index); index++; } } //封装大小王 pooker.put(0, "大王"); pooker.put(1, "小王"); pookerNumber.add(0); pookerNumber.add(1); //测试 //System.out.println(pooker); //洗牌:打乱集合中元素顺序(随机)--> Collections.shuffle(); Collections.shuffle(pookerNumber); //System.out.println(pookerNumber); //创建四个容器 ArrayList<Integer> player1=new ArrayList<Integer>(); ArrayList<Integer> player2=new ArrayList<Integer>(); ArrayList<Integer> player3=new ArrayList<Integer>(); ArrayList<Integer> bottom=new ArrayList<Integer>(); //发牌 for (int i = 0; i < pookerNumber.size(); i++) { //将前三张牌作为底牌 if (i<3) { bottom.add(pookerNumber.get(i)); }else if(i%3==0){ player1.add(pookerNumber.get(i)); }else if(i%3==1){ player2.add(pookerNumber.get(i)); }else if(i%3==2){ player3.add(pookerNumber.get(i)); } } //为四个容器中的牌排序(理顺)--> Collections.sort(); Collections.sort(player1); Collections.sort(player2); Collections.sort(player3); Collections.sort(bottom); //看牌 look("渣渣辉",pooker, player1); look("梁朝痿",pooker, player2); look("赵本仙",pooker, player3); look("底牌",pooker, bottom); } public static void look(String name,HashMap<Integer, String> pooker,ArrayList<Integer> player) { System.out.print(name+": "); for (int number : player) { System.out.print(pooker.get(number)+" "); } System.out.println(); } }
构思:
标签:sort ade shuff 排序 pad arraylist 图片 dex rgs
原文地址:https://www.cnblogs.com/l1314/p/12123620.html