import java.util.ArrayList;标签:String,斗地主,ArrayList,show,add,new,arrayList,模拟 From: https://www.cnblogs.com/zhaoshengfu/p/18081007
import java.util.Collections;
public class Main {
public static void main(String[] args) {
//模拟斗地主的洗牌发牌看牌;
//创建扑克牌
ArrayList<String> arrayList = new ArrayList<>();
//扑克牌(♦ ♣ ♠ ♥)
String[] color = {"♦", "♣", "♠", "♥"};
//牌号(2,3,4,5,6,7,8,9,10,J,Q,K,A)
String[] paihao = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
//大王小王
//用arrilist。add的强循环把牌装起来
for (String c : color) {
for (String p : paihao) {
arrayList.add(c + p);
}
}
arrayList.add("joker");
arrayList.add("小王");
//洗牌
Collections.sort(arrayList);
//发牌
//定义三个人的数组和一个底牌数组
ArrayList<String> zsf = new ArrayList<>();
ArrayList<String> jcs = new ArrayList<>();
ArrayList<String> zxt = new ArrayList<>();
ArrayList<String> dipai = new ArrayList<>();
for (int i = 0; i < arrayList.size(); i++) {
String s = arrayList.get(i);
if (i >= arrayList.size() - 3) {
dipai.add(s);
} else if (i % 3 == 1) {
zsf.add(s);
} else if (i % 3 == 2) {
jcs.add(s);
} else if (i % 3 == 0)
zxt.add(s);
}
show("zsf",zsf);
show("jcs",jcs);
show("zxt",zsf);
show("底牌",dipai);
}
//发牌了
public static void show(String s, ArrayList<String> a) {
System.out.print(s + "的牌是 ");
for (String q : a) {
System.out.print(q + " ");
}
System.out.println();
}
//定义遍历牌的函数被
}