JAVA模拟扑克牌洗牌发牌

代码实现

    public static void main(String[] args){
   //1.新建54牌
    List pokes = new ArrayList<>();
    List colors = new ArrayList<>();
    List numbers = new ArrayList<>();

    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");

    for(String c:colors){
        for(String n:numbers){
            String poker=c+n;
            pokes.add(poker);
        }
    }
    pokes.add("BigJoker");
    pokes.add("SmallJoker");
    System.out.println("生成纸牌"+pokes+"\n");
    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");

    for(String c:colors){
        for(String n:numbers){
            String poker=c+n;
            pokes.add(poker);
        }
    }
    pokes.add("BigJoker");
    pokes.add("SmallJoker");
    System.out.println("生成纸牌"+pokes+"\n");


    Collections.shuffle(pokes);
    System.out.println("洗牌"+pokes+"\n");

    //3.留3张底牌
    //4.发牌
    ArrayList x = new ArrayList<>();
    ArrayList y = new ArrayList<>();
    ArrayList z = new ArrayList<>();
    ArrayList FinalCard = new ArrayList<>();
    for(int i=0;i=51){
            FinalCard.add(poker);
        }else{
            if(i%3==0){
                x.add(poker);
            }else if(i%3==1){
                y.add(poker);
            }else{
                z.add(poker);
            }
        }
    }
    System.out.println("发牌后:");
    System.out.println("底牌"+FinalCard);
    System.out.println("x"+x);
    System.out.println("y"+y);
    System.out.println("z"+z+"\n");

    //5.理牌
    Collections.sort(x);
    Collections.sort(y);
    Collections.sort(z);
    Collections.sort(FinalCard);

    System.out.println("整理后:");
    System.out.println("底牌"+FinalCard);
    System.out.println("x"+x);
    System.out.println("y"+y);
    System.out.println("z"+z);
}

你可能感兴趣的:(JAVA模拟扑克牌洗牌发牌)