Creating a Blackjack Game

Hey yall (particularly flounder ;D),
Today, I have to create a simple, text-based Blackjack game. I haven't written any code for it yet, but I've begun making my plan in "simple english". Does this look right to you?
-Create an array for all 52 cards in a deck.
-Value each of the cards from 1-13 x 4 suits
-Create switch statements for the face cards, and make their values 10
-Create a switch statement for the aces (how do I make their values 1 or 11?)
-Create a loop system for drawing cards, which lets you draw another as long as you are under 21
-Dealer automatically wins if you go over
-Create a loop system for the dealer
-He will keep drawing as long as his value is under yours, but not over 21.
-Create a choice to play again.
I'm really new to Java, I've only been doing it for a few days or so, and I'm not sure what commands to use. In fact, I've never even made an array before (but I have been reading up on them as of today).
Thanks,
Apple Pie

I've decided to skip the array part, as it was just confusing me.. I know it wont be as proper, because you can draw any card an unlimited amount of times.. but...whatever.
Here's what I got so far... each player draws 2 cards... the jacks, queens and kings still count as 11, 12 and 13... I'm not sure how to change that... and I still have to put in the ace, which I'm not sure how to make count for 1 and 11..
I also have to code the ability to draw after your two initial cards..
import java.io.*;
import java.util.*;
import hsa.Console;
public class blackjack12
    static Console c=
    new Console ();
    static public void main (String[] args)
    Random randomNumbers = new Random ();
        int playercard = 1 + randomNumbers.nextInt(11)+1;
        int dealercard = 1 + randomNumbers.nextInt(11)+1;
        int playertotal = playercard + playercard;
        int dealertotal = dealercard + dealercard;
            if (playercard <= 10 && playercard != 1)
                c.println("You drew a " +playercard);
            if (playercard == 11)
                c.println("You drew a Jack ");
            else if (playercard == 12)
                c.println("You drew a Queen" );
            else if (playercard == 13)
                c.println("You drew a King" );
            if (playercard <= 10 && playercard != 1)
                c.println("And you drew a " +playercard);
            if (playercard == 11)
                c.println("And you drew a Jack ");
            else if (playercard == 12)
                c.println("And you drew a Queen" );
            else if (playercard == 13)
                c.println("And you drew a King" );
            c.println("Your total is: " +playertotal);
            if (dealercard <= 10 && dealercard != 1)
                c.println("The dealer drew a " +dealercard);
            if (dealercard == 11)
                c.println("The dealer a Jack ");
            else if (dealercard == 12)
                c.println("The dealer drew a Queen" );
            else if (dealercard == 13)
                c.println("The dealer drew a King" );
            if (dealercard <= 10 && dealercard != 1)
                c.println("And the dealer drew a " +dealercard);
            if (dealercard == 11)
                c.println("And the dealer drew a Jack ");
            else if (dealercard == 12)
                c.println("And the dealer drew a Queen" );
            else if (dealercard == 13)
                c.println("And the dealer drew a King" );
            c.println("The dealer's total is: " +dealertotal);
        if(dealertotal>21)
            c.println("Dealer BUSTED.");
            c.println("Dealer's total was " +dealertotal+".");
        }//if statement
        while (true)
            if(dealertotal>playertotal && dealertotal<21 && playertotal<21)
                c.println("The Dealer Wins"); break;
            if(dealertotal<playertotal && dealertotal<21 && playertotal<21)
                c.println("You WIN"); break;
            if(dealertotal>21 && playertotal>21)
                c.println("You both bust."); break;
            if(dealertotal==21)
                c.println("Dealer got BLACKJACK."); break;
            if(playertotal==21)
                c.println("You got BLACKJACK.");break;
            if(playertotal==21 && dealertotal==21)
        while(true) //checks for blackjack.
            if(playertotal==21)
                c.println("You win. BLACKJACK"); break;
            }//if statement
            if(dealertotal==21)
                c.println("You lose. Dealer BLACKJACK.");break;
            else
                break;
            }//else loop
        }//while loop
}}}}

Similar Messages

  • How do I create a new game center id for my own games

    My kids have many games on my phone (4s) how do I create a new Game center id and load some of the same games as my own?

    You can change the account by tapping or clicking Account and then signing out of the current account and into the new one(Apple ID).

  • My two iPads share an Apple ID.  How can I create a separate Game Center account so they can play each other?

    My two iPads share an Apple ID.  How can I create a separate Game Center account so they can play each other?

    1. This is a year old post.  Things have changed, the answer is no longer accurate due to how the OS functions now.
    2.  You can't have a second Gamecenter account tied to the same Apple ID, because the Apple ID is the game center account.  They are not separate things.
    3. The OP said they had 2 iPads, which means they can use a different Apple ID for Gamecenter on the second iPad.
    4. You can still creare Apple ID's specifically for game center without changing them for the other services on the other devices.
    ronjack wrote:
    I have the same issue.  Young children who cannot get Apple ID's but we all want separate Gamecenter accounts.
    You need to get Apple ID's for them.  They aren't getting them, you are. You can manage these new ID{s yourself. You can even make sure they have no credit card and are not associated with any other service on the device. So essentially they are Apple ID's for GameCente only.

  • I create a mobile game. How to get the signing key?

    I create a mobile game. How to get the signing key? Is the certificate is payable? Sorry if the topic is in the wrong section.

    You need to be an iOS/Mac OS X developer.
    https://developer.apple.com/devcenter/

  • The ever so savvy "creating a java game" post

    Hey, I'm creating a java game, and I did research, and found that this question has been asked many, many times. But my question unfortunately did not match up with any of these posts :( So here goes...
    Im creating a java game, which will run as....kind of a mix between a 2d game, and 3d game (no i am not insane). I dont want the original zelda look, and i dont want the first person shooter look, I want my character to be viewed from an angle, like tibia - if anyone has ever played that. And I also want to leave open the door to changing the view within the game. I figured I can just get my graphics friends to draw things in 3-d, (draw a house [draw the 4 sides and the roof]), and then somehow skew these images to accomodate for a different view.
    I am more than willing to code some kind of graphics engine if what I need is not available, I have looked at a couple and found no such luck.
    So what is the most efficient way to create this game? By just sortof getting all the graphics to be from a certain percpective, and then somehow modifying them with java.....
    or by using some kind of graphics engine that allows me to change views? If so any recomendations?
    Thanks a lot - wow this was long, oh yea a couple Dukes for this too thanks again
    -Mark

    you don't need to do any skewing. Here's what I'd do. I'd store all the tile information in a matrix (Object[][]) with a custom tile class that has the information it needs to retrieve its appropriate image, and certain game related data like slow down factor when a person walks over a certain type of tile, and whether it can be collided with. I'd draw them based on however you decide to angle your tiles. But the important part is you go in this order:
    [0, 0], [0, 1], [1, 0], [0, 2], [1, 1], [2, 0], etc., etc....
    The idea is if you're turning the floor 45 degrees clockwise, to give the correct illusion of depth, you'll want to draw the furthest back tile first, and the furthest tile forward last. Whether you start on the left or right depends on what angle you decide to work with. At a 45 degree angle, it obviously doesn't matter whether you start on the left or right. But if you guess wrong with your rendering, it will show because tiles that are closer to the "camera" will be overlapped by tiles further from the "camera".
    for (int i = 0; i < tiles.length; i++) {
         for (int j = 0; j < tiles.length; j++) {
              graphics2D.drawImage(tiles[i].getImage(), i*horizontalSpacing - camera.getX(), j*verticalSpacing, camera.getY(), null);
    }horizontalSpacing and verticalSpacing will be determined by the angle of your tiles. Set those to match however you make your art.
    Drawing moving sprites will be a bit trickier because you'll have to decide which set of axes to follow... meaning, do you follow the axes of the screen, or the axes of your "rotated world." Give that some thought and once you understand what's happening with the perspective here you'll be able to see which is easiest.
    So there's your engine ;)
    Now, as for the art itself, make them in png format, so that you can have the base of your images be diamond shape, but of course tiles for players and walls and stuff will extend above that diamond. Just don't let them get below the base of their diamond otherwise the tile that gets drawn below them will cut them off. And you don't want a character's feet cut off by the "floor" as he runs ;)
    For your final question, don't let java skew the sprite. The only possible way to make it decent is if when you pick an angle, a 3D render takes your 3D world and it's 3D models and re-renders them at that angle; skewing is simply not capable of creating that illusion. The closest you could get is to simply squish the hight of your art to give the illusion that the camera is moving up, but since you can't expose things higher, like the top of your character's head (since the data doesn't exist in the "lower" version), it will be obviously funny looking.
    Hope that answers your questions, and good luck! I would definitely like to see what you come up with.

  • Creating a jeopardy game

    Hi,
    I'd like to create a Jeopardy game using the interaction widget but am encourntering a ton of problems.
    First off often the information I input is no longer there after I leave the window in whcih I wrote it. Second, when I put anything in French in doesn't save (is there a way around this).
    Third, can the categories be longer than a few caracters?
    I am working in Captivate 7.
    Thank you!

    Hi
    I've had a look at your zip files, and with the best will in the world what your asking for is way beyond what one individual here is willing to invest.
    First of all, this is AS2.0 on the Timeline, most Coders don't do this anymore. It's AS3.0 and Classes now.
    If your able to invest a little time and patient in learning AS3 the rewards are far greater.
    I'm sorry this might not be the answer you where looking for, but it's best you find out now than waiting indefinitely and getting no further with your project.
    Best Regards
    The Feldkircher

  • Creating a matching game.

    So I would like to create a matching game in captivate using advanced action.
    The goal is for the learner to on click;
    Reveal a card then reveal another card, if it does not match hide both.
    If they do match they stay revealed and their actions disable so that other cards do not affect them.
    The process is then repeated with the other cards until all are matched

    Hello and welcome to the forum,
    Is this what you want?
    http://blog.lilybiri.com/concentration-game-created-exclusively-with-c
    I created this with CP5.5, now it is a lot easier in 6/7 with groups and shapes. Look at this video:
    http://www.youtube.com/watch?v=Sy09xPoP69A
    And in 7, with the shared actions, even easier. No documentation written for that (yet)
    Lilybiri

  • Object Oriented Blackjack game for class final...

    I'm trying to accomplish my final & this is what I have so far. The teacher has given permission to use outside resources, so I'm hoping you can help.
    This is what I have so far.....any suggestions?
    Thank you
    //Play one hand of Blackjack
    import java.util.Random;//program uses class Random
    public class Blackjack
         private String dealer;//Dealer who does not play
         private int player1;//Player one of three
         private int player2;//Player two of three
         private int player3;//Player three of three
         Random randomNumbers = new Random();//Random number genertor
              //enumeration with constants that represent game status
              private enum Status{ HIT, STAND, WIN, LOST }
              public void Blackjack( String Alice, int Emily, int Matt, int Mary )
                   //initializing variables in declaration
                   Alice = dealer;
                   Emily = player1;
                   Matt = player2;
                   Mary = player3;
                   int nextCard;
                   int totalHand;
                   Status gameStatus;
                   int sumOfCards = dealCard();
                   int Blackjack = 21;
                   int hit;
              public int dealCard()//deal cards, calculate sum and display results
                   //Player1 is dealt 2 cards
                   int card1 = 1 + randomNumbers.nextInt( 10 );
                   int card2 = 1 + randomNumbers.nextInt( 10 );
                   int sum = card1 + card2;
                   System.out.printf( "Emily is dealt %d, %d\nHer hand is: %d\n",
                   card1, card2, sum );
                   //Player2 is dealt 2 cards
                   card1 = 1 + randomNumbers.nextInt( 10 );
                   card2 = 1 + randomNumbers.nextInt( 10 );
                   sum = card1 + card2;
                   System.out.printf( "Matt is dealt %d, %d\nHis hand is: %d\n",
                   card1, card2, sum );
                   //Player3 is dealt 2 cards
                   card1 = 1 + randomNumbers.nextInt( 10 );
                   card2 = 1 + randomNumbers.nextInt( 10 );
                   sum = card1 + card2;
                   System.out.printf( "Mary is dealt %d, %d\nHer hand is: %d\n",
                   card1, card2, sum );
                   return totalHand;//return sum of hand
                   //Report game status and maintain sum of hand
                   switch ( sum of cards )
                        //Dealer asks player if he/she wants another card
                        System.out.println( "Do you want a hit?" );
                   if ( gameStatus == Status.HIT )
                        nextCard = 1 + randomNumbers.nextInt( 10 );
                        totalHand = nextCard + sum;
                        System.out.printf("Emily's next card is %d\nEmily's hand is: %d\n",      
                        nextCard, totalHand );
    }

    The following is not a constructor:
    public void Blackjack( String Alice, int Emily, int Matt, int Mary )
       //initializing variables in declaration
      Alice = dealer;
      Emily = player1;
      Matt = player2;
      Mary = player3;
    }Remove the word "void" to make it a constructor
    public Blackjack( String Alice, int Emily, int Matt, int Mary )And, your code doesn't make sense. When you make that into a constructor and run the constructor, you will do something like this:
    Blackjack game = new Blackjack("Alice", 1, 2, 3);But, when you run the constructor, dealer is 'null' [default value of String variable]; and player1, player2, and player3 are 0 [default value of int variable]. Your constructor essentially says:
    Alice = null;
    Emily = 0;
    Matt = 0;
    Mary = 0;It sets the parameters to new values, but only locally within the constructor. The instance variables don't get new values at all. You need to reverse the assignments:
    dealer = Alice;
    player1 = Emily;
    ...It doesn't make a lot of sense to name your parameters to the constructor with specific persons' names. Not sure what your int values for players are for, anyway. You should have a Player class, as someone else suggested. It should have a name that can be set by the person running your program. Your game could start by saying:
    What is the name of Player 1?
    What is the name of Player 2?
    What is the name of Player 3?Then use the names to generate messages in the program.

  • Creating Flash Board Game (Multiplayer online)

    Hi,
    Right now i am doing on a project on Chinese Checkers which
    have 2 players, 3 players, 4 players, 6 players. I used SQL Server
    as database. game programmed in AS3, and i used web services to
    connect them. I used Timers to get data Consistently as Web
    services does not support data push like flash remoting. Due to
    budget issue, i have to use web service in my project for
    educational learning.
    I have created game lobby in flash, where user can chat, see
    whose online, and create or join game. One main question: Can i do
    all of them in frames without using external actionscript
    files?like coding in first frame.
    1st swf: Game Lobby --> press create button --> 2nd
    swf: Game Create Border -->3rd swf: Press 2 , 3 ,4 or 6 players
    button -> 4th swf: Game.

    an as2 swf will work when loaded by an as3 swf. the two can
    communicate using the localconnection class.

  • Creating a Pong game in AS3 using a tutorial

    Hi,
    I'm a beginner using AS3 and found a great tutorial on how to create a Pong game: http://www.foundation-flash.com/tutorials/pong4/. There's a link to the source code: http://www.foundation-flash.com/source/viewer.php?file=pong4.txt.
    When I add the source code to a new AS file (using Flash CS 5.5), save it as "Main.as", create a new Fla and link it in the actionscript settings to the Main.as and run it, I get errors:
    C:\Users\xxx\Desktop\P4\Main.as, Line 117
    1093: Syntax error.
    C:\Users\xxx\Desktop\P4\Main.as, Line 117
    1084: Syntax error: expecting rightparen before 270.
    C:\Users\xxx\Desktop\P4\Main.as, Line 121
    1093: Syntax error.
    C:\Users\xxx\Desktop\P4\Main.as, Line 121
    1084: Syntax error: expecting rightparen before 270.
    Here's the section of code being referred to in the error message:
    116 public function resetHandler(e:Event){
    117         if(ball.x < (0 – 270)){
                    scoreText2.text = String(Number(scoreText2.text ) + 1)
                    reset();
    121         if(ball.x > (550 – 270)){
                    scoreText1.text = String(Number(scoreText1.text ) + 1)
                    reset();
    I must be doing something wrong? Is there some way to get this code and Pong game sample running ?
    Any help would be appreciated.
    Regards,
    saratogacoach

    As Raymond said, its an issue with the 'dashes' in your if statements; they need to be minus signs, its just the wrong character.
    On a related note..why are you (the tutorial?) doing basic equations in a conditional statement? 0 – 270 and 550 – 270 are always going to be the same value...why compute it on every check?

  • HT4314 I have two iPad with one game centre account as the second iPad is my sons machine. I created a second game centre account but am not able to log into it as game centre only seems to let me put in an appleID, can someone suggest how I can get his s

    I have two iPads, one is my son's machine. Previously he had an IPad 1 and mine was an ipad2. The iPad 1 died so I bought myself a new ipad4. I have only one appleID for both machines but created two Game centre accounts as there is a couple of games we both play and have different high scores. ipad 4 is nicely set up with all of my game data but now I would like some help in reinstating My sons game centre account (previously on the ipad1) now on the iPad 2. When I try to log into game centre it only lets me out in my appleID which gives up my game center account. Thankyou.

    You and your husband can share a store account and still have seperate iCloud accounts for your contacts, bookmarks and stuff like that.  Click here for instructions to make an apple account without entering a credit card.  Make sure you use a different email address for each apple account. 
    Set up your iPhone/iPad whatever using the new account for iCloud.  Then go into settings/store and sign in with your purchasing account, you may need to sign out of the other account.  To the best of my knowledge, your household is allowed to share purchased legally, someone please correct me if I'm wrong.
    Once you each have your own devices set to your own accounts you can set them to backup to that account and it will keep all your contacts seperate.

  • How do you create a new Game center account for IOS 8.1?

    I really want to know how to create a Game center account on IOS 8.1. Can u please help me?

    You can change the account by tapping or clicking Account and then signing out of the current account and into the new one(Apple ID).

  • Need help creating text based game in Java

    Alright, I'm taking a big leap and I'm jumping a little out of league here. Anyways here are my two classes...I'm sure I've got plenty of errors :-/ One other thing. I have only programmed the battle section of the program so don't worry about the other 5 sections when fixing the code.
    import cs1.Keyboard;
    public class Knights
        public static void main (String[] args)
            // Object Declaration
            KnightsAccount player1 = new Account (1, 100, 200);
            // variable declarations
            boolean run = true;
            int choice;
            // Game Start
            System.out.println ("Welcome to Knights.");
            System.out.println ("--------------------------------------");
            System.out.println ("You are a level 1 character.  With 100 HP and 200 gold...good luck.");
            System.out.println ();
            while (run == true)
                System.out.println ();
                System.out.println ("Enter the number of the option you would like to do");
                System.out.println ();
                System.out.println ("1. Battle");
                System.out.println ("2. Train");
                System.out.println ("3. Work");
                System.out.println ("4. Rest");
                System.out.println ("5. Stats");
                System.out.println ("6. Quit");
                choice = Keyboard.readInt();
                if (choice == 1)
                    player1.battle();
                else if (choice == 2)
                    player1.train();
                else if (choice == 3)
                    player1.work();
                else if (choice == 4)
                    player1.rest();
                else if (choice == 5)
                    player1.stats();
                else
                    run = false;
    }And here is the second class...
    import java.util.Random;
    public class KnightsAccount
        public String winner;
        public int exp = 0;
        public void Account (int level, int hitPoints, int gold) {}
        public battle ()
            Random generator = new Random();
            int pumpkinHP = 80;
            int playerAttack, pumpkinAttack;
            System.out.println ("Engaged in combat with an Evil Pumpkin!");
            while (hitPoints > 0 && pumpkinHP > 0)
                if (pumpkinHP > 0)
                    playerAttack = generator.nextInt(15);
                    hitPoints -= playerAttack;
                    System.out.println ("Player 1 attacked Evil Pumpkin for " + playerAttack + ".");
                    System.out.println ("Evil Pumpkin has " + hitPoints + " HP left.");
                if (pumpkinHP <= 0)
                    pumpkinDead();
                if (hitPoints > 0 && !(pumpkinHP <= 0))
                    pumpkinAttack = generator.nextInt(12);
                    hitPoints -= pumpkinAttack;
                    System.out.println ("Evil Pumpkin attacked Player1 for " + pumpkinAttack + ".");
                    System.out.println ("Player 1 has " + pumpkinHP + " HP left.");
                if (hitPoints <= 0)
                    playerDead();
            return winner;
        private pumpkinDead ()
            System.out.println ("Success!  You have defeated the Evil Pumpkin with " + hitPoints + "HP left!");
            System.out.println ("For you good deed you earned 20 exp.");
            exp += 20;
            return exp;
        private void playersDead ()
            System.out.println ("You have been defeated.  Go home before we pelt melty cheeze at you.");
    }Whoever can help me I'd be grateful. I know there are probably a lot of things wrong here. Also if some of you could post your AIM or MSN so that I can get some one on one help on any of the smaller problems I run acrost that would help a lot too.
    Duke dollars to whoever helps me ;)
    AIM: Trebor DoD
    MSN: [email protected]

    You should really create a GameCharacter object that contains the
    statistics for a character (player or non-player) in the game.
    public class GameCharacter {
       private double attackStrength;
       private double defenseStrength;
       private String name;
       private String[] bodyParts;
       private Random = new Random();
    public GameCharacter(String name, String[] bodyParts, double attackSt, double defenseSt){
       this.attackStrength = attackSt;
       this.defenseStrength = defenseSt;
       this.bodyParts = bodyParts;
       this.name = name;
    // put lots of methods in here to get and set the information
    public String getName(){
      return this.name;
    public String getRandomBodyPart(){
       return this.bodyParts[random.nextInt(this.bodyParts.length)];
    }You then create your "knight" character and your "rabid pumpkin"
    character.
    Your fight method then just takes two GameCharacter objects and uses
    the information they contain to fight the battle.
    public void fight(GameCharacter a, GameCharacter b) {
       boolean fightOver = false;
       Random rn = new Random();
       double attackValue;
       while(!fightOver) {
           attackValue = a.getAttackStrength()*rn.nextDouble();
           System.out.println(a.getName()+" attacks "+b.getName()+"'s "+b.getRandomBodyPart()+" for "+attackValue+" points");
    }The above is not the fighting loop of course. I just put it in to
    demostrate how the fight method can be made generic. It takes any
    two characters and uses their defensive and attack information to
    calculate the fight outcome. It also uses the descriptions that the characters have
    to make the fight more interesting. (the getRandomBodyPart method in
    particular)
    matfud

  • Help with Creating a Jeopardy Game for Classroom Teacher

    Hi,
    I am a middle school teacher and would like to create a Flash Jeopardy game for the teachers at our school to use on our school website.  I would like a game similar to the game on http://www.superteachertools.com/jeopardy/.
    I have been able to successfully create a flash jeopardy game that uses a xml file.  My problem is that I have to have a swf file and an xml file for every game we create.  I want to be able to have one swf file that will load many different Jeopardy games. 
    I am using Flash CS3, Dreamweaver CS3, and MySQL.  The files I have created are here:  http://www.marylynnewilliams.com/MaryLynneWilliams/test/DownloadZIP/JeopardyGames.php
    There is also a zip file:  http://www.marylynnewilliams.com/MaryLynneWilliams/test/DownloadZIP/Jeopardy.zip
    If anyone has time to help me with this it would be greatly appreciated.
    Thank you,
    Mary Lynne

    Hi
    I've had a look at your zip files, and with the best will in the world what your asking for is way beyond what one individual here is willing to invest.
    First of all, this is AS2.0 on the Timeline, most Coders don't do this anymore. It's AS3.0 and Classes now.
    If your able to invest a little time and patient in learning AS3 the rewards are far greater.
    I'm sorry this might not be the answer you where looking for, but it's best you find out now than waiting indefinitely and getting no further with your project.
    Best Regards
    The Feldkircher

  • Can I create an iOS game using C++?

    I want to create games for iOS using C++ and Maya? Please help me. Tell me what I need to know. Thanks!

    I do not have Flash CS6 (too many bug reports) but I use it perfectly fine in CS5.5.
    What your error means is basically the libraries are not the latest and what it's trying to export to is a lower version than is supported. It runs on Desktop because you've updated your desktops AIR to 3.2 and have flash player 11.0 or better. For AIR for iOS, you need to make absolutely sure it is packaging with AIR 3.2 or higher. Flash CS6 might be targeting something below AIR 3.2.
    Here are instructions for overlaying the latest version of AIR on Flash. This should give you an idea of what to check in your version of Flash. Go through the list item by item and check the files in the locations that are mentioned and make sure the versions are at least the same.
    http://helpx.adobe.com/x-productkb/multi/overlay-air-sdk-flash-professional.html
    If you jump ahead to step 4 you should be seeing in those files a version="15". You should also see in step 6 that the namespace AIR is pointing to is at least 3.2. If either are lower you may need to update your version of AIR, and there are the instructions to do so. Although the AIR folder will probably not be named AIR2.6 of course. But the instructions should be similar.

Maybe you are looking for