package yong.wan.day0426;
/**
* 模拟斗地主发牌
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DouDiZhuDemo {
public static void main(String[] args) {
String[] color = { "黑桃", "梅花", "红心", "方块" };
String[] numbers = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"J", "Q", "K" };
List<String> li = new ArrayList<String>();
//添加大小鬼
li.add("大鬼");
li.add("小鬼");
//获取具体每张跑
for (int i = 0; i < color.length; i++) {
for (int j = 0; j < numbers.length; j++) {
li.add(color[i].concat(numbers[j]));
}
}
//for循环装牌
//增强for更快更方便
/*for (String c : color) {
for (String n : numbers) {
//通过增强循环将牌装入集合中
al.add(c.concat(n));
}
}
//洗牌
*
*/
Collections.shuffle(li);
System.out.println(li);
List<String> lin = new ArrayList<String>();
List<String> zhang = new ArrayList<String>();
List<String> liu = new ArrayList<String>();
for (int i = 0; i < li.size() - 3; i++) {
if (i % 3 == 0) {
lin.add(li.get(i));
} else if (i % 3 == 1) {
zhang.add(li.get(i));
} else if (i % 3 == 2) {
liu.add(li.get(i));
}
}
//显示每个人拿的牌
System.out.println("lin:" + lin);
System.out.println("张:" + zhang);
System.out.println("liu:" + liu);
//显示3张底牌
for (int i = li.size()-3; i < li.size(); i++) {
System.out.println(li.get(i));
}
}
}
|