package Test19_Demo.Demo08;/*
@create 2020--12--09--16:07
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class CardDemo {
public static void main(String[] args) {
//确定牌&数字的对应关系
Map<Integer, String> map = new HashMap<>();
//花色集合
ArrayList<String> colors = new ArrayList<>();
colors.add("♠");
colors.add("♣");
colors.add("♦");
colors.add("♥");
//数字集合
ArrayList<String> numbers = new ArrayList<>();
for (int i = 2; i < 11; i++) {
numbers.add(i + " ");
}
Collections.addAll(numbers, "J", "Q", "K", "A");
//设置对应关系
int cardNumber = 0;
//遍历数字集合,使用每一种颜色匹配每一个花色
for (String thisNumber: numbers
) {
for (String thisColor: colors
) {
String thisCard = thisColor + thisNumber;
map.put(cardNumber, thisCard);
cardNumber++;
}
}
//添加大小王
map.put(cardNumber++, "大");
map.put(cardNumber++, "小");
ArrayList<Integer> poker = new ArrayList<>();
for (int i = 0; i < 54; i++) {
poker.add(i);
}
Collections.shuffle(poker);
System.out.println(poker);
//发牌
ArrayList<Integer> player01 = new ArrayList<>();
ArrayList<Integer> player02 = new ArrayList<>();
ArrayList<Integer> player03 = new ArrayList<>();
ArrayList<Integer> dipai = new ArrayList<>();
for (int index = 0; index <poker.size() ; index++) {
//通过索引,获取代表牌的数字
Integer integerCard = poker.get(index);
if (index>=poker.size() - 3){
dipai.add(integerCard);
}else if (index % 3 == 0) {
player01.add(integerCard);
}else if (index % 3 == 1) {
player02.add(integerCard);
}else{
player03.add(integerCard);
}
}
// for (int index = 0; index < poker.size() - 3; index++) {
// //通过索引,获取代表牌的数字
// Integer integerCard = poker.get(index);
// if (index % 3 == 0) {
// player01.add(integerCard);
// }else if (index % 3 == 1) {
// player02.add(integerCard);
// }else{
// player03.add(integerCard);
// }
// }
//
// for (int index = poker.size()-3; index <poker.size() ; index++) {
// Integer integerCard = poker.get(index);
// dipai.add(integerCard);
//
// }
//看牌 - 排序
Collections.sort(player01);
Collections.sort(player02);
Collections.sort(player03);
Collections.sort(dipai);
for (int i = player01.size() - 1; i >= 0; i--) {
Integer integer = player01.get(i);
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
System.out.println();
for (int i = player02.size() - 1; i >= 0; i--) {
Integer integer = player02.get(i);
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
System.out.println();
for (int i = player03.size() - 1; i >= 0; i--) {
Integer integer = player03.get(i);
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
System.out.println();
/*for (int i = player01.size() - 1; i >= 0; i--) {
Integer integer = player01.get(i);
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
System.out.println();
for (int i = player02.size() - 1; i >= 0; i--) {
Integer integer = player02.get(i);
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
System.out.println();
for (int i = player03.size() - 1; i >= 0; i--) {
Integer integer = player03.get(i);
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
System.out.println();*/
for (Integer integer:dipai) {
String realCard = map.get(integer);
System.out.print(realCard+" ");
}
}
}