package com.learn.Demo9;
import java.util.*;
/* 准备牌:
牌可以设计为一个ArrayList<String>,每个字符串为一张牌。
每张牌由花色数字两部分组成,我们可以使用花色集合与数字集合嵌套迭代完成每张牌的组装。
牌由Collections类的shuffle方法进行随机排序。
* 发牌
将每个人以及底牌设计为ArrayList<String>,将最后3张牌直接存放于底牌,剩余牌通过对3取模依次发牌。
* 看牌
直接打印每个集合。
*/
public class Demo1 {
public static void main(String[] args) {
HashMap<Integer,String> pokerBox=new HashMap<>();
Integer pokerBoxindex=0;
ArrayList pokerBoxindexnumber=new ArrayList<>();
ArrayList colors=new ArrayList<>();
ArrayList numbers=new ArrayList<>();
//1.4 分别给花色 以及 数字集合添加元素
colors.add(“♥”);
colors.add(“♦”);
colors.add(“♠”);
colors.add(“♣”);
for(int i = 2; i<=10 ; i++){
numbers.add(i+"");
}
numbers.add(“J”);
numbers.add(“Q”);
numbers.add(“K”);
numbers.add(“A”);
System.out.println(colors);
System.out.println(numbers);
//1.6大王小王并添加编号
pokerBox.put(pokerBoxindex,"大☠");
pokerBoxindexnumber.add(pokerBoxindex);
++pokerBoxindex;
pokerBox.put(pokerBoxindex,"小☺");
pokerBoxindexnumber.add(pokerBoxindex);
for(String color:colors){
for (String number:numbers) {
++pokerBoxindex;
pokerBox.put(pokerBoxindex,color+number);
pokerBoxindexnumber.add(pokerBoxindex);
}
}
System.out.println(pokerBox);
System.out.println(pokerBoxindexnumber);
// 洗牌
Collections.shuffle(pokerBoxindexnumber);
System.out.println(pokerBoxindexnumber);
ArrayList A1=new ArrayList<>();
ArrayList B2=new ArrayList<>();
ArrayList C3=new ArrayList<>();
ArrayList dipai=new ArrayList<>();
Iterator iterator=pokerBoxindexnumber.iterator();
int i=0;
while (iterator.hasNext()){
if (i<51){
if (i%30){
A1.add(iterator.next());
}else if(i%31){
B2.add(iterator.next());
}else if(i%3==2){
C3.add(iterator.next());
}
}else {
dipai.add(iterator.next());
}
++i;
}
System.out.println(A1);
System.out.println(B2);
System.out.println(C3);
System.out.println(dipai);
Collections.shuffle(A1);
Collections.shuffle(B2);
Collections.shuffle(C3);
Collections.shuffle(dipai);
lookpaker("A1",pokerBox,A1);
lookpaker("B2",pokerBox,B2);
lookpaker("C3",pokerBox,C3);
lookpaker("底牌",pokerBox,dipai);
}
private static void lookpaker(String name ,HashMap<Integer,String> pokerBox,ArrayList<Integer> list){
System.out.print(name+":");
for (Integer key:list){
String value = pokerBox.get(key);
System.out.print(value);
}
System.out.println();
}
}