回覆列表
  • 1 # 匠工加工

    import java.util.ArrayList;

    import java.util.Collections;

    import java.util.List;

    @SuppressWarnings("unchecked")

    public class XiPaiFaPai {

    List ALLP = new ArrayList();

    List player1 = new ArrayList();

    List palyer2 = new ArrayList();

    List player3 = new ArrayList();

    List player4 = new ArrayList();

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

    String[] numbers = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10",

    "J", "Q", "K" };//牌上數字

    String[] jokers = { "JOKER", "joker" };//大小王

    String[] two = { "▼", "▽" };//兩副牌

    public static void main(String[] args) {

    new XiPaiFaPai().xiPai_faPai();

    }

    public void xiPai_faPai() {

    for (int m = 0; m < two.length; m++) {

    for (int i = 0; i < types.length; i++) {

    for (int j = 0; j < numbers.length; j++) {

    ALLP.add(types[i] + numbers[j] + two[m]);

    }

    }

    for (int i = 0; i < jokers.length; i++) {

    ALLP.add(jokers[i] + two[m]);

    }

    }

    Collections.shuffle(ALLP);// 用Shuffle洗牌

    for (int i = 0; i < 27; i++) {

    player1.add(ALLP.remove(0)); // 做27次迴圈進行發牌

    palyer2.add(ALLP.remove(0));

    player3.add(ALLP.remove(0));

    player4.add(ALLP.remove(0));

    }

    System.out.println("玩家1:" + player1); // 列印每位玩家手裡的牌

    System.out.println("玩家2:" + palyer2);

    System.out.println("玩家3:" + player3);

    System.out.println("玩家4:" + player4);

    }

    }

    output:

    玩家1:[♣3▼, ♣2▽, ♥9▼, ♠3▽, ♠10▽, ♣2▼, ♠7▼, ♠4▼, ♦5▼, ♦4▼, ♠2▼, ♥7▼, ♣9▼, ♣10▼, ♣A▽, ♠6▽, ♥K▼, ♠8▽, ♠K▽, ♦4▽, joker▽, ♦Q▼, ♥9▽, ♣4▼, ♠5▽, ♣8▼, ♣J▼]

    玩家2:[♥4▽, ♦5▽, ♥6▽, ♣8▽, ♥10▽, ♦6▼, ♥Q▽, ♥2▼, ♦K▼, ♠2▽, ♠10▼, ♦Q▽, ♠6▼, ♠Q▽, ♦A▼, ♣Q▼, ♦7▼, ♠A▽, ♥2▽, ♥8▽, ♣J▽, ♦J▽, ♦3▼, ♣K▼, ♦K▽, ♠A▼, ♦7▽]

    玩家3:[♦8▼, ♥3▽, ♦6▽, ♣9▽, ♠8▼, ♠5▼, ♦8▽, ♦2▽, ♠9▼, ♣4▽, JOKER▽, ♥5▽, ♠9▽, ♦2▼, ♣3▽, ♠3▼, ♥6▼, ♦10▼, ♠K▼, ♦9▽, ♥A▽, ♥10▼, ♠7▽, ♥8▼, ♦J▼, ♥K▽, ♥J▼]

    玩家4:[joker▼, ♣7▽, JOKER▼, ♣5▼, ♣Q▽, ♦9▼, ♣K▽, ♥Q▼, ♠Q▼, ♦3▽, ♣6▽, ♥7▽, ♠J▼, ♣7▼, ♠J▽, ♦A▽, ♦10▽, ♥4▼, ♣6▼, ♣A▼, ♣10▽, ♥A▼, ♥3▼, ♠4▽, ♣5▽, ♥5▼, ♥J▽]

  • 中秋節和大豐收的關聯?
  • 華為mate40pro雙卡還是單卡?