public class Game {
public static void main(String[] args) {
//存放牌数
List<Integer> list=new ArrayList<>();
//存放牌
Map<Integer,String> map=new HashMap<>();
String[] num={"A","2","3","4","5","6","7","8","9","10","J","Q","k"};
String[] color={"♠","♥","♣","♦"};
int index=0;//记录下标
for (String n:num){
for (String col:color){
map.put(index,col+n);//将牌存入map集合
list.add(index);
index++;
}
}
//处理大小王
map.put(52,"小王");
map.put(53,"大王");
list.add(52);
list.add(53);
Collections.shuffle(list);//打乱排序(洗牌)
List<Integer> p1=new ArrayList<>();
List<Integer> p2=new ArrayList<>();
List<Integer> p3=new ArrayList<>();
List<Integer> d=new ArrayList<>();
for (Integer l:list){//发牌
if(l<3){
d.add(l);
}else if (l%3==0){
p1.add(l);
}else if (l%3==1){
p2.add(l);
}else {
p3.add(l);
}
}
Collections.sort(p1);//排序
Collections.sort(p2);//排序
Collections.sort(p3);//排序
Collections.sort(d);//排序
//看牌
show("a",p1,map);
show("b",p2,map);
show("c",p3,map);
show("底牌",d,map);
}
private static void show(String name, List<Integer> list, Map<Integer, String> map) {
System.out.print(name+" ");
for (int i = 0; i <list.size() ; i++) {
System.out.print(map.get(list.get(i))+" ");
}
System.out.println();
}
}
斗地主的小测试
最新推荐文章于 2022-09-15 19:53:47 发布