鬥地主發牌的java代碼

import java.util.*;

public class Test02 {
    public static void main(String[] args) {
        Map<Integer,String> poker = new HashMap<>();
        List<Integer> pokerIndex = new ArrayList<>();
        List<String> colors = new ArrayList<>();
        colors.add("♠");colors.add("♥");colors.add("♣");colors.add("◆");
        List<String> numbers = new ArrayList<>();
        numbers.add("2");numbers.add("A");numbers.add("K");
        numbers.add("Q");numbers.add("J");numbers.add("10");
        numbers.add("9");numbers.add("8");numbers.add("7");
        numbers.add("6");numbers.add("5");numbers.add("4");
        numbers.add("3");
        int index = 0;
        poker.put(index,"大王");
        pokerIndex.add(index);
        index++;
        poker.put(index,"小王");
        pokerIndex.add(index);
        index++;
        for (String number : numbers) {
            for(String color : colors) {
                poker.put(index,color+number);
                pokerIndex.add(index);
                index++;
            }
        }
        //System.out.println(poker);
        //System.out.println(pokerIndex);

        Collections.shuffle(pokerIndex);
        //System.out.println(pokerIndex);

        List<Integer> player01 = new ArrayList<>();
        List<Integer> player02 = new ArrayList<>();
        List<Integer> player03 = new ArrayList<>();
        List<Integer> dipai = new ArrayList<>();

        for(int i=0;i<pokerIndex.size();i++){
            Integer in = pokerIndex.get(i);
            if(i>=51){
                dipai.add(in);
            }else if(i%3==0){
                player01.add(in);
            }else if(i%3==1){
                player02.add(in);
            }else if(i%3==2){
                player03.add(in);
            }
        }
        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(dipai);
        printPoker("劉德華",poker,player01);
        printPoker("周潤發",poker,player02);
        printPoker("周星馳",poker,player03);
        printPoker("底  牌",poker,dipai);


    }
    public static void printPoker(String name, Map<Integer,String> poker, List<Integer> player){
        System.out.print(name + ":");
        for(Integer i:player){
            System.out.print(poker.get(i)+"\t");
        }
        System.out.println();
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章