/*
* 模拟斗地主洗牌和发牌,牌没有排序
* 自己创建一个集合对象 将扑克牌存储进去
* 洗牌 collections 里的方法
* 发牌
* 看牌 底牌单独看
*/
//自己创建一个集合对象 将扑克牌存储进去
String [] num = {"A","1","2","3","4","5","6","7","8","9"
,"10","J","Q","K"};
String [] color ={"红桃","黑桃","方块","梅花"};
ArrayList<String> poker =new ArrayList<>();
//拼接花色和字符
for (String s1 : color) {
for (String s2 : num) {
poker.add(s1.concat(s2)); //concat链接两个字符串
}
}
poker.add("大王");
poker.add("小王");
//洗牌 collections 里的方法
Collections.shuffle(poker);
System.out.println(poker);
//发牌
ArrayList<String> gaojing =new ArrayList<>();
ArrayList<String> longwu =new ArrayList<>();
ArrayList<String> mi=new ArrayList<>();
ArrayList<String> dipai=new ArrayList<>();
for (int i = 0; i < poker.size(); i++) {
if (i>=poker.size()-3) {
//存三张底牌给底牌
dipai.add(poker.get(i));
}else if (i%3==0) {
gaojing.add(poker.get(i));
}else if (i%3==1) {
longwu.add(poker.get(i));
}else{
mi.add(poker.get(i));
}
}
//看牌
System.out.println(mi);
System.out.println(longwu);
System.out.println(gaojing);
System.out.println(dipai);