Re: Designing a Card Game
Well, IMO, in games where ACES (or any card) that can be in more than
one places should be checked using rules. The links that Kriwan
provided had some evaluator classes which I think is how you can deal
with placing the cards correctly.
Here is another interesting question. Using comparable, you can find
whether one card is before or after another, but can you find how many
"steps" is it? I thought enum had an easy way of finding the index of
an element but it doesn't. So, what do you think about this solution:
public enum Rank {
ACE(1),TWO(2),THREE(3),FOUR(4),FIVE(5),SIX(6),SEVEN(7),EIGHT(8),NINE(9),TEN(10),JACK(11),QUEEN(12),KING(13);
private int index;
private Rank(int index) { this.index = index; }
public int getIndex() { return this.index; }
}
And yet another. Let's say that we have a Card class that other than
having a Rank and a Suit it has a Face (whether it is faced up or
down). Face.UP means that you can see the Rank and Suit of a Card
while Face.DOWN you cannot (think of cards in Klondike Solitaire).
Now, if a card is faced down and an object calls getRank() or
getSuit(), would throwing an Exception("The card is faced down, you
cannot see the rank or suit") be a good implementation or is this not
needed?
Sorry for extending this discussion further than it's original
topic. ;)