Package controller
Class Controller
java.lang.Object
controller.Controller
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionChecks who wins the game and returns a message indicating the result.Deprecated.Deprecated.Deprecated.doubleGets the current player's balance.doublegetBet()Gets the current player's bet.getDealerCardFilePath(int i) getPlayerCardFilePath(int i) voidHits the player with aCard.voidsetBalance(double balance) Sets the player's current balance.voidsetBet(double bet) Sets the current player's bet.voidStarts a new round of the game.
-
Constructor Details
-
Controller
public Controller()ConstructsControllerobject. Initializes theDealerandPlayer, theDeckand 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
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 aCard. -
displayPlayerHand
Deprecated.- Returns:
- the player's current
Hand
-
displayPlayerHandValue
- Returns:
- the value of the player's
Hand
-
displayDealerHand
Deprecated.- Returns:
- the dealer's current
Hand
-
displayDealerHandValue
- Returns:
- the value of dealer's
Hand
-
displayDealerFirstCard
Deprecated.- Returns:
- the dealer's first
Card
-
displayDealerFirstCardValue
- Returns:
- the value of the first
Card
-
getDealerCardFilePath
-
getPlayerCardFilePath
-