import java.util.ArrayList; import java.util.Collections; import java.util.List; public class DouDiZhuDemo { public static void main(String[] args) { // Person p1 = new Person("用户1"); // Person p2 = new Person("用户2"); // Person p3 = new Person("用户3"); // Person p4 = new Person("用户4"); String[] huase = {"♠","♥","♣","◇"}; String[] nums ={"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; List<String> lists = new ArrayList<String>(); for (int i = 0; i <huase.length ; i++) { for (int j = 0; j <nums.length ; j++) { lists.add(huase[i]+nums[j]); } } lists.add("大王"); lists.add("小王"); //洗牌 List<String> xipai = new DouDiZhuDemo().xipai(lists); //定义4个集合 存储玩家和牌 List<String> player01 = new ArrayList<String>(); List<String> player02 = new ArrayList<String>(); List<String> player03 = new ArrayList<String>(); List<String> dipai = new ArrayList<String>(); //发牌的代码 核心代码 for (int i = 0; i <xipai.size() ; i++) { //获取所有的牌 String p = xipai.get(i); if(i >= 51){ //改底牌的发牌 dipai.add(p); }else if(i%3==0){ //给玩家1发牌 player01.add(p); }else if(i%3==1){ //给玩家2发牌 player02.add(p); }else if(i%3==2){ //给玩家3发牌 player03.add(p); } } //看牌 System.out.println(player01); System.out.println(player02); System.out.println(player03); System.out.println(dipai); } //洗牌的方式 public List<String> xipai(List l){ List ll = l; Collections.shuffle(l); return ll; } }
原文:https://www.cnblogs.com/gaoSJ/p/12844204.html