zoukankan      html  css  js  c++  java
  • 集合模拟斗地主

    集合模拟斗地主

    public class Demo04Main {
      public static void main(String[] args) {
          //1、准备牌
          ArrayList<String> poker = new ArrayList<>();

          String[] colors = {"♥","♠","♦","♣"};
          String[] nums = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
          poker.add("大王");
          poker.add("小王");

          for (String color : colors) {
              for (String num : nums) {
                  poker.add(color + num);
              }
          }
          System.out.println(poker);
          /*Iterator<String> it = poker.iterator();
          while (it.hasNext()){
              System.out.print(it.next());
          }*/

          //2、洗牌
          Collections.shuffle(poker);

          //3、发牌
          ArrayList<String> play1 = new ArrayList<>();
          ArrayList<String> play2 = new ArrayList<>();
          ArrayList<String> play3 = new ArrayList<>();
          ArrayList<String> dipai = new ArrayList<>();

          //3张底牌
          for (int i = 0; i < poker.size(); i++) {
              String s = poker.get(i);
              if (i>=51){
                  dipai.add(s);
              }else if (i % 3 == 0){
                  play1.add(s);
              }else if (i % 3 == 1){
                  play2.add(s);
              }else if (i % 3 == 2){
                  play3.add(s);
              }
          }

          //4看牌
          System.out.println(play1);
          System.out.println(play2);
          System.out.println(play3);
          System.out.println(dipai);
      }
    }

    运行结果:
    [♦4, ♦Q, ♠9, ♣8, ♦A, ♣K, ♥5, ♠8, ♥J, ♠4, ♣4, ♦10, ♦6, ♥7, ♠2, ♣3, ♠10]
    [♠7, ♥6, ♠Q, ♠J, ♦J, ♠K, ♣5, ♥K, 小王, ♣2, ♥8, ♠A, ♣9, ♣7, 大王, ♦8, ♦K]
    [♠5, ♥A, ♠6, ♥Q, ♣Q, ♦5, ♥4, ♦7, ♦3, ♠3, ♥9, ♦9, ♣10, ♥2, ♥3, ♣J, ♣6]
    [♣A, ♥10, ♦2]

     

  • 相关阅读:
    新單詞
    custom preview link
    注冊碼
    准备用VB.Net 写一个律师管理的系统
    Windows服務
    下一步
    失败
    如何在篩選聯絡人時控制只能篩選上層客戶的聯絡人.
    如何取Lookup欄位的值
    Dynamic Picklist Sample
  • 原文地址:https://www.cnblogs.com/lxy522/p/12818789.html
Copyright © 2011-2022 走看看