发牌
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();
}
}
總結
- 上一篇: 现在去北京需要隔离吗(北京居民现在还能出
- 下一篇: win10 恢复分区怎么删除