发牌

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();
 }
 
}

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注