package work;
import java.util.ArrayList;
public class Lord {
public static void main(String[] args) {
ArrayList<String> prepare = prepare();
ArrayList<String> shuffle = shuffle(prepare);
System.out.println(shuffle);
Players p1 = new Players();
Players p2 = new Players();
Players p3 = new Players();
p1.setName("张三");
p2.setName("李四");
p3.setName("王五");
deal(shuffle, p1, p2, p3);
System.out.println(p1.getName() + p1.getMyPoker());
System.out.println(p2.getName() + p2.getMyPoker());
System.out.println(p3.getName() + p3.getMyPoker());
}
public static ArrayList<String> prepare() {
ArrayList<String> poker = new ArrayList<>();
String[] color = {"♠", "♥", "♣", "♦"};
String[] num = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
for (int i = 0; i < color.length; i++) {
for (int j = 0; j < num.length; j++) {
poker.add(color[i] + num[j]);
}
}
poker.add("🃏");
poker.add("🃏");
return poker;
}
public static ArrayList<String> shuffle(ArrayList<String> poker) {
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 54; i++) {
int x = (int) (Math.random() * poker.size());
list.add(poker.get(x));
poker.remove(x);
}
return list;
}
public static void deal(ArrayList<String> shuffle, Players p1, Players p2, Players p3) {
ArrayList<String> player1 = new ArrayList<>();
ArrayList<String> player2 = new ArrayList<>();
ArrayList<String> player3 = new ArrayList<>();
ArrayList<String> ace = new ArrayList<>();
for (int i = 0; i < 51; i++) {
if (i % 3 == 0) {
player1.add(shuffle.get(0));
} else if (i % 3 == 1) {
player2.add(shuffle.get(0));
} else {
player3.add(shuffle.get(0));
}
shuffle.remove(0);
}
p1.setMyPoker(player1);
p2.setMyPoker(player2);
p3.setMyPoker(player3);
for (int i = 0; i < shuffle.size(); i++) {
ace.add(shuffle.get(i));
}
System.out.println("底牌为:" + ace);
}
}
package work;
import java.util.ArrayList;
public class Players {
private String name;
private ArrayList<String> MyPoker;
public Players(String name, ArrayList<String> myPoker) {
this.name = name;
MyPoker = myPoker;
}
public Players() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<String> getMyPoker() {
return MyPoker;
}
public void setMyPoker(ArrayList<String> myPoker) {
MyPoker = myPoker;
}
@Override
public String toString() {
return "Players{" +
"name='" + name + '\'' +
", MyPoker=" + MyPoker +
'}';
}
}