Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: JAVA game black jack need help on finding an error!!

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JAVA game black jack need help on finding an error!!

    // The "BlackJack" class.
    import java.awt.*;
    import hsa.Console;

    public class BlackJack
    {
    static Console c; // The output console

    public static int GetSuite ()
    {
    int y;
    y = (int) ((Math.random () * 4) + 1) * 15;
    return y;
    }


    public static int GetNumber ()
    {
    int x;
    x = (int) ((Math.random () * 13) + 1);
    return x;
    }


    public static void DrawClubs (int x, int y)
    {
    int trianglex[] = {x + 2, x + 6, x + 10};
    int triangley[] = {y + 16, y + 10, y + 16};
    c.setColor (Color.black);
    c.fillOval (x + 0, y + 5, 8, 8);
    c.fillOval (x + 5, y + 5, 8, 8);
    c.fillOval (x + 2, y, 8, 8);
    c.fillPolygon (trianglex, triangley, 3);
    }


    public static void DrawSpades (int x, int y)
    {
    int trianglex[] = {x + 2, x + 6, x + 10};
    int triangley[] = {y + 16, y + 10, y + 16};
    int diamondx[] = {x, x + 6, x + 12};
    int diamondy[] = {y + 6, y, y + 6};
    c.setColor (Color.black);
    c.fillOval (x + 0, y + 5, 8, 8);
    c.fillOval (x + 5, y + 5, 8, 8);
    c.fillPolygon (trianglex, triangley, 3);
    c.fillPolygon (diamondx, diamondy, 3);
    }


    public static void DrawHearts (int x, int y)
    {
    int diamondx[] = {x + 7, x + 2, x + 7, x + 12};
    int diamondy[] = {y + 4, y + 9, y + 14, y + 9};
    c.setColor (Color.red);
    c.fillOval (x + 0, y + 0, 10, 10);
    c.fillOval (x + 5, y + 0, 10, 10);
    c.fillPolygon (diamondx, diamondy, 4);
    }


    public static void DrawDiamonds (int x, int y)
    {
    int diamondx[] = {x + 7, x, x + 7, x + 15};
    int diamondy[] = {y, y + 7, y + 15, y + 7};
    c.setColor (Color.red);

    c.fillPolygon (diamondx, diamondy, 4);
    }


    public static void DrawCard (int NumOfCards, int Suite, int Num)
    {
    int x, y = 60;

    x = (NumOfCards * 155);

    c.setColor (new Color (130, 90, 30));
    c.drawRoundRect (x, 25, 140, 190, 10, 10);

    if (Suite == 15)
    DrawSpades (x + 70, y);

    else if (Suite == 30)
    DrawHearts (x + 70, y);

    else if (Suite == 45)
    DrawClubs (x + 70, y);

    else if (Suite == 60)
    DrawDiamonds (x + 70, y);

    c.setFont (new Font ("VERDANA", Font.BOLD, 100));

    if (Num == 10)
    c.drawString (" " + Num, (x - 35), 200);

    else if (Num == 1)
    c.drawString ("A", (x + 35), 200);

    else if (Num == 13)
    c.drawString ("K", (x + 35), 200);

    else if (Num == 12)
    c.drawString ("Q", (x + 30), 180);

    else if (Num == 11)
    c.drawString ("J", (x + 45), 200);

    else
    c.drawString (" " + Num, (x + 7), 200);
    }


    public static void DrawCard_Ash (int NumOfCards_Ash, int Suite, int Num)
    {
    int x, y = 285;
    x = (NumOfCards_Ash * 155);

    c.setColor (new Color (130, 90, 30));
    c.drawRoundRect (x, 265, 140, 190, 10, 10);

    if (Suite == 15)
    DrawSpades (x + 70, y);

    else if (Suite == 30)
    DrawHearts (x + 70, y);

    else if (Suite == 45)
    DrawClubs (x + 70, y);

    else if (Suite == 60)
    DrawDiamonds (x + 70, y);

    c.setFont (new Font ("VERDANA", Font.BOLD, 100));

    if (Num == 10)
    c.drawString (" " + Num, (x - 35), 440);

    else if (Num == 1)
    c.drawString ("A", (x + 35), 440);

    else if (Num == 13)
    c.drawString ("K", (x + 35), 440);

    else if (Num == 12)
    c.drawString ("Q", (x + 30), 420);

    else if (Num == 11)
    c.drawString ("J", (x + 45), 440);

    else
    c.drawString (" " + Num, (x + 7), 440);

    }


    public static int GetCard (int NumOfCards)
    {
    int[] PreviousCard = new int [100];
    int Num, Suite, NewCard, Card = 0, i = 0;

    do
    {
    Num = GetNumber ();
    Suite = GetSuite ();

    NewCard = Num + Suite;
    }
    while (NewCard == PreviousCard [i]);

    PreviousCard [i] = NewCard;
    i++;

    DrawCard (NumOfCards, Suite, Num);

    if (Num > 10)
    Card = 11;

    else
    Card = Num;

    return Card;
    }


    public static int GetAsh_Card (int NumOfCards_Ash)
    {
    int[] PreviousCard = new int [100];
    int Num, Suite, NewCard, Ash_Card = 0, i = 0;

    do
    {
    Num = GetNumber ();
    Suite = GetSuite ();

    NewCard = Num + Suite;
    }
    while (NewCard == PreviousCard [i]);

    DrawCard_Ash (NumOfCards_Ash, Suite, Num);

    PreviousCard [i] = NewCard;
    i++;

    if (Num > 10)
    Ash_Card = 11;

    else
    Ash_Card = Num;

    return Ash_Card;

    }


    public static void cleartop ()
    {
    c.setColor (Color.black);
    c.fillRect (0, 480, 1000, 60);
    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);
    }


    public static void clearbottom ()
    {
    c.setColor (Color.black);
    c.fillRect (0, 540, 1000, 60);
    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);

    }


    public static void drawbar (int money, int CardValue, int amount)
    {
    c.setColor (Color.blue);
    c.fillRect (0, 600, 1000, 100);
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 30));
    c.setColor (Color.white);

    c.drawString ("Your Money: $" + money, 5, 635);
    c.drawString ("Bet Amount: $" + amount, 300, 635);
    c.drawString ("Player's value of cards:" + CardValue, 600, 635);

    }


    public static int Loss (int money, int amount)
    {
    money = money - amount;

    return money;

    }


    public static int Win (int money, int amount)
    {
    money = money + amount;

    return money;

    }


    public static int Bet (int money)
    {
    int amount = 0;

    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 510);
    c.setCursor (26, 92);
    amount = c.readInt ();
    cleartop ();

    while (amount > money || amount < 0)
    {
    if (amount > money)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nYou gotta earn it before you can bet it!", 5, 510);

    }

    if (amount < 0)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nThere is no such thing as negative money bro!", 5, 510);
    }

    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 570);
    c.setCursor (29, 92);
    amount = c.readInt ();
    clearbottom ();
    }
    cleartop ();
    clearbottom ();

    return amount;
    }


    public static void main (String[] args)
    {
    c = new Console (34, 120);
    String name;
    char NewGame;

    do
    {
    int money = 1000;
    char NewHand;

    c.clear ();
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setFont (new Font ("VERDANA", Font.BOLD, 50));
    c.setColor (Color.green);
    c.drawString ("Welcome to BlackJack!", 150, 200);
    c.drawString ("Please enter your name: ", 150, 350);
    c.setCursor (22, 42);
    name = c.readString ();

    do
    {
    c.clear ();
    int Card = 0, Ash_Card = 0, CardValue = 0, Ash_CardValue = 0, amount = 0, NumOfCards, NumOfCards_Ash;
    char Hit = 'N', Bet;
    boolean win = false, loss = false;

    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 30));
    c.setColor (Color.blue);

    c.drawString (" " + name, 400, 20);

    c.drawString ("ASH", 390, 245);

    c.setColor (Color.black);
    c.fillRect (0, 480, 1000, 120);


    drawbar (money, CardValue, amount);


    cleartop ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 510);
    Bet = c.getChar ();

    while (Bet != 'y' && Bet != 'n' && Bet != 'Y' && Bet != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    clearbottom ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 570);
    Bet = c.getChar ();
    clearbottom ();
    }


    drawbar (money, CardValue, amount);

    cleartop ();

    if (Bet == 'Y' || Bet == 'y')
    amount = Bet (money);

    for (NumOfCards = 0 ; NumOfCards < 2 ; NumOfCards++)
    {
    Card = GetCard (NumOfCards);
    CardValue = CardValue + Card;
    }

    c.setColor (new Color (130, 90, 30));
    c.fillRoundRect (5, 265, 140, 190, 10, 10);
    c.fillRoundRect (155, 265, 140, 190, 10, 10);
    c.setColor (Color.black);
    c.fillRoundRect (165, 275, 120, 170, 10, 10);
    c.fillRoundRect (15, 275, 120, 170, 10, 10);
    c.setFont (new Font ("ALGERIAN", Font.PLAIN, 15));
    c.setColor (Color.blue);
    c.drawString ("BLACKJACK", 30, 360);
    c.drawString ("BLACKJACK", 180, 360);


    do
    {
    drawbar (money, CardValue, amount);

    if (CardValue == 21)
    {

    cleartop ();
    c.drawString ("\nBlackJack, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (CardValue >= 22)
    {
    cleartop ();
    c.drawString ("\nOoops, you busted. Ash Wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nWould you like to take a hit? (y/n)", 5, 510);
    Hit = c.getChar ();

    if (Hit == 'y' || Hit == 'Y')
    {
    Card = GetCard (NumOfCards);
    NumOfCards++;
    CardValue = CardValue + Card;
    }
    }
    }
    while ((Hit == 'y' || Hit == 'Y') && (!win && !loss));

    c.setColor (Color.white);
    c.fillRect (0, 265, 295, 220);
    cleartop ();

    for (NumOfCards_Ash = 0 ; NumOfCards_Ash < 2 ; NumOfCards_Ash++)
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    Ash_CardValue = Ash_CardValue + Ash_Card;
    }

    if ((Ash_CardValue == 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBlackJack for Ash, he wins", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if ((Ash_CardValue > 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (Ash_CardValue <= CardValue && (!loss && !win))
    {
    while (Ash_CardValue <= 16 && (!loss && !win))
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    NumOfCards_Ash++;
    Ash_CardValue = Ash_CardValue + Ash_Card;

    if (Ash_CardValue > 21)
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    }

    if (!loss && !win)
    {
    if (Ash_CardValue > CardValue)
    {
    cleartop ();
    c.drawString ("\nAsh has higher numbers than you, Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if (Ash_CardValue == CardValue)
    {
    if (NumOfCards_Ash > NumOfCards)
    {
    cleartop ();
    c.setFont (new Font ("VERDANA", Font.BOLD, 20));
    c.drawString ("\nYou guys have the same numbers but Ash has more cards, so Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou guys have the same numbers but " + name + " has more cards, so " + name + " wins!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou have higher numbers than Ash, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    drawbar (money, CardValue, amount);

    do
    {
    clearbottom ();
    c.drawString ("\nWould you like to play a new hand?(y/n)", 5, 570);
    NewHand = c.getChar ();
    if (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    }
    }
    while (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N');
    }
    while (money > 0 && (NewHand == 'y' || NewHand == 'Y'));

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 45));
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.green);
    if (NewHand == 'y' || NewHand == 'Y')
    c.drawString ("You are Bankcrupt!", 20, 100);

    c.drawString ("\nYour total money: $" + money, 20, 200);
    c.drawString ("\nYour net Profit: $" + (money - 1000), 20, 300);

    do
    {
    c.drawString ("\nWould you like to restart the whole game?(y/n)", 20, 500);
    NewGame = c.getChar ();

    if (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N')
    c.drawString ("\nInvalid input, please enter y or n", 20, 600);
    }
    while (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N');

    }


    while (NewGame == 'y' || NewGame == 'Y')
    ;

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 50));
    c.setColor (Color.white);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.blue);
    c.drawString ("\n\nThank you for playing BlackJack!", 100, 100);
    c.drawString ("Developed by Ashraf Abedin.", 120, 200);
    c.drawString ("Hope you had fun!", 220, 300);

    } // main method
    } // BlackJack class


  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Black Jack Game help on finding the error

    [#code=java[/#]


    }


    public static int Loss (int money, int amount)
    {
    money = money - amount;

    return money;

    }


    public static int Win (int money, int amount)
    {
    money = money + amount;

    return money;

    }


    public static int Bet (int money)
    {
    int amount = 0;

    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 510);
    c.setCursor (26, 92);
    amount = c.readInt ();
    cleartop ();

    while (amount > money || amount < 0)
    {
    if (amount > money)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nYou gotta earn it before you can bet it!", 5, 510);

    }

    if (amount < 0)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nThere is no such thing as negative money bro!", 5, 510);
    }

    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 570);
    c.setCursor (29, 92);
    amount = c.readInt ();
    clearbottom ();
    }
    cleartop ();
    clearbottom ();

    return amount;
    }


    public static void main (String[] args)
    {
    c = new Console (34, 120);
    String name;
    char NewGame;

    do
    {
    int money = 1000;
    char NewHand;

    c.clear ();
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setFont (new Font ("VERDANA", Font.BOLD, 50));
    c.setColor (Color.green);
    c.drawString ("Welcome to BlackJack!", 150, 200);
    c.drawString ("Please enter your name: ", 150, 350);
    c.setCursor (22, 42);
    name = c.readString ();

    do
    {
    c.clear ();
    int Card = 0, Ash_Card = 0, CardValue = 0, Ash_CardValue = 0, amount = 0, NumOfCards, NumOfCards_Ash;
    char Hit = 'N', Bet;
    boolean win = false, loss = false;

    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 30));
    c.setColor (Color.blue);

    c.drawString (" " + name, 400, 20);

    c.drawString ("ASH", 390, 245);

    c.setColor (Color.black);
    c.fillRect (0, 480, 1000, 120);


    drawbar (money, CardValue, amount);


    cleartop ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 510);
    Bet = c.getChar ();

    while (Bet != 'y' && Bet != 'n' && Bet != 'Y' && Bet != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    clearbottom ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 570);
    Bet = c.getChar ();
    clearbottom ();
    }


    drawbar (money, CardValue, amount);

    cleartop ();

    if (Bet == 'Y' || Bet == 'y')
    amount = Bet (money);

    for (NumOfCards = 0 ; NumOfCards < 2 ; NumOfCards++)
    {
    Card = GetCard (NumOfCards);
    CardValue = CardValue + Card;
    }

    c.setColor (new Color (130, 90, 30));
    c.fillRoundRect (5, 265, 140, 190, 10, 10);
    c.fillRoundRect (155, 265, 140, 190, 10, 10);
    c.setColor (Color.black);
    c.fillRoundRect (165, 275, 120, 170, 10, 10);
    c.fillRoundRect (15, 275, 120, 170, 10, 10);
    c.setFont (new Font ("ALGERIAN", Font.PLAIN, 15));
    c.setColor (Color.blue);
    c.drawString ("BLACKJACK", 30, 360);
    c.drawString ("BLACKJACK", 180, 360);


    do
    {
    drawbar (money, CardValue, amount);

    if (CardValue == 21)
    {

    cleartop ();
    c.drawString ("\nBlackJack, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (CardValue >= 22)
    {
    cleartop ();
    c.drawString ("\nOoops, you busted. Ash Wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nWould you like to take a hit? (y/n)", 5, 510);
    Hit = c.getChar ();

    if (Hit == 'y' || Hit == 'Y')
    {
    Card = GetCard (NumOfCards);
    NumOfCards++;
    CardValue = CardValue + Card;
    }
    }
    }
    while ((Hit == 'y' || Hit == 'Y') && (!win && !loss));

    c.setColor (Color.white);
    c.fillRect (0, 265, 295, 220);
    cleartop ();

    for (NumOfCards_Ash = 0 ; NumOfCards_Ash < 2 ; NumOfCards_Ash++)
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    Ash_CardValue = Ash_CardValue + Ash_Card;
    }

    if ((Ash_CardValue == 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBlackJack for Ash, he wins", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if ((Ash_CardValue > 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (Ash_CardValue <= CardValue && (!loss && !win))
    {
    while (Ash_CardValue <= 16 && (!loss && !win))
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    NumOfCards_Ash++;
    Ash_CardValue = Ash_CardValue + Ash_Card;

    if (Ash_CardValue > 21)
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    }

    if (!loss && !win)
    {
    if (Ash_CardValue > CardValue)
    {
    cleartop ();
    c.drawString ("\nAsh has higher numbers than you, Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if (Ash_CardValue == CardValue)
    {
    if (NumOfCards_Ash > NumOfCards)
    {
    cleartop ();
    c.setFont (new Font ("VERDANA", Font.BOLD, 20));
    c.drawString ("\nYou guys have the same numbers but Ash has more cards, so Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou guys have the same numbers but " + name + " has more cards, so " + name + " wins!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou have higher numbers than Ash, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    drawbar (money, CardValue, amount);

    do
    {
    clearbottom ();
    c.drawString ("\nWould you like to play a new hand?(y/n)", 5, 570);
    NewHand = c.getChar ();
    if (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    }
    }
    while (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N');
    }
    while (money > 0 && (NewHand == 'y' || NewHand == 'Y'));

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 45));
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.green);
    if (NewHand == 'y' || NewHand == 'Y')
    c.drawString ("You are Bankcrupt!", 20, 100);

    c.drawString ("\nYour total money: $" + money, 20, 200);
    c.drawString ("\nYour net Profit: $" + (money - 1000), 20, 300);

    do
    {
    c.drawString ("\nWould you like to restart the whole game?(y/n)", 20, 500);
    NewGame = c.getChar ();

    if (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N')
    c.drawString ("\nInvalid input, please enter y or n", 20, 600);
    }
    while (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N');

    }


    while (NewGame == 'y' || NewGame == 'Y')
    ;

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 50));
    c.setColor (Color.white);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.blue);
    c.drawString ("\n\nThank you for playing BlackJack!", 100, 100);
    c.drawString ("Developed by Ashraf Abedin.", 120, 200);
    c.drawString ("Hope you had fun!", 220, 300);

    } // main method
    } // BlackJack class&do=process' style='color:#00B2EE;'>#// The "BlackJack" class.
    import java.awt.*;
    import hsa.Console;

    public class BlackJack
    {
    static Console c; // The output console

    public static int GetSuite ()
    {
    int y;
    y = (int) ((Math.random () * 4) + 1) * 15;
    return y;
    }


    public static int GetNumber ()
    {
    int x;
    x = (int) ((Math.random () * 13) + 1);
    return x;
    }


    public static void DrawClubs (int x, int y)
    {
    int trianglex[] = {x + 2, x + 6, x + 10};
    int triangley[] = {y + 16, y + 10, y + 16};
    c.setColor (Color.black);
    c.fillOval (x + 0, y + 5, 8, 8);
    c.fillOval (x + 5, y + 5, 8, 8);
    c.fillOval (x + 2, y, 8, 8);
    c.fillPolygon (trianglex, triangley, 3);
    }


    public static void DrawSpades (int x, int y)
    {
    int trianglex[] = {x + 2, x + 6, x + 10};
    int triangley[] = {y + 16, y + 10, y + 16};
    int diamondx[] = {x, x + 6, x + 12};
    int diamondy[] = {y + 6, y, y + 6};
    c.setColor (Color.black);
    c.fillOval (x + 0, y + 5, 8, 8);
    c.fillOval (x + 5, y + 5, 8, 8);
    c.fillPolygon (trianglex, triangley, 3);
    c.fillPolygon (diamondx, diamondy, 3);
    }


    public static void DrawHearts (int x, int y)
    {
    int diamondx[] = {x + 7, x + 2, x + 7, x + 12};
    int diamondy[] = {y + 4, y + 9, y + 14, y + 9};
    c.setColor (Color.red);
    c.fillOval (x + 0, y + 0, 10, 10);
    c.fillOval (x + 5, y + 0, 10, 10);
    c.fillPolygon (diamondx, diamondy, 4);
    }


    public static void DrawDiamonds (int x, int y)
    {
    int diamondx[] = {x + 7, x, x + 7, x + 15};
    int diamondy[] = {y, y + 7, y + 15, y + 7};
    c.setColor (Color.red);

    c.fillPolygon (diamondx, diamondy, 4);
    }


    public static void DrawCard (int NumOfCards, int Suite, int Num)
    {
    int x, y = 60;

    x = (NumOfCards * 155);

    c.setColor (new Color (130, 90, 30));
    c.drawRoundRect (x, 25, 140, 190, 10, 10);

    if (Suite == 15)
    DrawSpades (x + 70, y);

    else if (Suite == 30)
    DrawHearts (x + 70, y);

    else if (Suite == 45)
    DrawClubs (x + 70, y);

    else if (Suite == 60)
    DrawDiamonds (x + 70, y);

    c.setFont (new Font ("VERDANA", Font.BOLD, 100));

    if (Num == 10)
    c.drawString (" " + Num, (x - 35), 200);

    else if (Num == 1)
    c.drawString ("A", (x + 35), 200);

    else if (Num == 13)
    c.drawString ("K", (x + 35), 200);

    else if (Num == 12)
    c.drawString ("Q", (x + 30), 180);

    else if (Num == 11)
    c.drawString ("J", (x + 45), 200);

    else
    c.drawString (" " + Num, (x + 7), 200);
    }


    public static void DrawCard_Ash (int NumOfCards_Ash, int Suite, int Num)
    {
    int x, y = 285;
    x = (NumOfCards_Ash * 155);

    c.setColor (new Color (130, 90, 30));
    c.drawRoundRect (x, 265, 140, 190, 10, 10);

    if (Suite == 15)
    DrawSpades (x + 70, y);

    else if (Suite == 30)
    DrawHearts (x + 70, y);

    else if (Suite == 45)
    DrawClubs (x + 70, y);

    else if (Suite == 60)
    DrawDiamonds (x + 70, y);

    c.setFont (new Font ("VERDANA", Font.BOLD, 100));

    if (Num == 10)
    c.drawString (" " + Num, (x - 35), 440);

    else if (Num == 1)
    c.drawString ("A", (x + 35), 440);

    else if (Num == 13)
    c.drawString ("K", (x + 35), 440);

    else if (Num == 12)
    c.drawString ("Q", (x + 30), 420);

    else if (Num == 11)
    c.drawString ("J", (x + 45), 440);

    else
    c.drawString (" " + Num, (x + 7), 440);

    }


    public static int GetCard (int NumOfCards)
    {
    int[] PreviousCard = new int [100];
    int Num, Suite, NewCard, Card = 0, i = 0;

    do
    {
    Num = GetNumber ();
    Suite = GetSuite ();

    NewCard = Num + Suite;
    }
    while (NewCard == PreviousCard [i]);

    PreviousCard [i] = NewCard;
    i++;

    DrawCard (NumOfCards, Suite, Num);

    if (Num > 10)
    Card = 11;

    else
    Card = Num;

    return Card;
    }


    public static int GetAsh_Card (int NumOfCards_Ash)
    {
    int[] PreviousCard = new int [100];
    int Num, Suite, NewCard, Ash_Card = 0, i = 0;

    do
    {
    Num = GetNumber ();
    Suite = GetSuite ();

    NewCard = Num + Suite;
    }
    while (NewCard == PreviousCard [i]);

    DrawCard_Ash (NumOfCards_Ash, Suite, Num);

    PreviousCard [i] = NewCard;
    i++;

    if (Num > 10)
    Ash_Card = 11;

    else
    Ash_Card = Num;

    return Ash_Card;

    }


    public static void cleartop ()
    {
    c.setColor (Color.black);
    c.fillRect (0, 480, 1000, 60);
    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);
    }


    public static void clearbottom ()
    {
    c.setColor (Color.black);
    c.fillRect (0, 540, 1000, 60);
    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);

    }


    public static void drawbar (int money, int CardValue, int amount)
    {
    c.setColor (Color.blue);
    c.fillRect (0, 600, 1000, 100);
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 30));
    c.setColor (Color.white);

    c.drawString ("Your Money: $" + money, 5, 635);
    c.drawString ("Bet Amount: $" + amount, 300, 635);
    c.drawString ("Player's value of cards:" + CardValue, 600, 635);

    }


    public static int Loss (int money, int amount)
    {
    money = money - amount;

    return money;

    }


    public static int Win (int money, int amount)
    {
    money = money + amount;

    return money;

    }


    public static int Bet (int money)
    {
    int amount = 0;

    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 510);
    c.setCursor (26, 92);
    amount = c.readInt ();
    cleartop ();

    while (amount > money || amount < 0)
    {
    if (amount > money)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nYou gotta earn it before you can bet it!", 5, 510);

    }

    if (amount < 0)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nThere is no such thing as negative money bro!", 5, 510);
    }

    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 570);
    c.setCursor (29, 92);
    amount = c.readInt ();
    clearbottom ();
    }
    cleartop ();
    clearbottom ();

    return amount;
    }


    public static void main (String[] args)
    {
    c = new Console (34, 120);
    String name;
    char NewGame;

    do
    {
    int money = 1000;
    char NewHand;

    c.clear ();
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setFont (new Font ("VERDANA", Font.BOLD, 50));
    c.setColor (Color.green);
    c.drawString ("Welcome to BlackJack!", 150, 200);
    c.drawString ("Please enter your name: ", 150, 350);
    c.setCursor (22, 42);
    name = c.readString ();

    do
    {
    c.clear ();
    int Card = 0, Ash_Card = 0, CardValue = 0, Ash_CardValue = 0, amount = 0, NumOfCards, NumOfCards_Ash;
    char Hit = 'N', Bet;
    boolean win = false, loss = false;

    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 30));
    c.setColor (Color.blue);

    c.drawString (" " + name, 400, 20);

    c.drawString ("ASH", 390, 245);

    c.setColor (Color.black);
    c.fillRect (0, 480, 1000, 120);


    drawbar (money, CardValue, amount);


    cleartop ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 510);
    Bet = c.getChar ();

    while (Bet != 'y' && Bet != 'n' && Bet != 'Y' && Bet != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    clearbottom ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 570);
    Bet = c.getChar ();
    clearbottom ();
    }


    drawbar (money, CardValue, amount);

    cleartop ();

    if (Bet == 'Y' || Bet == 'y')
    amount = Bet (money);

    for (NumOfCards = 0 ; NumOfCards < 2 ; NumOfCards++)
    {
    Card = GetCard (NumOfCards);
    CardValue = CardValue + Card;
    }

    c.setColor (new Color (130, 90, 30));
    c.fillRoundRect (5, 265, 140, 190, 10, 10);
    c.fillRoundRect (155, 265, 140, 190, 10, 10);
    c.setColor (Color.black);
    c.fillRoundRect (165, 275, 120, 170, 10, 10);
    c.fillRoundRect (15, 275, 120, 170, 10, 10);
    c.setFont (new Font ("ALGERIAN", Font.PLAIN, 15));
    c.setColor (Color.blue);
    c.drawString ("BLACKJACK", 30, 360);
    c.drawString ("BLACKJACK", 180, 360);


    do
    {
    drawbar (money, CardValue, amount);

    if (CardValue == 21)
    {

    cleartop ();
    c.drawString ("\nBlackJack, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (CardValue >= 22)
    {
    cleartop ();
    c.drawString ("\nOoops, you busted. Ash Wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nWould you like to take a hit? (y/n)", 5, 510);
    Hit = c.getChar ();

    if (Hit == 'y' || Hit == 'Y')
    {
    Card = GetCard (NumOfCards);
    NumOfCards++;
    CardValue = CardValue + Card;
    }
    }
    }
    while ((Hit == 'y' || Hit == 'Y') && (!win && !loss));

    c.setColor (Color.white);
    c.fillRect (0, 265, 295, 220);
    cleartop ();

    for (NumOfCards_Ash = 0 ; NumOfCards_Ash < 2 ; NumOfCards_Ash++)
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    Ash_CardValue = Ash_CardValue + Ash_Card;
    }

    if ((Ash_CardValue == 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBlackJack for Ash, he wins", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if ((Ash_CardValue > 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (Ash_CardValue <= CardValue && (!loss && !win))
    {
    while (Ash_CardValue <= 16 && (!loss && !win))
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    NumOfCards_Ash++;
    Ash_CardValue = Ash_CardValue + Ash_Card;

    if (Ash_CardValue > 21)
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    }

    if (!loss && !win)
    {
    if (Ash_CardValue > CardValue)
    {
    cleartop ();
    c.drawString ("\nAsh has higher numbers than you, Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if (Ash_CardValue == CardValue)
    {
    if (NumOfCards_Ash > NumOfCards)
    {
    cleartop ();
    c.setFont (new Font ("VERDANA", Font.BOLD, 20));
    c.drawString ("\nYou guys have the same numbers but Ash has more cards, so Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou guys have the same numbers but " + name + " has more cards, so " + name + " wins!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou have higher numbers than Ash, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    drawbar (money, CardValue, amount);

    do
    {
    clearbottom ();
    c.drawString ("\nWould you like to play a new hand?(y/n)", 5, 570);
    NewHand = c.getChar ();
    if (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    }
    }
    while (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N');
    }
    while (money > 0 && (NewHand == 'y' || NewHand == 'Y'));

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 45));
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.green);
    if (NewHand == 'y' || NewHand == 'Y')
    c.drawString ("You are Bankcrupt!", 20, 100);

    c.drawString ("\nYour total money: $" + money, 20, 200);
    c.drawString ("\nYour net Profit: $" + (money - 1000), 20, 300);

    do
    {
    c.drawString ("\nWould you like to restart the whole game?(y/n)", 20, 500);
    NewGame = c.getChar ();

    if (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N')
    c.drawString ("\nInvalid input, please enter y or n", 20, 600);
    }
    while (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N');

    }


    while (NewGame == 'y' || NewGame == 'Y')
    ;

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 50));
    c.setColor (Color.white);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.blue);
    c.drawString ("\n\nThank you for playing BlackJack!", 100, 100);
    c.drawString ("Developed by Ashraf Abedin.", 120, 200);
    c.drawString ("Hope you had fun!", 220, 300);

    } // main method
    } // BlackJack class
    Last edited by Clyde90; June 13th, 2012 at 07:27 AM.

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    161
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: Black Jack Game help on finding the error

    What is the "error" you are having?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Black Jack Game help on finding the error

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Black Jack Game help on finding the error

    how do you do that?

  6. #6
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Black Jack Game help on finding the error

    please anyone help

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Black Jack Game help on finding the error

    Does your post have an Edit Post button below it? Press that.
    Then put the code tags before and after the code.

    Press the Go Advanced button below the input box, select the code and press the #button. It should look like this:
        int x = 0;
    Last edited by Norm; June 13th, 2012 at 07:03 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Black Jack Game help on finding the error

    got it then so my errors are the highlighted one?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Black Jack Game help on finding the error

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting. Unformatted code is very hard to read.

    If you are getting errors, copy and paste here the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Black Jack Game help on finding the error

    }


    public static int Loss (int money, int amount)
    {
    money = money - amount;

    return money;

    }


    public static int Win (int money, int amount)
    {
    money = money + amount;

    return money;

    }


    public static int Bet (int money)
    {
    int amount = 0;

    c.setFont (new Font ("VERDANA", Font.PLAIN, 30));
    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 510);
    c.setCursor (26, 92);
    amount = c.readInt ();
    cleartop ();

    while (amount > money || amount < 0)
    {
    if (amount > money)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nYou gotta earn it before you can bet it!", 5, 510);

    }

    if (amount < 0)
    {
    cleartop ();
    c.setColor (Color.yellow);
    c.drawString ("\nThere is no such thing as negative money bro!", 5, 510);
    }

    c.setColor (Color.yellow);
    c.drawString ("\nHow much would you like to bet?(0 to not bet)", 5, 570);
    c.setCursor (29, 92);
    amount = c.readInt ();
    clearbottom ();
    }
    cleartop ();
    clearbottom ();

    return amount;
    }


    public static void main (String[] args)
    {
    c = new Console (34, 120);
    String name;
    char NewGame;

    do
    {
    int money = 1000;
    char NewHand;

    c.clear ();
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setFont (new Font ("VERDANA", Font.BOLD, 50));
    c.setColor (Color.green);
    c.drawString ("Welcome to BlackJack!", 150, 200);
    c.drawString ("Please enter your name: ", 150, 350);
    c.setCursor (22, 42);
    name = c.readString ();

    do
    {
    c.clear ();
    int Card = 0, Ash_Card = 0, CardValue = 0, Ash_CardValue = 0, amount = 0, NumOfCards, NumOfCards_Ash;
    char Hit = 'N', Bet;
    boolean win = false, loss = false;

    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 30));
    c.setColor (Color.blue);

    c.drawString (" " + name, 400, 20);

    c.drawString ("ASH", 390, 245);

    c.setColor (Color.black);
    c.fillRect (0, 480, 1000, 120);


    drawbar (money, CardValue, amount);


    cleartop ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 510);
    Bet = c.getChar ();

    while (Bet != 'y' && Bet != 'n' && Bet != 'Y' && Bet != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    clearbottom ();
    c.drawString ("\nWould you like to place a bet? (y/n)", 5, 570);
    Bet = c.getChar ();
    clearbottom ();
    }


    drawbar (money, CardValue, amount);

    cleartop ();

    if (Bet == 'Y' || Bet == 'y')
    amount = Bet (money);

    for (NumOfCards = 0 ; NumOfCards < 2 ; NumOfCards++)
    {
    Card = GetCard (NumOfCards);
    CardValue = CardValue + Card;
    }

    c.setColor (new Color (130, 90, 30));
    c.fillRoundRect (5, 265, 140, 190, 10, 10);
    c.fillRoundRect (155, 265, 140, 190, 10, 10);
    c.setColor (Color.black);
    c.fillRoundRect (165, 275, 120, 170, 10, 10);
    c.fillRoundRect (15, 275, 120, 170, 10, 10);
    c.setFont (new Font ("ALGERIAN", Font.PLAIN, 15));
    c.setColor (Color.blue);
    c.drawString ("BLACKJACK", 30, 360);
    c.drawString ("BLACKJACK", 180, 360);


    do
    {
    drawbar (money, CardValue, amount);

    if (CardValue == 21)
    {

    cleartop ();
    c.drawString ("\nBlackJack, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (CardValue >= 22)
    {
    cleartop ();
    c.drawString ("\nOoops, you busted. Ash Wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nWould you like to take a hit? (y/n)", 5, 510);
    Hit = c.getChar ();

    if (Hit == 'y' || Hit == 'Y')
    {
    Card = GetCard (NumOfCards);
    NumOfCards++;
    CardValue = CardValue + Card;
    }
    }
    }
    while ((Hit == 'y' || Hit == 'Y') && (!win && !loss));

    c.setColor (Color.white);
    c.fillRect (0, 265, 295, 220);
    cleartop ();

    for (NumOfCards_Ash = 0 ; NumOfCards_Ash < 2 ; NumOfCards_Ash++)
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    Ash_CardValue = Ash_CardValue + Ash_Card;
    }

    if ((Ash_CardValue == 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBlackJack for Ash, he wins", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if ((Ash_CardValue > 21) && (!win && !loss))
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }

    else if (Ash_CardValue <= CardValue && (!loss && !win))
    {
    while (Ash_CardValue <= 16 && (!loss && !win))
    {
    Ash_Card = GetAsh_Card (NumOfCards_Ash);
    NumOfCards_Ash++;
    Ash_CardValue = Ash_CardValue + Ash_Card;

    if (Ash_CardValue > 21)
    {
    cleartop ();
    c.drawString ("\nBummer, Ash busted. You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    }

    if (!loss && !win)
    {
    if (Ash_CardValue > CardValue)
    {
    cleartop ();
    c.drawString ("\nAsh has higher numbers than you, Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else if (Ash_CardValue == CardValue)
    {
    if (NumOfCards_Ash > NumOfCards)
    {
    cleartop ();
    c.setFont (new Font ("VERDANA", Font.BOLD, 20));
    c.drawString ("\nYou guys have the same numbers but Ash has more cards, so Ash wins!", 5, 510);
    money = Loss (money, amount);
    loss = true;
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou guys have the same numbers but " + name + " has more cards, so " + name + " wins!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }

    else
    {
    cleartop ();
    c.drawString ("\nYou have higher numbers than Ash, You win!", 5, 510);
    money = Win (money, amount);
    win = true;
    }
    }
    drawbar (money, CardValue, amount);

    do
    {
    clearbottom ();
    c.drawString ("\nWould you like to play a new hand?(y/n)", 5, 570);
    NewHand = c.getChar ();
    if (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N')
    {
    cleartop ();
    c.drawString ("\nInvalid entry, please enter y or n", 5, 510);
    }
    }
    while (NewHand != 'y' && NewHand != 'n' && NewHand != 'Y' && NewHand != 'N');
    }
    while (money > 0 && (NewHand == 'y' || NewHand == 'Y'));

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 45));
    c.setColor (Color.black);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.green);
    if (NewHand == 'y' || NewHand == 'Y')
    c.drawString ("You are Bankcrupt!", 20, 100);

    c.drawString ("\nYour total money: $" + money, 20, 200);
    c.drawString ("\nYour net Profit: $" + (money - 1000), 20, 300);

    do
    {
    c.drawString ("\nWould you like to restart the whole game?(y/n)", 20, 500);
    NewGame = c.getChar ();

    if (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N')
    c.drawString ("\nInvalid input, please enter y or n", 20, 600);
    }
    while (NewGame != 'y' && NewGame != 'n' && NewGame != 'Y' && NewGame != 'N');

    }


    while (NewGame == 'y' || NewGame == 'Y')
    ;

    c.clear ();
    c.setFont (new Font ("TIMES NEW ROMAN", Font.BOLD, 50));
    c.setColor (Color.white);
    c.fillRect (0, 0, 1000, 800);
    c.setColor (Color.blue);
    c.drawString ("\n\nThank you for playing BlackJack!", 100, 100);
    c.drawString ("Developed by Ashraf Abedin.", 120, 200);
    c.drawString ("Hope you had fun!", 220, 300);

    } // main method

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Black Jack Game help on finding the error

    You need to do two things:

    1) Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    2) copy and paste here the full text of the error messages.

    Some how you have not been able to do either of these things.
    Last edited by Norm; June 13th, 2012 at 07:21 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Black Jack Game help on finding the error

    ok il try to do it

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Black Jack Game help on finding the error

    NOT yet. Use the Preview Post button to verify the formatting before saving. When its down correctly it should look like this:
          String Name = "aName";
          int index = Arrays.binarySearch(result, Name);
          System.out.println("index=" + index);           // changes with size of result[]

    Also you need to post the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: JAVA game black jack need help on finding an error!!

    ...did you have a question? I see you've dumped a ton of unformatted code here (without highlight tags), but I don't see a question, or a description of what you expect to happen versus what actually happens.

    I suggest you read through the link in my signature on asking questions the smart way, then provide an SSCCE and a specific technical question. You should also do some debugging, or at least add some print statements, until you figure out what the problem is.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: JAVA game black jack need help on finding an error!!

    Clyde, please do not post duplicate threads. I've merged your threads into one, let's keep it here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 6
    Last Post: February 24th, 2012, 09:45 PM
  2. black jack game
    By 314159 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 6th, 2011, 10:42 AM
  3. (URGENT) Plz help me with the black jack program.
    By diogo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2011, 04:08 AM
  4. error with a java game..(beginner)
    By Skat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 1st, 2010, 02:04 PM
  5. Black Jack Statistics game? lost.
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2010, 07:20 AM

Tags for this Thread