ood 4 (big class)

ODD4 


棋牌類的 我己經暈了, 換個類型

public enum Suit{
  Club;
  Diamond;
  Heart;
  Spade;
}


public class Card{
  private int faceValue; // 1 for A, 11 for J, 12 for Q, 13 for K. or we can use enum here
  private Suit suit;
  
  public Card(int c, Suit s){
    faceValue = c;
    suit = s;
  }
  
  public int value(){
    return faceValue:
  }
  
  public Suit suit(){
    return suit;
  }
}


public class Deck{
  private static final Random random = new Random();
  
  private final List<Card> cards = new ArrayList<>();
  private int dealtIndex = 0;
  
  public Deck(){
    for(int i = 1; i <= 13; i++){
      for(Suit suit : Suit.values()){
        cards.add(new Card(i, suit));
      }
    }
  }
  
  public void shuffle(){
    for(int i = 0; i < cards.size(); i++){
      int j = random.nextInt(cards.size() - i) + i;
      Card card1 = cards.get(i);
      Card card2 = cards.get(j);
      cards.set(i, card2);
      cards.set(j, card1);
    }
  }
  
  private int remainingCards(){
    return cards.size() - dealtIndex;
  }
  
相關文章
相關標籤/搜索