package com.by.cmweb;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class TestMain {
public static void main(String[] args) {
List<String> poker = new ArrayList<>();
List<String> reserveCard = new ArrayList<>();
List<String> symbol = new ArrayList<>();
Collections.addAll(symbol, "♥", "♠", "♦", "♣");
Collections.addAll(poker, "大王", "小王");
Collections.addAll(reserveCard, "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2");
for (String s : reserveCard) {
for (String bs : symbol) {
poker.add(s + "*" + bs);
}
}
Collections.shuffle(poker);
System.out.println("=====洗完牌======>" + poker);
Us A = new Us("A");
Us B = new Us("B");
Us C = new Us("C");
Random random = new Random();
String landlord = poker.get(random.nextInt(54) - 3);
List<String> Alist = new ArrayList<>();
List<String> Blist = new ArrayList<>();
List<String> Clist = new ArrayList<>();
System.out.println("=====地主牌======>" + landlord);
String uname = "A";
for (int i = 0; i < 1; i--) {
String s = poker.get(0);
if (uname.equals(A.getName())) {
Alist.add(s);
uname = "B";
} else if (uname.equals(B.getName())) {
Blist.add(s);
uname = "C";
} else if (uname.equals(C.getName())) {
Clist.add(s);
uname = "A";
}
poker.remove(s);
if (poker.size() == 3) {
break;
}
}
if (Alist.contains(landlord)) {
Alist.addAll(poker);
}
if (Blist.contains(landlord)) {
Blist.addAll(poker);
}
if (Clist.contains(landlord)) {
Clist.addAll(poker);
}
A.setPoker(Alist, reserveCard);
B.setPoker(Blist, reserveCard);
C.setPoker(Clist, reserveCard);
System.out.println("=====最終牌==========");
System.out.println(A);
System.out.println(B);
System.out.println(C);
}
}
class Us {
private String name;
private List<String> poker;
public Us() {
}
public Us(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getPoker() {
return poker;
}
public void setPoker(List<String> poker, List<String> reserveCard) {
List<String> ls = new ArrayList<>();
List<String> Ps = new ArrayList<>();
for (String brand : poker) {
if (!brand.equals("大王") && !brand.equals("小王")) {
Ps.add(brand);
}
}
for (String res : reserveCard) {
for (String p : Ps) {
String split = p.split("\\*")[0];
if (res.equals(split)) {
ls.add(p);
}
}
}
for (String brand : poker) {
if (brand.equals("大王") || brand.equals("小王")) {
if (ls.contains("大王")) {
ls.add(ls.size() - 1, brand);
} else {
ls.add(ls.size(), brand);
}
}
}
this.poker = ls;
}
@Override
public String toString() {
return "玩家:" + name + "==>" + poker + "";
}
}