package Shuo_homework.Landlords;
import java.util.*;
/**
* @description: some desc
* @author: Shuoliu
* @date: 2022/9/13 15:24
*/
public class Homework {
public static void main(String[] args) {
final String[] identity = {"方块", "梅花", "红桃", "黑桃"};
final String[] idSum = {"3","4","5","6", "7", "8", "9", "10", "J", "Q", "K""A","2"};
final String[] Boss = {"大王", "小王"};
List<Integer> cards = new ArrayList<Integer>();
Map<Integer,String>map = new HashMap<Integer,String>();
List<Integer> A = new ArrayList<Integer>();
List<Integer> A1 = new ArrayList<Integer>();
List<Integer> A2 = new ArrayList<Integer>();
List<Integer> A3 = new ArrayList<Integer>();
Integer id = 0;
//字符串组合
for (String i : identity) {
for (String j : idSum) {
map.put(id,i + j);
cards.add(id);
id++;
}
}
map.put(52,Boss[0]);
map.put(53,Boss[1]);
cards.add(52);
cards.add(53);
//洗牌:排序打乱
Collections.shuffle(cards);
//发牌
for (int n = 0; n < cards.size(); n++) {
if (n > 50) {
A.add(cards.get(n));
}
if (n % 3 == 0) {
A1.add(cards.get(n));
} else if (n % 3 == 1) {
A2.add(cards.get(n));
} else if (n % 3 == 2) {
A3.add(cards.get(n));
}
}
//排序
Collections.sort(A1);
Collections.sort(A2);
Collections.sort(A3);
Collections.sort(A);
//输出信息
System.out.print("A1"+": ");
for(Integer in:A1){
String value = map.get(in);
System.out.print(value+" ");
}
System.out.println();
System.out.print("A2"+": ");
for(Integer in:A2){
String value = map.get(in);
System.out.print(value+" ");
}
System.out.println();
System.out.print("A3"+": ");
for(Integer in:A3){
String value = map.get(in);
System.out.print(value+" ");
}
System.out.println();
System.out.print("底牌"+": ");
for(Integer in:A){
String value = map.get(in);
System.out.print(value+" ");
}
System.out.println();
}
}
Java斗地主洗牌+发牌+排序功能实现
于 2022-09-13 23:18:57 首次发布