Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you don't understand your boolean array. You currently have an array with 52 trues in it: <code>[true, true, true, true, ..., true]</code> That is all that your <code>deck</code> currently is. As I understand your code the array is representing a deck of cards merely by position. Element 0 in <code>deck</code> would refer to the Ace of Spades and element 51 in <code>deck</code> would refer to the King of Hearts.</p> <p>Each position in the array then refers to if the card is currently in the deck.</p> <pre><code>if(deck[0]) { System.out.println("This deck currently has an Ace of Spades"); } if(!deck[51]) { System.out.println("This deck currently does not have a King of Hearts"); } </code></pre> <p>Shuffle is placing every card into the deck so all it has to do is set every card to true. (You already do this in the constructor, presumable shuffle resets the deck).</p> <p>Deal is a little more complicated. You have to do the following:</p> <ol> <li>Check that cardsInDeck > 0</li> <li>Pick a random number 0 to 51 (using <code>dealer</code>)</li> <li>Check <code>if(deck[randomNumber])</code> if false pick a new number</li> <li>Set <code>deck[randomNumber] = false</code></li> <li>Decrease <code>cardsInDeck</code> by 1</li> </ol> <p>So basically you check that your deck has at least 1 card to deal. You then pick a random card from the deck. If the card doesn't exist in your deck then pick a new one. You then tell your deck that you have removed that card. Finally tell the deck that it has 1 fewer card total.</p> <p>EDIT: How to output the existing deck:</p> <pre><code>int card = 0; System.out.println("The deck contains the following: \n"); for(PlayingCard.CardSuit suit : PlayingCard.CardSuit.values()) { for(PlayingCard.CardRank rank : PlayingCard.CardRank.values()) { if(deck[ card++ ]) { System.out.println(rank + " of " + suit + "\n"); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload