Package controller

Class Controller

java.lang.Object
controller.Controller

public class Controller extends Object

The Controller class is responsible for handling most of the game logic for a Blackjack game.

It creates a new instance of the Dealer and Player classes, initializes the deck with a new shuffled and populated Deck object, and keeps track of the bet and balance of the player. It also keeps track of game statistics using a Statistics object.

Author:
Michael Neuper michael@michaelneuper.com
  • Constructor Details

    • Controller

      public Controller()
      Constructs Controller object. Initializes the Dealer and Player, the Deck and discarded decks, and the bet and balance of the player. The deck is also populated and shuffled.
  • Method Details

    • getBet

      public double getBet()
      Gets the current player's bet.
      Returns:
      the player's current bet
    • setBet

      public void setBet(double bet)
      Sets the current player's bet. If it is greater than the total balance, an error is displayed.
      Parameters:
      bet - the bet amount
    • getBalance

      public double getBalance()
      Gets the current player's balance.
      Returns:
      the player's current balance
    • setBalance

      public void setBalance(double balance)
      Sets the player's current balance.
      Parameters:
      balance - player's balance
    • startRound

      public void startRound()

      Starts a new round of the game.

      Discards the dealer and player hands to the discarded deck if there are no cards left, and reloads the deck from the discarded deck if there are fewer than four cards left. Deals two cards to the dealer and two cards to the player.

    • checkWhoWins

      public String checkWhoWins()
      Checks who wins the game and returns a message indicating the result. Increments game statistics for wins, losses, and pushes.
      Returns:
      a message indicating the result of the game
    • hitPlayer

      public void hitPlayer()
      Hits the player with a Card.
    • displayPlayerHand

      @Deprecated public String displayPlayerHand()
      Deprecated.
      Returns:
      the player's current Hand
    • displayPlayerHandValue

      public String displayPlayerHandValue()
      Returns:
      the value of the player's Hand
    • displayDealerHand

      @Deprecated public String displayDealerHand()
      Deprecated.
      Returns:
      the dealer's current Hand
    • displayDealerHandValue

      public String displayDealerHandValue()
      Returns:
      the value of dealer's Hand
    • displayDealerFirstCard

      @Deprecated public String displayDealerFirstCard()
      Deprecated.
      Returns:
      the dealer's first Card
    • displayDealerFirstCardValue

      public String displayDealerFirstCardValue()
      Returns:
      the value of the first Card
    • getDealerCardFilePath

      public String getDealerCardFilePath(int i)
      Parameters:
      i - index of the card in the dealer's Hand
      Returns:
      file path of the dealer's Card
    • getPlayerCardFilePath

      public String getPlayerCardFilePath(int i)
      Parameters:
      i - index of the card in the player's Hand
      Returns:
      file path of player's Card