Esempio n. 1
0
  /**
   * 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;
  }
Esempio n. 2
0
  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;
  }