So i'm making an uno game where the user can ony play a card that has the same value or the same color as the card in the stock pile I currently have this as my code:
if(topPileCard().getColor()==card.getColor() || topPileCard().getValue() == card.getValue())
but if a user, for example, plays a green card the condition turns true only if the color matches and the value no longer works and vice versa Is there any way I can get around this?
and here is the code with uno cards class that has the getValue() and getColor() methods
public class UnoCard {
enum Color {
RED, BLUE, GREEN, YELLOW,BLACK;
private static final Color[] colors = Color.values();
public static Color getColor(int i){
return Color.colors[i];
}
}
enum Value {
ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, SKIP, DRAW_TWO, REVERSE, WILD, WILD_FOUR;
private static final Value[] values = Value.values();
public static Value getValue(int i){
return Value.values[i];
}
}
private final Color color;
private final Value value;
public UnoCard(final Color color, final Value value){
this.color = color;
this.value = value;
}
public Color getColor(){
return this.color;
}
public Value getValue(){
return this.value;
}
@Override
public String toString() {
return color + "_" + value;
}
}