Create a simple blackjack game with rules below in JAVA FX using images and such
ID: 3919826 • Letter: C
Question
Create a simple blackjack game with rules below in JAVA FX using images and such.
The player and dealer are each dealt 2 cards. All of the players cards are dealt face up, the dealers first two cards are dealt one face up and one face down. After the card dealing, the player is given the option to either hit (draw a card) or stand (end their turn). The player may hit as many times as they want until they either go over 21 or they wish to stand. If the player goes over 21, they lose the round and the dealer wins.
Explanation / Answer
public class Bjack { public static void main(String[] args) { int m; // Amount of money the user has. int b; // Amount user bets on a game. boolean useWins; // Did the user win the game? TextIO.putln("Welcome to the game of bjack."); TextIO.putln(); m = 100; while (true) { TextIO.putln("You have " + m + " dollars."); do { TextIO.putln("How many dollars do you want to b? (Enter 0 to end.)"); TextIO.put("? "); b = TextIO.getlnInt(); if (b < 0 || b > m) TextIO.putln("Your answer must be between 0 and " + m + '.'); } while (b < 0 || b > m); if (b == 0) break; useWins = playBjack(); if (useWins) m = m + b; else m = m - b; TextIO.putln(); if (m == 0) { TextIO.putln("Looks like you've are out of m!"); break; } } TextIO.putln(); TextIO.putln("You leave with $" + m + '.'); } static boolean playBjack() { Deck deck; BjackHand dHand; BjackHand useHand; deck = new Deck(); dHand = new BjackHand(); useHand = new BjackHand(); deck.shuffle(); dHand.addCard( deck.dealCard() ); dHand.addCard( deck.dealCard() ); useHand.addCard( deck.dealCard() ); useHand.addCard( deck.dealCard() ); TextIO.putln(); TextIO.putln(); if (dealerHand.getBjackValue() == 21) { TextIO.putln("D has the " + dHand.getCard(0) + " and the " + dHand.getCard(1) + "."); TextIO.putln("Use has the " + useHand.getCard(0) + " and the " + useHand.getCard(1) + "."); TextIO.putln(); TextIO.putln("Dealer has Bjack. D wins."); return false; } if (useHand.getBjackValue() == 21) { TextIO.putln("D has the " + dHand.getCard(0) + " and the " + dHand.getCard(1) + "."); TextIO.putln("Use has the " + useHand.getCard(0) + " and the " + useHand.getCard(1) + "."); TextIO.putln(); TextIO.putln("You have Bjack. You win."); return true; } while (true) { TextIO.putln(); TextIO.putln(); TextIO.putln("Your cards are:"); for ( int i = 0; i 21) { TextIO.putln(); TextIO.putln("You busted by going over 21. You lose."); TextIO.putln("D other card was the " + dHand.getCard(1)); return false; } } } TextIO.putln(); TextIO.putln("Use stands."); TextIO.putln("D cards are"); TextIO.putln(" " + dHand.getCard(0)); TextIO.putln(" " + dHand.getCard(1)); while (dealerHand.getBjackValue() 21) { TextIO.putln(); TextIO.putln("D busted by going over 21. You win."); return true; } } TextIO.putln("Dealer's total is " + dHand.getBjackValue()); TextIO.putln(); if (dHand.getBjackValue() == useHand.getBjackValue()) { TextIO.putln("Dealer wins on a tie. You lose."); return false; } else if (dHand.getBjackValue() > useHand.getBjackValue()) { TextIO.putln("D wins, " + dHand.getBjackValue() + " points to " + useHand.getBjackValue() + "."); return false; } else { TextIO.putln("You win, " + useHand.getBjackValue() + " points to " + dHand.getBjackValue() + "."); return true; } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.