package cn.nzw.day04;
import java.util.ArrayList;
import java.util.Collections;
/*
斗地主案例
1.准备牌
2.洗牌
3.发牌
4.看牌
* */
public class DoudiZhu {
public static void main(String[] args) {
//1.准备牌
ArrayListpuker= new ArrayList<>();//存储扑克的集合
//定义数组放置扑克
String []huase={"♠","❤","♣","♦"};
String []shuzi={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
puker.add("大鬼");
puker.add("小鬼");
for (String s : shuzi) {
for (String s1 : huase) {
puker.add(s+s1);
}
}
System.out.println(puker);
//2.洗牌
Collections.shuffle(puker);
System.out.println(puker);
//发牌,将牌放到三个集合中,再给出一个底牌集合用于放置地主牌
ArrayListzw1=new ArrayList<>();
ArrayListzw2=new ArrayList<>();
ArrayListzw3=new ArrayList<>();
ArrayListdipai=new ArrayList<>();
for(int i=0;i
String p = puker.get(i);//拿出索引为i的牌
//将52,53,54张牌设为地主牌,剩余51张牌%3,分别给三个集合
if(i>=51){
dipai.add(p);
}else if(i%3==0){
zw1.add(p);
}else if(i%3==1){
zw2.add(p);
}else if(i%3==2){
zw3.add(p);
}
}
//3.看牌
System.out.println("李白的牌是:"+zw1);
System.out.println("王维的牌是:"+zw2);
System.out.println("杜甫的牌是:"+zw3);
System.out.println("地主牌是:"+dipai);
}
}
类似这样: