/** @return true - if the game can be continued, false if the game has ended. */ public boolean playRound() { if (result != null) { return false; } round++; try { /* * if it's the first round, turn over the top card; otherwise, turn over the number of cards shown by the top * turned-over card */ if (round == 1) { topCard = deck.draw(); } else { List<Card> drawn = deck.draw(getTopCardValue()); topCard = drawn.get(drawn.size() - 1); } } catch (DeckExhaustedException e) { result = LOSE; return false; } if (deck.isEmpty()) { result = WIN; return false; } return true; }
public DoorsGame(Deck deck, CardValuePolicy valuePolicy) { if (deck == null) { throw new NullPointerException("Deck arg cannot be null."); } if (valuePolicy == null) { throw new NullPointerException("CardValuePolicy arg cannot be null."); } if (deck.isEmpty()) { throw new IllegalArgumentException("Cannot play with an empty deck."); } this.deck = deck; this.valuePolicy = valuePolicy; }