package DouDiZhu2;
import java.util.*;
public class Game {
public static void main(String[] args) {
//准备牌
List<Integer> index = new ArrayList<Integer>();
for(int i=0;i<54;i++){
index.add(i);
}
Map<Integer,String> card = prepare();
//洗牌
Collections.shuffle(index);
//发牌
ArrayList<Integer>[] discard = distribute(index);
ArrayList<Integer> player01;
ArrayList<Integer> player02;
ArrayList<Integer> player03;
ArrayList<Integer> Bottom;
Bottom = discard[0];
player01 = discard[1];
player02 = discard[2];
player03 = discard[3];
//排序
Collections.sort(player01);
Collections.sort(player02);
Collections.sort(player03);
//看牌
System.out.print("player01:");
lookCard(card,player01);
System.out.print("player02:");
lookCard(card,player02);
System.out.print("player03:");
lookCard(card,player03);
System.out.print("Bottom:");
lookCard(card,Bottom);
}
private static void lookCard(Map<Integer, String> card, ArrayList<Integer> disIndex) {
for(Integer i:disIndex){
System.out.print(card.get(i)+" ");
}
System.out.println();
}
private static ArrayList<Integer>[] distribute(List<Integer> index){
ArrayList<Integer>[] disIndex = new ArrayList[4];
disIndex[0] = new ArrayList<>();
disIndex[1] = new ArrayList<>();
disIndex[2] = new ArrayList<>();
disIndex[3] = new ArrayList<>();
for(int i=0;i<54;i++){
if(i>=51){
disIndex[0].add(index.get(i));
} else {
if(i%3==0){
disIndex[1].add(index.get(i));
} else if(i%3==1){
disIndex[2].add(index.get(i));
} else if(i%3==2){
disIndex[3].add(index.get(i));
}
}
}
return disIndex;
}
private static Map<Integer,String> prepare() {
List<String> Color = List.of("♥","♣","♦","♠");
List<String> Number = List.of("3","4","5","6","7","8","9","10","J","Q","K","A","2");
Map<Integer,String> card = new HashMap<>();
int count=0;
for(String number:Number){
for(String color:Color){
card.put(count,color.concat(number));
count++;
}
}
card.put(count,"小王");
card.put(count+1,"大王");
return card;
}
}
[Java进阶]学习笔记22:斗地主案例2
最新推荐文章于 2024-04-29 21:10:06 发布