模拟洗牌、发牌

package com.sina;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Card {
 public int playerNumber;
 public int cardNumber;
 
 String[]huase={"红桃","黑桃","方块","梅花"};
 String[]paivalue={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
 
 List car;

 public Card(int playerNumber, int cardNumber) {
  super();
  this.playerNumber = playerNumber;
  this.cardNumber = cardNumber;
  car=new ArrayList();
  for(int i=0;i    for(int j=0;j     car.add(huase[i]+paivalue[j]);
   }
  }
 }
 public void xipai(){
  Collections.shuffle(car);
 }
 public void fapai(){//方法1:
  int toallPai=car.size();
  List hand= car.subList(toallPai-cardNumber, toallPai);
  System.out.println(hand);
  hand.clear();//将发出的牌移除集合
  
  
 }
 public void fapai2(){//方法2:
  int toallPai=car.size();
  List hand= car.subList(toallPai-cardNumber, toallPai);
      List hand2 = new ArrayList(hand);
  hand.clear();//将发出的牌移除集合
  System.out.println(hand2);
  
  
 }
}


//建立一个测试类
package com.sina;

public class Test {

 public static void main(String[] args) {
  Card c=new Card(4,3);
  
  c.xipai();
  for(int i=0;i    System.out.print("第"+(i+1)+"位玩家牌值:");
   c.fapai();
   
  }

 }

}

你可能感兴趣的:(Study,Summarize)