Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 KB | None | 0 0
  1. package ch.epfl.javass.jass;
  2.  
  3. import ch.epfl.javass.Preconditions;
  4. import ch.epfl.javass.bits.Bits32;
  5.  
  6. public final class Trick {
  7.    
  8.     private final int packed;
  9.     public static final Trick INVALID = new Trick(PackedTrick.INVALID);
  10.    
  11.     private Trick(int packed){
  12.         this.packed = packed;
  13.     }
  14.    
  15.     public int packed() {
  16.         return packed;
  17.     }
  18.    
  19.     public int index() {
  20.         return PackedTrick.index(this.packed());
  21.     }
  22.     public Card.Color trump(){
  23.         return PackedTrick.trump(this.packed());
  24.     }
  25.    
  26.     public Card.Color baseColor(){
  27.         if (PackedTrick.size(this.packed) != 0){
  28.             return PackedTrick.baseColor(this.packed());
  29.         }
  30.         else throw new IllegalStateException();
  31.     }
  32.    
  33.     public static Trick ofPacked(int packed) {
  34.         Preconditions.checkArgument(PackedTrick.isValid(packed));
  35.         Trick trick = new Trick(packed);
  36.         return trick;
  37.     }
  38.    
  39.     public static Trick firstEmpty(Card.Color trump, PlayerId firstPlayer) {
  40.         return ofPacked(PackedTrick.firstEmpty(trump, firstPlayer));
  41.     }
  42.    
  43.     public Trick nextEmpty() {
  44.         if (!PackedTrick.isFull(this.packed())) {
  45.             throw new IllegalStateException();
  46.         }
  47.         return new Trick(PackedTrick.nextEmpty(this.packed()));
  48.     }
  49.    
  50.     public boolean isEmpty() {
  51.         return PackedTrick.isEmpty(this.packed());
  52.     }
  53.    
  54.     public boolean isFull() {
  55.         return PackedTrick.isFull(this.packed());
  56.     }
  57.    
  58.     public boolean isLast() {
  59.         return PackedTrick.isLast(this.packed());
  60.     }
  61.    
  62.     public int size() {
  63.         return PackedTrick.size(this.packed);
  64.     }
  65.    
  66.     public PlayerId player(int index) {
  67.         if (index >= 4 || index <0) {
  68.             throw new IndexOutOfBoundsException();
  69.         }
  70.         else {
  71.             return PackedTrick.player(this.packed(), index);
  72.         }
  73.     }
  74.    
  75.     public Card card(int index) {
  76.         if (index >= PackedTrick.size(this.packed()) || index <0) {
  77.             throw new IndexOutOfBoundsException();
  78.         }
  79.         else {
  80.             return Card.ofPacked(PackedTrick.card(this.packed(), index));
  81.         }
  82.     }
  83.    
  84.     public Trick withAddedCard(Card c) {
  85.         if (PackedTrick.size(this.packed()) == 4) {
  86.             throw new IllegalStateException();
  87.         }
  88.         else {
  89.             return ofPacked(PackedTrick.withAddedCard(this.packed(), c.packed()));
  90.         }
  91.     }
  92.    
  93.     public int points() {
  94.         return PackedTrick.points(this.packed);
  95.     }
  96.    
  97.     public PlayerId winningPlayer() {
  98.         if (PackedTrick.size(this.packed()) == 0) {
  99.             throw new IllegalStateException();
  100.         }
  101.         else {
  102.             return PackedTrick.winningPlayer(this.packed());
  103.         }
  104.     }
  105.    
  106.     public boolean equals(Object that0) {
  107.         if (that0 != null && (that0.getClass().equals(this.getClass()))) {
  108.             if (that0 instanceof Trick) {
  109.                 Trick trick = (Trick) that0;
  110.                 return (this.packed() == trick.packed());
  111.             } else {
  112.                 return false;
  113.             }
  114.         } else {
  115.             return false;
  116.         }
  117.     }
  118.    
  119.     public CardSet playableCards(CardSet hand) {
  120.         if (PackedTrick.isFull(this.packed())) {
  121.             throw new IllegalStateException();
  122.         }
  123.         else {
  124.             return CardSet.ofPacked(PackedTrick.playableCards(this.packed(), hand.packed()));
  125.         }
  126.     }
  127.    
  128.     public int hashCode() {
  129.         return Integer.hashCode(this.packed());
  130.     }
  131.    
  132.     public String toString() {
  133.         return PackedTrick.toString(this.packed());
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement