zoukankan      html  css  js  c++  java
  • 发牌

    package com.lovo.pai;

    public class TestCard {

     public static void main(String[] args) {

      // TODO Auto-generated method stub  

     Card card = new Card(4,13);

      card.xiPai();

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

     card.faPai();   

    }

     }

    }

    package com.lovo.pai;

    import java.util.ArrayList;

    import java.util.Collections;

    import java.util.List;

    public class Card {
     
     private int playNumber;//玩家人数
     
     private int cardNumber;//每个玩家发多少张牌
     
     private String[] huase = {"黑桃","红桃","梅花","方块"};


     private String[] paiValue = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
     
     private List<String> allCards;

    public Card(int playNumber, int cardNumber){
      this.playNumber = playNumber;
      this.cardNumber = cardNumber;
      this.allCards = new ArrayList<String>();
      for(int i = 0; i < huase.length; i++){
       for(int j = 0; j < paiValue.length; j++){
        this.allCards.add(huase[i] + paiValue[j]);
       }
      }
     }


     public void xiPai(){
      Collections.shuffle(this.allCards);
     }
     
     public void faPai(){
      int allNum = this.allCards.size();//牌堆总张数
      List<String> outLst = this.allCards.subList(allNum - this.cardNumber, allNum);
      System.out.print("本轮发牌:");
      for(String card : outLst){
       System.out.print(card + " ");
      }
      System.out.println();
      outLst.clear();
     }
     
    }

  • 相关阅读:
    Docker简介安装与下载
    ActiveMq安装以及简单的测试
    HashMap源码解析<一>put()方法
    SQL语句查询练习题
    珍藏的数据库SQL基础练习题答案
    MySQL习题及答案
    Hadoop学习1
    数据库简单的实际应用
    数据库基础练习选择题
    数据库练习题
  • 原文地址:https://www.cnblogs.com/-xhx/p/5598813.html
Copyright © 2011-2022 走看看