/** * CS 231 — Project 1 * Blackjack * * Purpose: * Runs the simplified Blackjack game used in Project 1. */ public class Blackjack { // TODO: Declare private instance variables for: // - the Deck // - the player's Hand // - the dealer's Hand /** * Constructs a new Blackjack game. */ public Blackjack() { // TODO: // 1. Create the Deck. // 2. Create the player's Hand. // 3. Create the dealer's Hand. // // The Deck constructor calls build(), and build() shuffles the // completed deck, so the initial Deck is ready to use. } /** * Resets the game for a new hand. * * Both hands become empty. If fewer than 26 cards remain in the deck, * build() replaces it with a complete, shuffled 52-card deck. */ public void reset() { // TODO: Reset the player and dealer Hands. // // TODO: If fewer than 26 Cards remain, call build() on the Deck. // build() already shuffles the newly completed Deck. } /** * Deals two cards to the player and two cards to the dealer. */ public void deal() { // TODO: Deal two Cards to each Hand from the Deck. } /** * Plays the player's turn. * * The player draws until the hand value is at least 16. * * @return false if the player busts; true otherwise */ public boolean playerTurn() { // TODO: Keep dealing to the player while the total is below 16. // // TODO: Return whether the player avoided going over 21. return false; } /** * Plays the dealer's turn. * * The dealer draws until the hand value is at least 17. * * @return false if the dealer busts; true otherwise */ public boolean dealerTurn() { // TODO: Keep dealing to the dealer while the total is below 17. // // TODO: Return whether the dealer avoided going over 21. return false; } /** * Returns a String describing the current state of the game. * * @return the current player and dealer hands */ public String toString() { // TODO: Return a clear representation of both Hands. return ""; } /** * Plays one complete game of Blackjack. * * game() does not reset the game before playing. The caller should call * reset() after recording the result and before starting the next game. * * @param verbose if true, print the initial and final hands and the result * @return -1 for dealer win, 0 for push (tie), 1 for player win */ public int game(boolean verbose) { // TODO: // 1. deal() the initial hands. // 2. If verbose is true, print the initial hands. // 3. Play the player's turn. // 4. If the player did not bust, play the dealer's turn. // 5. Determine the result. // 6. If verbose is true, print the final hands and the result. // 7. Return -1, 0, or 1. return 0; } /** * Plays one verbose game so that Blackjack can be run directly. */ public static void main(String[] args) { Blackjack game = new Blackjack(); game.game(true); } }