Similar Threads

All the user's cards are dealt face up. Please don't laugh at my very-beginner simple code or don't laugh to hard I'm trying to learn java on my own. Blackjack History The origin of Blackjack, like many other casino games, is still debatable. Could I just copy the Javacode in the message? You should make your entire application more Object Oriented.

Your Answer

Blackjack History

Please don't laugh at my very-beginner simple code or don't laugh to hard I'm trying to learn java on my own. The code does work. If I would make one method to generate a card, should I use an other method to determine the value and one to determine if it's a ace or not? Or do I make it more difficult than I should by using multiple methods for a simple game? Making a simple blackjack game.

I'm trying to make a very simple blackjack game to play against the computer. I now made it, without using GUI in one class. It's quite big and now I want to try to make it possible to split.

However, I would like to make methods like "drawcard". Now I use a switch for this and call the "drawcard" method in the main class.

But, if I place my switch drawcard in an method in an other class, I can only return 1 variable, and I want to return more the name of the card, the points you get by it and if it's a ace or not. I just started with learning Java so sorry if I don't use the correct terms.

I can copy the code I have now, but then I have to translate some names of variables and text. Every card in the deck is equally likely to take the position of deckCards[51]. With the last element deckCards[51] thus fairly selected, repeat the process — randomly draw from the remaining card deck to fill its last element deckCards[50] , and so on for the entire deck. Aces are only 11, but not 1. This means the player or the dealer could bust with just the two cards they're dealt. Assuming they only had Aces, then it would be a bust with this code.

I would add a check to see if the player is busting, but that one of the cards was dealt as an Ace. Possibly even creating a boolean, PlayerHasAce. You would just need to make sure the boolean is set only ONCE per Ace though, and not repeated during the same hand. In addition to creating an object for Deck, an object for a player's hands and the dealer hand will also be useful.

In Blackjack a player may take different actions depending on the first two cards dealt, split or double. The player may also take different actions depending on the dealer's up card -- take insurance if it is an ace.

One of the first two cards is the up card. Finally you may consider a Game object that can deal hands, evaluate the winners of each round, keep score and display the results. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service , privacy policy and cookie policy , and that your continued use of the website is subject to these policies. Home Questions Tags Users Unanswered. First attempt at a Blackjack game Ask Question.

Niall Szalkai 2 6 You have a lot of multiline print statements that could probably be joined together; System. Jivings 2, 9 Since you asked about the validity of the comment in shuffleArray … This is what you wrote, ignoring the initial noise: This function shuffles its elements in place. The user should see all the dealer's cards at this point. Now, the winner can be determined: If the dealer has gone over 21, the user wins.

Otherwise, if the dealer's total is greater than or equal to the user's total, then the dealer wins. Otherwise, the user wins. Two notes on programming: At any point in the subroutine, as soon as you know who the winner is, you can say " return true ;" or " return false ;" to end the subroutine and return to the main program. To avoid having an overabundance of variables in your subroutine, remember that a function call such as userHand.

Write a main program that lets the user play several games of Blackjack. To make things interesting, give the user dollars, and let the user make bets on the game. If the user loses, subtract the bet from the user's money. If the user wins, add an amount equal to the bet to the user's money. End the program when the user wants to quit or when she runs out of money. Here is an applet that simulates the program you are supposed to write.

It would probably be worthwhile to play it for a while to see how it works. Sorry, your browser doesn't support Java. Let's start by designing the main program. Then, the user plays Blackjack games until the user runs out of money or until the user wants to quit.

We could ask the user after each game whether she wants to continue. But instead of this, I just tell the user to enter a bet amount of 0 if she wants to quit.

We need variables to represent the amount of money that the user has and the amount that the user bets on a given game. Let money and bet be variables of type int to represent these quantities.

Then, we can write an algorithm for the main program:. Since the Blackjack game will take place in a subroutine, we need some way for the main routine to find out whether the user won. The exercise says that the subroutine should be a function that returns a boolean value with this information. We should record the return value and test it to see whether the user won.

The other point that needs some refinement is inputting the user's bet. We better make sure that the user's bet is a reasonable amount, that is, something between 0 and the amount of money the user has.

How to Play Blackjack

Leave a Reply