分牌:将原列表分为4个列表,分别是3个农民与底牌
package com.item.test; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Action { public static void main(String[] args) { //随机卡牌 List<Card> list=ResetCard(StartCard()); List<Card> one=list.subList(0,17); List<Card> two=list.subList(17,2*17); List<Card> three=list.subList(2*17,3*17); List<Card> four=list.subList(3*17,54); System.out.println("农民"); for (Card c:one) { System.out.print(c.getIndex()+":"+c.getName()+"\t"); } System.out.println(); System.out.println("农民"); for (Card c:two) { System.out.print(c.getIndex()+":"+c.getName()+"\t"); } System.out.println(); System.out.println("农民"); for (Card c:three) { System.out.print(c.getIndex()+":"+c.getName()+"\t"); } System.out.println(); System.out.println("底牌"); for (Card c:four) { System.out.print(c.getIndex()+":"+c.getName()+"\t"); } System.out.println(); } /** * 随机排序 * @param list * @return */ public static List<Card> ResetCard(List<Card> list){ Collections.shuffle(list); return list; } /** * 初始化卡牌 * @return */ public static List<Card> StartCard(){ List<Card> list=new ArrayList<>(54); int i=0; for (CardsEnum cardsEnum:CardsEnum.values()) { for (CardColorEnum cardColorEnum:CardColorEnum.values()) { list.add(new Card(cardsEnum,cardColorEnum,i++)); } } Card big=new Card(); big.setName(CardBossEnum.BIG.getName()); big.setIndex(i++); Card small=new Card(); small.setName(CardBossEnum.SMALL.getName()); small.setIndex(i++); list.add(big); list.add(small); return list; } }
效果如下: