斗地主洗牌发牌的逻辑

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

public class Demo_斗地主洗牌发牌的逻辑 {

public static void main(String[] args) {


ArrayList cards=new ArrayList();

//定义点数;
String[] points={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

//定义花色;
String[] colors={"♥" , "♦" , "♠" , "♣"};

for(String ds:points)
    for (String co:colors)
    {  cards.add(ds+co);}

    cards.add("小☠");
    cards.add("大☠");

    System.out.println("新牌:");
    System.out.println(cards);

    //LinkedList list= new LinkedList<>();

    //洗牌;
    Collections.shuffle(cards);
    System.out.println("洗牌后:");
    System.out.println(cards);
    //创建角色玩家;
    ArrayList player01=new ArrayList<>();
    ArrayList player02=new ArrayList<>();
    ArrayList player03=new ArrayList<>();
    ArrayList lastthree=new ArrayList<>();

    //发牌;
    for (int i = 0; i =51)
          lastthree.add(cards.get(i));
        else if(i%3==0)
            player01.add(cards.get(i));
        else if(i%3==1)
            player02.add(cards.get(i));
        else if(i%3==2)
            player03.add(cards.get(i));
    }
    if(player01.contains("大☠"))
        player01.addAll(lastthree);
    else if(player02.contains("大☠"))
        player02.addAll(lastthree);
    else if(player03.contains("大☠"))
        player03.addAll(lastthree);

    System.out.println("玩家1");
    System.out.println(player01);
    System.out.println("玩家2");
    System.out.println(player02);
    System.out.println("玩家3");
    System.out.println(player03);
    System.out.println("底牌:");
    System.out.println(lastthree);




}

}

你可能感兴趣的:(Java类应用)