/**
   * Verifies that three given Cards constitute a set
   *
   * @param card1 first Card
   * @param card2 second Card
   * @param card3 third Card
   * @return true if the three Cards constitute a set false if the three Cards do not constitute a
   *     set
   */
  public boolean checkForSet(Card card1, Card card2, Card card3) {
    // SET isSet to true
    boolean isSet = true;

    // IF card1 and card2 and card3 are null
    if (card1 == null || card2 == null || card3 == null) {
      // SET isSet to false
      isSet = false;
    }
    // ELSE IF card1 == card2 and card2 == card3 and card1 == card3
    else if (card1.equals(card2) && card2.equals(card3) && card1.equals(card3)) {
      // SET isSet to false
      isSet = false;
    }
    // ELSE
    else {
      // SET isSet to the AND of the return value of isFeatureSet with
      // each cards color
      isSet &= isFeatureSet(card1.getColor(), card2.getColor(), card3.getColor());
      // SET isSet to the AND of the return value of isFeatureSet with
      // each cards shape
      isSet &= isFeatureSet(card1.getShape(), card2.getShape(), card3.getShape());
      // SET isSet to the AND of the return value of isFeatureSet with
      // each cards fill
      isSet &= isFeatureSet(card1.getFill(), card2.getFill(), card3.getFill());
      // SET isSet to the AND of the return value of isFeatureSet with
      // each cards number
      isSet &= isFeatureSet(card1.getNumber(), card2.getNumber(), card3.getNumber());
    }
    // END IF

    // RETURN isSet
    return isSet;
  }
  private Integer getCardCount(Card referencia) {

    Integer contador = 0;
    for (Card item : this.cards) {
      if (referencia.getNumber() == item.getNumber()) {
        contador = contador + 1;
      }
    }

    return contador;
  }
Beispiel #3
0
  public CardPanel(Card card) {
    // Prueba Borrar
    String colorCard;
    this.card = card;
    String cardColor = card.getColor(), cardType = card.getType(), imagePath = null;

    if (cardColor != null) {
      setBackground(getColor(cardColor));
    }

    if (cardType.equals("Number")) {
      imagePath = card.getNumber();
      System.out.print("Numero " + imagePath);

    } else {
      imagePath = card.getType();
    }

    setSize(150, 200);
    try {
      image = ImageIO.read(new File(imagePath + ".png"));
    } catch (IOException e) {
      System.out.println("Error IO " + imagePath);
      System.out.println(" largo " + cardType.length());
    }
  }
Beispiel #4
0
 /**
  * Checks to see if a certain card is in the memory.
  *
  * @param c The card to check.
  * @return True if it is in the memory, else false.
  */
 public boolean contains(Card c) {
   for (int i = 0; i < memory.size(); i++) {
     if (memory.get(i).getNumber() == c.getNumber() && memory.get(i).getSuit() == c.getSuit()) {
       return true;
     }
   }
   return false;
 }
  private boolean isStraight() {
    TreeSet<Card> treeSet = new TreeSet<Card>(this.cards);
    Iterator<Card> iterator = treeSet.iterator();
    Card primeiraCarta = iterator.next();
    int proximoNumero = primeiraCarta.getNumber() + 1;

    while (iterator.hasNext()) {
      Card carta = iterator.next();
      if (carta.getNumber() != proximoNumero) {
        if (!iterator.hasNext() && primeiraCarta.getNumber() == 2 && carta.getNumber() == 14) {
          return true;
        } else {
          return false;
        }
      } else {
        proximoNumero = carta.getNumber() + 1;
      }
    }

    return true;
  }
  private boolean isTwoPairs() {

    Map<Integer, Integer> mapCartas = new HashMap<Integer, Integer>();
    Integer contadorPares = 0;

    for (int index = 0; index < this.cards.size(); index++) {
      Card carta = this.cards.get(index);
      if (!mapCartas.containsKey(carta.getNumber())) {
        Integer quantidade = this.getCardCount(carta);
        mapCartas.put(carta.getNumber(), quantidade);

        if (quantidade == 2 && contadorPares == 1) {
          return true;
        } else if (quantidade == 2) {
          contadorPares = contadorPares + 1;
        }
      }
    }

    return false;
  }
Beispiel #7
0
  private Card getCard(String number, String expire, int crypt) {
    // This is the method where we should access the database
    // and request the cards...

    // Mock //

    ArrayList<Card> cards = new ArrayList<Card>();
    cards.add(new Card("0000000000000000", "12/17", 124, 5500, "EUR"));
    cards.add(new Card("1111111111111111", "12/17", 124, 50, "USD"));
    cards.add(new Card("2222222222222222", "12/17", 124, 150000, "JPY"));
    for (Card card : cards) {
      if (card.getNumber().equals(number)
          && card.getExpire().equals(expire)
          && card.getCrypt() == crypt) {
        return card; // As soon as we find the corresponding card, we return it.
      }
    }

    return null;

    // Mock End //

  }
package store;
 @Test
 public void number() {
   assertTrue(card.getNumber() == number);
 }
Beispiel #10
0
 public boolean isLowerOneNumber(Card card) {
   if (this.number + 1 == card.getNumber()) {
     return true;
   } else return false;
 }
  private String getReasons(boolean set) {
    String retString = "";

    Card c1 = getInlayCard(new Natural(0));
    Card c2 = getInlayCard(new Natural(1));
    Card c3 = getInlayCard(new Natural(2));

    if (set) {
      if (c1.getColor() == c2.getColor() && c1.getColor() == c3.getColor()) {
        retString = retString + "-All cards are " + c1.getColor() + "\n";
      } else {
        retString = retString + "-All cards have different colors\n";
      }

      if (c1.getFill() == c2.getFill() && c1.getFill() == c3.getFill()) {
        retString = retString + "-All cards have a " + c1.getFill() + " fill\n";
      } else {
        retString = retString + "-All cards have a different fill\n";
      }

      if (c1.getNumber() == c2.getNumber() && c1.getNumber() == c3.getNumber()) {
        retString = retString + "-All cards are of number " + c1.getNumber() + "\n";
      } else {
        retString = retString + "-All cards have different number\n";
      }

      if (c1.getShape() == c2.getShape() && c1.getShape() == c3.getShape()) {
        retString = retString + "-All cards are " + c1.getShape() + " shapes\n";
      } else {
        retString = retString + "-All cards are have different shapes\n";
      }
    } else {
      if (!isFeatureSet(c1.getColor(), c2.getColor(), c3.getColor())) {
        if (c1.getColor() == c2.getColor()) {
          retString =
              retString + "-Card1 and Card2 have same color but Card3 has a different color\n";
        } else if (c1.getColor() == c3.getColor()) {
          retString =
              retString + "-Card1 and Card 3 have same color but Card2 has a different color\n";
        } else if (c2.getColor() == c3.getColor()) {
          retString =
              retString + "-Card2 and Card3 have same color but Card1 has a different color\n";
        }
      }
      if (!isFeatureSet(c1.getFill(), c2.getFill(), c3.getFill())) {
        if (c1.getFill() == c2.getFill()) {
          retString =
              retString + "-Card1 and Card2 have same fill but Card3 has a different fill\n";
        } else if (c1.getFill() == c3.getFill()) {
          retString =
              retString + "-Card1 and Card 3 have same fill but Card2 has a different fill\n";
        } else if (c2.getFill() == c3.getFill()) {
          retString =
              retString + "-Card2 and Card3 have same fill but Card1 has a different fill\n";
        }
      }
      if (!isFeatureSet(c1.getNumber(), c2.getNumber(), c3.getNumber())) {
        if (c1.getNumber() == c2.getNumber()) {
          retString =
              retString + "-Card1 and Card2 have same number but Card3 has a different number\n";
        } else if (c1.getNumber() == c3.getNumber()) {
          retString =
              retString + "-Card1 and Card 3 have same number but Card2 has a different number\n";
        } else if (c2.getNumber() == c3.getNumber()) {
          retString =
              retString + "-Card2 and Card3 have same number but Card1 has a different number\n";
        }
      }
      if (!isFeatureSet(c1.getShape(), c2.getShape(), c3.getShape())) {
        if (c1.getShape() == c2.getShape()) {
          retString =
              retString + "-Card1 and Card2 have same shape but Card3 has a different shape\n";
        } else if (c1.getShape() == c3.getShape()) {
          retString =
              retString + "-Card1 and Card 3 have same shape but Card2 has a different shape\n";
        } else if (c2.getShape() == c3.getShape()) {
          retString =
              retString + "-Card2 and Card3 have same shape but Card1 has a different shape\n";
        }
      }
    }

    return retString;
  }