import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class DouDizZhu {
public static void main(String[] args) {
//准备牌 创建花色和数字集合
ArrayList<String> colors = new ArrayList<String>();
ArrayList<String> numbers = new ArrayList<String>();
Collections.addAll(colors, "♥","♠","♣","♦");
Collections.addAll(numbers, "3","4","5","6","7","8","9","10","J","Q","K","A","2");
HashMap<Integer, String> poker = new HashMap<Integer, String>();
int index = 0;
for (String number : numbers) {
for (String color : colors) {
String sss = number + color;
poker.put(index, sss);
index++;
}
}
poker.put(52,"大☻");
poker.put(53,"小☺");
//洗牌
ArrayList<Integer> in = new ArrayList<Integer>();
for(int i = 0;i<poker.size();i++){
in.add(i);
}
Collections.shuffle(in);
//发牌
ArrayList<Integer> p1 = new ArrayList<Integer>();
ArrayList<Integer> p2 = new ArrayList<Integer>();
ArrayList<Integer> p3 = new ArrayList<Integer>();
ArrayList<Integer> dd = new ArrayList<Integer>();
for(int i = 0;i<54;i++){
if(i>50){
dd.add(in.get(i)); //将已定义的in集合(已被打乱)数放至dd中
}else if(i%3==0){
p1.add(in.get(i));
}else if(i%3==1){
p2.add(in.get(i));
}else if(i%3==2){
p3.add(in.get(i));
}
}
Collections.sort(p1);
Collections.sort(p2);
Collections.sort(p3);
Collections.sort(dd);
ArrayList<String> player1 = new ArrayList<String>();
ArrayList<String> player2 = new ArrayList<String>();
ArrayList<String> player3 = new ArrayList<String>();
ArrayList<String> diPai = new ArrayList<String>();
for (Integer d: dd) {
diPai.add(poker.get(d));
}
for (Integer pp: p1) {
player1.add(poker.get(pp));
}
for (Integer pp: p2) {
player2.add(poker.get(pp));
}
for (Integer pp: p3) {
player3.add(poker.get(pp));
}
System.out.println("令狐冲:"+player1);
System.out.println("郭靖:"+player2);
System.out.println("葫芦娃:"+player3);
System.out.println("底牌:"+diPai);
}
}
|
|