Ejemplo n.º 1
0
bool Deck::isSet(Card c1, Card c2, Card c3)
{
  //ALL THREE CARDS MUST:
  //1) have the same number or 3 different numbers
  //2) have the same shading or 3 different shadings
  //3) have the same shape or 3 different shapes
  //4) have the same color or 3 different colors
  bool numbers = false;
  bool shading = false;
  bool shape = false;
  bool color = false;
  if ((c1.doesNumberMatch(c2) && c1.doesNumberMatch(c3)) || 
      !(c1.doesNumberMatch(c2) && c1.doesNumberMatch(c3)))
  {
    numbers = true;
  }
   if ((c1.doesShadingMatch(c2) && c1.doesShadingMatch(c3)) || 
      !(c1.doesShadingMatch(c2) && c1.doesShadingMatch(c3)))
  {
    shading = true;
  }
 if ((c1.doesShapeMatch(c2) && c1.doesShapeMatch(c3)) || 
      !(c1.doesShapeMatch(c2) && c1.doesShapeMatch(c3)))
  {
    shape = true;
  }
 if ((c1.doesColorMatch(c2) && c1.doesColorMatch(c3)) || 
      !(c1.doesColorMatch(c2) && c1.doesColorMatch(c3)))
  {
    color = true;
  }
  
  if (numbers && shading && shape && color) //all conditions met, cards are a set
     return true; 
  else //if not all conditions are met, it is not a set
     return false;

}//checks if the 3 cards the user chooses creates a set or not...