import java.util.*;
public class DouDiZhu {
public static void main(String[] args) {
// 1.准备牌
Map<Integer, String> poker = new HashMap<>();
List<String> colors = List.of("♠","♥","♣","♦");
List<String> numbers = List.of("2","A","K","Q","J","10","9","8","7","6","5","4","3");
ArrayList<Integer> pokerIndex = new ArrayList<>();
int index = 0;
poker.put(index, "大王");
index++;
poker.put(index, "小王");
index++;
for (String number : numbers) {
for (String color : colors) {
poker.put(index, color + number);
index++;
}
}
// System.out.println(poker);
// 2.洗牌
for(int i = 0; i <= 53; i++) {
pokerIndex.add(i);
}
// System.out.println(pokerIndex);
Collections.shuffle(pokerIndex);
// System.out.println(pokerIndex);
// 3.发牌
ArrayList<Integer> player01 = new ArrayList<>();
ArrayList<Integer> player02 = new ArrayList<>();
ArrayList<Integer> player03 = new ArrayList<>();
ArrayList<Integer> diPai = new ArrayList<>();
for (Integer i : pokerIndex) {
if(i >= 51) {
int pI = pokerIndex.get(i);
diPai.add(pI);
} else if(i % 3 == 0) {
int pI = pokerIndex.get(i);
player01.add(pI);
} else if(i % 3 == 1) {
int pI = pokerIndex.get(i);
player02.add(pI);
} else {
int pI = pokerIndex.get(i);
player03.add(pI);
}
}
// 4.将牌从大到小排序
Collections.sort(player01);
Collections.sort(player02);
Collections.sort(player03);
Collections.sort(diPai);
// 5.看牌
lookPoker("周润发",player01,poker);
lookPoker("刘德华",player02,poker);
lookPoker("周星驰",player03,poker);
lookPoker("底牌",diPai,poker);
}
public static void lookPoker(String name, ArrayList<Integer> player, Map<Integer, String> poker) {
System.out.print(name + ":");
for (Integer i : player) {
String value = poker.get(i);
System.out.print(value);
}
System.out.println();
}
}
/*
周润发:♠2♥K♣K♦K♣J♣10♠9♥9♦9♠8♦8♠7♦7♦6♠4♦4♠3
刘德华:大王♦2♠A♣A♦A♠K♠Q♣Q♠J♥J♦10♣9♣8♣7♠6♠5♥3
周星驰:小王♥2♣2♥Q♦J♠10♥10♥8♥6♣6♥5♣5♦5♥4♣4♣3♦3
底牌:♥A♦Q♥7
*/
Java笔记010-斗地主案例
最新推荐文章于 2024-08-16 23:08:28 发布