List无序版本
需求:
/*
斗地主综合案例:
1.准备牌
2.洗牌
3.发牌
4.看牌
*/
public class DouDiZhu {
public static void main(String[] args) {
//1.准备牌
//定义一个存储54张牌的ArrayList集合,泛型使用String
ArrayList<String> poker = new ArrayList<>();
//定义俩个数组,一个数组存储牌的花色,一个数组存储牌的序号
String[] colors = {
"♠", "♥", "♣", "♦"};
String[] numbers = {
"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
//先把大王小王存储带poker集合当中
poker.add("大王");
poker.add("小王");
//循环嵌套遍历俩个数组,组装52张牌
for (String number : numbers) {
for (String color : colors) {
// System.out.println(color + number);
//把组装好的牌存储到集合中
poker.add(color + number);
}
}
// System.out.println(poker);
/*
2.洗牌
使用集合当中的Collections中的方法
shuffle(List<?> list, Random rnd)
使用指定的随机源随机排列指定的列表。
*/
Collections.shuffle(poker);
// System.out.println(poker);
/*
3.发牌
定义四个集合,存储玩家的牌和底牌
*/
ArrayList<String> player1 = new ArrayList<>();
ArrayList<String>