package com.company;
import java.util.ArrayList;
import java.util.Collections;
public class Lookpoker {
public void kanPai(String name, ArrayList<String> arrayList) {//看牌方法
System.out.print(name + "的牌是:");
for (String s :
arrayList) {
System.out.print(s);
}
System.out.println();
}
public static void main(String[] args) {
/*
"1:创建一个牌盒,也就是定义一个集合对象,用ArrayList集合实现
2:往牌盒里面装牌
3:洗牌,也就是把牌打撒,用collections的shuffle()方法实现
4:发牌,也就是遍历集合,给三个玩家发牌
5:看牌,也就是三个玩家分别遍历自己的牌
*/
ArrayList<String> arrayList = new ArrayList<>();
//将可能出现的花色和点数分别存入两个String数组
String[] design = {"♣", "♦", "♠", "♥"};
String[] num = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
//嵌套循环两个数组,将遍历出来的牌存入arrayList集合
for (String s1 : design) {
for (String s2 : num) {
arrayList.add(s1 + s2);
}
}
arrayList.add("小王");
arrayList.add("大王");
//使用Collection.shuffle方法将arrayList集合打乱;
Collections.shuffle(arrayList);
//创建玩家
ArrayList<String> jhh = new ArrayList<>();
ArrayList<String> ws = new ArrayList<>();
ArrayList<String> xsy = new ArrayList<>();
ArrayList<String> dPai = new ArrayList<>();//底牌
//给玩家发放手牌
for (int i = 0; i < arrayList.size(); i++) {
String str = arrayList.get(i);
if (i >= arrayList.size() - 3) {
dPai.add(str);
} else if (i % 3 == 1) {
ws.add(str);
} else if (i % 3 == 0) {
jhh.add(str);
} else {
xsy.add(str);
}
}
//玩家看牌
Lookpoker lookpoker = new Lookpoker();
lookpoker.kanPai("蒋某", jhh);
lookpoker.kanPai("王某", ws);
lookpoker.kanPai("向某", xsy);
lookpoker.kanPai("底牌", dPai);
}
}