Hey,
I'm implementing a simple "Play your cards right" (otherwise known as higher/lower) game. In case you've not come across it before the rules are really simple. A single suit of cards (e.g. hearts) are used. One card is drawn at a time and the objective is to correctly guess if the face value of the next card will be higher or lower than the face value of the previously drawn card.
The logic for the game isn't particularly complex, I'm not worried about that. I've come up with a design, but I am not entirely happy with it. There are a few areas where I'm sure that it could be improved, and that's what I would like your advice on. Here's an interface for the class (comments for additional understanding, not real comments):
public interface PlayYourCardsRight {
/**
* Get the number of cards remaining with higher face values than the previously
* drawn card
* @return
*/
public abstract int getNumberCardsHigher();
/**
* Get the number of cards remaining with lower face values than the previously
* drawn card
* @return
*/
public abstract int getNumberCardsLower();
/**
* Get all cards that have already been drawn in the order they were drawn in
*
*/
public abstract List<Card> getPlayedCards();
/**
* Simple prediction algorithm - if there are more cards left in the deck with
* lower face values than the previous card, then predict 'Lower', if there
* are more cards left in the deck with higher face values then predict
* 'Higher', if there are equal numbers of higher/lower cards pick 'higher' or 'lower'
* at random
*
* Prediction is an Enum (Higher/Lower/None)
*
*/
public abstract Prediction getPrediction();
/*
* Draw the next card at random
*/
public abstract void nextRound();
/**
* Specifiy what the next card should be
*
* @param card
*/
public abstract void nextRound(Card card);
}
As you can see it is all fairly self explanatory and simple. Here are my issues:
I do not want the constructor to automatically draw a card. This means that initially there is no "previously drawn card". I have a NO PREDICTION
value in the Prediction
enum but, as there is no "previously drawn card" the getNumberCardsHigher()
and getNumberCardsLower()
methods can't return sane values (they cannot also return sane values when all the cards from the deck have been drawn).
Obviously, I could simply throw an exception, but that seems like overkill - especially as then all calls to the methods then have to be wrapped in try/catches. I'm also unhappy with returning a negative value, since that could easily lead to some errors if someone forgets/can't be bothered to check for them.
All suggestions welcome!