Results 1 to 2 of 2
  1. #1
    TangoMango is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Exclamation Help With BlackJack Game !

    Hey,

    I Made A Blackjack Game For My School Project, And I'm Pretty Sure All The Knowledge In The Game Is Correct.

    However, I Am Getting A Large Amount Of Errors When Trying To Compile. Can Someone Help Me !


    import java.util.*;
    import java.util.Scanner;


    public class BlackJack{
    static int playerStand = 0;
    static int computerStand = 0;
    static int cardsUsed=0;
    static int value = 0;
    static int unknown = 0;
    static int chips = 5000;
    static int bet = 0;
    static int player = 0;
    static int computer = 0;
    static int winMoney = 0;
    static int computerD=0;
    static String playerCards="";
    static String decision="";
    static String computerCards="";
    static String deck;// choice;
    static boolean bust=false;


    public static void main ( String[] arg ) throws Exception{
    game();
    }


    public static boolean display (){ //Asks The User If He/She Wants To Play Or Not.
    boolean play=false;
    String choice="";
    Scanner input = new Scanner(System.in);
    System.out.println("\n\nWW WW lll TTTTTTT ");
    System.out.println("WW WW eee lll cccc oooo mm mm mmmm eee TTT oooo ");
    System.out.println("WW W WW ee e lll cc oo oo mmm mm mm ee e TTT oo oo");
    Thread.sleep(500);
    System.out.println(" WW WWW WW eeeee lll cc oo oo mmm mm mm eeeee TTT oo oo");
    System.out.println(" WW WW eeeee lll ccccc oooo mmm mm mm eeeee TTT oooo ");
    System.out.println("");
    Thread.sleep(1000);
    System.out.println(" TTTTTTT ");
    System.out.println(" TTT oooo ");
    System.out.println(" TTT oo oo");
    Thread.sleep(500);
    System.out.println(" TTT oo oo");
    System.out.println(" TTT oooo ");
    Thread.sleep(1000);
    System.out.println("");
    System.out.println("BBBBB lll kk JJJ kk !!! ");
    System.out.println("BB B lll aa aa cccc kk kk JJJ aa aa cccc kk kk !!! ");
    System.out.println("BBBBBB lll aa aaa cc kkkkk JJJ aa aaa cc kkkkk !!! ");
    Thread.sleep(500);
    System.out.println("BB BB lll aa aaa cc kk kk JJ JJJ aa aaa cc kk kk ");
    System.out.println("BBBBBB lll aaa aa ccccc kk kk JJJJJ aaa aa ccccc kk kk !!! ");
    Thread.sleep(1000);

    while (!(choice.equals("s") || choice.equals("q"))) {
    System.out.print("Press s to start playing or q to quit: ");
    choice=input.nextLine();
    }

    if (choice.equals("s")) {
    return(true);
    }
    else if (choice.equals("q")) {
    System.out.print("\nHope you try Blackjack next time.\n");
    }
    }



    public static int game() {
    Scanner input = new Scanner(System.in);

    System.out.print("Please enter your name: ");
    name=input.nextLine();

    System.out.println("Hello " +name+ ", Welcome to Casino Legit ! You currently have " +chips+ " !");
    System.out.println("How much would you like to bet today, " +name+ " :");
    bet = input.nextInt();

    while (bet > chips) {
    System.out.println("I'm sorry, " +name+ "I'm afraid I can not let you do that. You do not have sufficient chips, please reconsider your bet !");
    System.out.print("How much exctally would you like to bet, " +name+ " :");
    bet = input.nextInt();
    }

    if (bet <= chips) {
    chips-=bet;
    winMoney=bet*2;
    }


    //System.out.println();
    //Collections.shuffle(Arrays.asList(cards));// I found this on the internet it's for shuffling the cards.

    while(bet <= chips);
    do{
    cardDealer(deck);//dealing cards.
    String iCard = card;
    }

    if(iCard==("0")){//if cards run out it reshuffles the array and resets the counter.
    cardsUsed=0;
    Collections.shuffle(Arrays.asList(deck));
    cardDealer(deck);
    }

    System.out.println();
    playerCards+=iCard;
    cardValueAssigner(iCard);//getting the value of the card.
    player+=value;//summing values of the cards.


    System.out.println("You were dealt"+ card);
    System.out.println("Your cards are: "+playerCards);


    System.out.println("Would you like to? hit/stand");
    decision = input.nextLine();

    if(decision.equals("stand")){
    playerStand=1;
    break;
    }

    while(decision.equals("hit")&&player<21);
    if (bust){
    break;
    }

    if(playerStand==1){//if player stand computer turn starts.
    System.out.println("Computer's turn !");

    do{
    cardDealer(deck);
    String iCard=card;
    cardDealer(deck);//dealing cards.
    String iCard = card;
    }
    }

    if(iCard==("0")){//if cards run out it reshuffles the array and resets the counter.
    cardsUsed=0;
    Collections.shuffle(Arrays.asList(deck));
    cardDealer(deck);
    }

    System.out.println();
    computerCards+=iCard;
    (cardValueAssigner(iCard);//getting the value of the card.
    computer+=value;//summing values of the cards.

    System.out.println("Computer was dealt"+ card);
    System.out.println("Computer cards are: "+computerCards);
    compd++;

    while(computer<16);//condition to make computer stand.

    if(computer>=16&&computer<=21){
    System.out.println("Computer stands.");
    computerStand =1;
    }


    if(playerStand==computerStand){//if both player and computer stand it checks for winning conditions.
    if(player>computer){
    System.out.println("You won !");

    System.out.println("Computer cards are: "+computerCards);
    numchips+=pot;
    System.out.println("You have " + chips +" chips.");
    }
    else if(computer>player){
    System.out.println("You lost !");


    System.out.println("Computer cards are: "+computerCards);
    broke(chips);

    System.out.println("You lost "+ bet +" chips.");
    System.out.println("You now have " + chips);
    }

    else{
    System.out.println("Tie");
    chips+=bet;
    System.out.println("You have "+chips+" chips.");
    }
    }



    if(chips>0){
    System.out.println("Do you wish to play again? y/n");
    again = c.nextLine().charAt(0);
    if(again==('y')||again==('Y')){//resests everything for new turn.
    playerCards="";
    computerCards="";
    player=0;
    computer=0;
    computerD=0;
    }
    }

    }while(again==('y')||again==('Y'));

    }


    public static String cardDealer(String[] deck){ // method for dealing a card
    if(cardsUsed<52){
    card=deck[cardsUsed++];
    return(card);
    }
    else if(cardsUsed>=52){
    return("0");
    }
    else{
    return("0");
    }
    }




    public static String deckCreator() { // Creates An Unshuffled Deck Of Cards.
    int v = 0;
    String deck[] = new String [52];

    for (int a = 0; a <= 52; a++) {

    v = a%13;

    if (v == 0) {
    deck[a]="K";
    }
    else if (v == 1) {
    deck[a]="A";
    }
    else if (v >= 2 && v < 11) {
    deck[a]= " " + v;
    }
    else if (v == 11) {
    deck[a]= "J";
    }
    else if (v == 12) {
    deck[a]= "Q";
    }

    if (a < 13) {
    deck [a]= (char)(6) + deck[a] + (" ");
    }
    else if (a < 26) {
    deck[a] = (char)(3) + deck[a] + (" ");
    }
    else if (a < 39) {
    deck[a] = (char)(5) + deck[a] + (" ");
    }
    else if (a < 52) {
    deck[a] = (char)(4) + deck[a] + (" ");
    }
    }
    }




    public static int cardValueAssigner(String deck) {
    Scanner input = new Scanner(System.in);
    int value = 0;

    if(deck.contains("2")) {
    value = 2;
    }
    else if(deck.contains("3")) {
    value = 3;
    }
    else if(deck.contains("4")){
    value = 4;
    }
    else if(deck.contains("5")) {
    value = 5;
    }
    else if (deck.contains("6")) {
    value = 6;
    }
    else if(deck.contains("7")) {
    value = 7;
    }
    else if(deck.contains("8")) {
    value = 8;
    }
    else if(deck.contains("9")) {
    value = 9;
    }
    else if(deck.contains("A")) {
    System.out.print(name + ", you've got an Ace ! Would you like to use it as 1 or 11 : ");
    value = input.nextInt();
    while (!(value==1 || value==11)) {
    System.out.println(name + ", that is not acceptable. Please reconsider your choice, " +name);
    System.out.print("So, what's your decision " +name+ " : ");
    value = input.nextInt();
    }
    }
    else if (deck.contains("K") || deck.contains("Q") || deck.contains("J") || deck.contains("10")) {
    value = 10;
    }
    return(value
    }
    Attached Files Attached Files

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    What are these errors?

    Nobody is going to want to read through all of that unformatted code. If you post code, make sure it's an SSCCE and don't forget the code tags.

    That means you should narrow each of your errors down to as little code as possible- if it's longer than 10 lines or so, it's probably too long.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. blackjack help
    By jordaejava in forum New To Java
    Replies: 1
    Last Post: 12-11-2009, 05:44 AM
  2. Multiplayer BlackJack Applet
    By lostwake in forum Java Applets
    Replies: 0
    Last Post: 07-23-2009, 11:04 PM
  3. Need ideas and help for a simple BlackJack Game
    By Dannii in forum New To Java
    Replies: 5
    Last Post: 04-27-2009, 10:53 AM
  4. Help with simple Blackjack Program?
    By meeper3000 in forum New To Java
    Replies: 2
    Last Post: 04-26-2009, 09:46 AM
  5. BlackJack help please,, adding hand values
    By javakid9000 in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 04:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •