13 Replies - 2899 Views - Last Post: 07 December 2008 - 09:01 PM Rate Topic: ***** 1 Votes

#1 wwood8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-December 07

BlackJack Game

Post icon  Posted 02 May 2008 - 08:11 AM

Unfortunately, I had to turn in this assignment unfinished. Whenever the player stands, everything works fine, however if you choose to hit, nothing happens. I have been working on this for weeks, I have to know what I am doing wrong! :crazy:

/**
 * Objects in this class represent one card from a deck of 52.
 * 
 * @author Chad Wood
 * 3/10/2008
 */

public class Card 
{
	private final int cardValue;
	private final int cardSuit;
	public final static int ACE = 1,		  
							JACK = 11,	   
							QUEEN = 12,	  
							KING = 13;
	public final static int SPADES = 0,	   
							HEARTS = 1,
							DIAMONDS = 2,
							CLUBS = 3;		  
	public Card(int theValue, int theSuit) 
	{
		cardValue = theValue;
		cardSuit = theSuit;
	}
	public int getSuit() 
	{
		return cardSuit;
	}
	public int getValue() 
	{
		return cardValue;
	}
	public String getValueAsString() 
	{
		switch (cardValue) 
		{
		   case 1:   return "Ace";
		   case 2:   return "2";
		   case 3:   return "3";
		   case 4:   return "4";
		   case 5:   return "5";
		   case 6:   return "6";
		   case 7:   return "7";
		   case 8:   return "8";
		   case 9:   return "9";
		   case 10:  return "10";
		   case 11:  return "Jack";
		   case 12:  return "Queen";
		   case 13:  return "King";
		   default:  return "Invalid";
		}
	}
	 public String getSuitAsString() 
	{
		switch (cardSuit) 
		{
		   case SPADES:   return "Spades";
		   case HEARTS:   return "Hearts";
		   case DIAMONDS: return "Diamonds";
		   case CLUBS:	return "Clubs";
		   default:	   return "Invalid";
		}
	}
	public String toString()
	{
		return getValueAsString() + " of " + getSuitAsString();
	}


} 



/**
 * This class will represent an array which shall act as a deck of 52 cards.
 * 
 * @author Chad Wood 
 * 3/10/2007
 */
public class Deck 
{
	private Card[] deck;   
	private int cardsDealt; 
	public Deck() 
	   {
	   deck = new Card[52];
	   int cardCounter = 0; 
	   for ( int cardSuit = 0; cardSuit <= 3; cardSuit++ ) 
	   {
		  for ( int cardValue = 1; cardValue <= 13; cardValue++ ) 
		  {
			 deck[cardCounter] = new Card(cardValue,cardSuit);
			 cardCounter++;
		  }
	   }
	   cardsDealt = 0;
	}
	
	public void shuffle() 
	{
		for ( int i = 51; i > 0; i-- ) 
		{
			int random = (int)(Math.random()*(i+1));
			Card temp = deck[i];
			deck[i] = deck[random];
			deck[random] = temp;
		}
		cardsDealt = 0;
	}
	public int cardsRemaining() 
	{
	   return 52 - cardsDealt;
	}
	public Card dealCard() 
	{
		if (cardsDealt == 52)
		   shuffle();
		cardsDealt++;
		return deck[cardsDealt - 1];
	}
} 


/**
 * This class is used to simply represent a hand of cards.
 * 
 * Chad Wood 
 * 3/10/2007
 */
import java.util.Vector;
public class Hand 
{
   private Vector hand;   
   public Hand()
   {
	hand = new Vector();
   }
   public void clear() 
   {
	hand.removeAllElements();
   }
   public void addCard(Card card) 
   {
	if (card != null)
	 hand.addElement(card);
   }
   public void removeCard(Card card) 
   {
	 hand.removeElement(card);
   }
   public void removeCard(int position) 
   {
	if (position >= 0 && position < hand.size())
	 hand.removeElementAt(position);
   }
   public int getCardCount() 
   {
	 return hand.size();
   }
   
   public Card getCard(int position) {
		
	  if (position >= 0 && position < hand.size())
		 return (Card)hand.elementAt(position);
	  else
		 return null;
   }
   
   public void sortBySuit() {
		
	  Vector newHand = new Vector();
	  while (hand.size() > 0) {
		 int position = 0;  
		 Card card = (Card)hand.elementAt(0); 
		 for (int i = 1; i < hand.size(); i++) 
		 {
			Card card1 = (Card)hand.elementAt(i);
			if ( card1.getSuit() < card.getSuit() ||
					(card1.getSuit() == card.getSuit() && card1.getValue() < card.getValue()) ) 
					{
				position = i;
				card = card1;
			}
		 }
		 hand.removeElementAt(position);
		 newHand.addElement(card);
	  }
	  hand = newHand;
   }
   
   public void sortByValue() 
   {
	  Vector newHand = new Vector();
	  while (hand.size() > 0) 
	  {
		 int position = 0;  
		 Card card = (Card)hand.elementAt(0);  
		 for (int i = 1; i < hand.size(); i++) 
		 {
			Card card1 = (Card)hand.elementAt(i);
			if ( card1.getValue() < card.getValue() ||
					(card1.getValue() == card.getValue() && card1.getSuit() < card.getSuit()) ) 
			{
				position = i;
				card = card1;
			}
		 }
		 hand.removeElementAt(position);
		 newHand.addElement(card);
	  }
	  hand = newHand;
   }
   
}


/**
 * The class is a subclass of the Hand Class.  This class
 * determines the value of tha hand according to the rules of 21.
 * Chad Wood
 * 3/10/2007
 */
public class Game21Hand extends Hand 
{
	 public int getGame21Value() 
	 {
		 int value;	  
		 boolean atLeastOneAce;  
		 int cards;	
		 value = 0;
		 atLeastOneAce = false;
		 cards = getCardCount();
		 for ( int i = 0;  i < cards;  i++ ) 
		 {
			 Card card;   
			 int cardVal;  
			 card = getCard(i);
			 cardVal = card.getValue();  
			 if (cardVal > 10) 
			 {
				 cardVal = 10;   
			 }
			 if (cardVal == 1) 
			 {
				 atLeastOneAce = true;	 
			 }
			 value = value + cardVal;
		  }

			 
		  if ( atLeastOneAce == true  &&  value + 10 <= 21 )
			  value = value + 10;

		  return value;

	 }  
 
} 


/**
 * This class allows the user to play a game of 21 against the computer.
 * 
 * Chad Wood
 * 3/10/2008
 */
import java.util.Scanner;
import java.util.*;

public class Game21
{

	public static void main(String[] args)
	{ 
		boolean userWins;
		System.out.println("Get ready to play 21.");
		playGame21();
	}
	 static boolean playGame21()
	{
		Deck deck;
		Game21Hand compHand;
		Game21Hand yourHand;
		deck = new Deck();
		compHand = new Game21Hand();
		yourHand = new Game21Hand();
		deck.shuffle();
		compHand.addCard(deck.dealCard());
		compHand.addCard(deck.dealCard());
		yourHand.addCard(deck.dealCard());
		yourHand.addCard(deck.dealCard());
		if (compHand.getGame21Value() == 21)
		{
			System.out.println("The Dealer has the " + compHand.getCard(0)
							  + " and the " + compHand.getCard(1) + ".");
			System.out.println("You have the " + yourHand.getCard(0)
							  + " and the " + yourHand.getCard(1) + ".");
			System.out.println("The Dealer wins with 21!!");
			
			return false;
		}
		if (yourHand.getGame21Value() == 21)
		{
			System.out.println("The Dealer has the " + compHand.getCard(0)
							  + " and the " + compHand.getCard(1) + ".");
			System.out.println("The User has the " + yourHand.getCard(0)
							  + " and the " + yourHand.getCard(1) + ".");
			System.out.println("21, You win!!.");
			
			return true;
		}
		while (true)
		{
			System.out.println("You have:");
			for (int i = 0; i < yourHand.getCardCount(); i++)
				System.out.println("	" + yourHand.getCard(i));
			System.out.println("Your current score is: " + yourHand.getGame21Value());
			System.out.println();
			System.out.println("The Dealer is showing the " + compHand.getCard(0));
			System.out.println("Would You Like to Hit (h) or Stand (s)? ");
			char userChoice;
			do
			{
				Scanner Keyboard = new Scanner(System.in);
				userChoice = Keyboard.next( ).charAt(0);			   
				if (userChoice != 'h' && userChoice != 's')
					System.out.println("Please choose h or s:  ");
			}
			   while (userChoice != 's');
			  
			if (userChoice == 's')
			{
			  System.out.println("You choose to stand.");
			  System.out.println("The Dealer's hand is:");
			  System.out.println("	" + compHand.getCard(0));
			  System.out.println("	" + compHand.getCard(1));
			while (compHand.getGame21Value() <= 16)
			{
				Card newCard = deck.dealCard();
				System.out.println("The Dealer hits and receives the: " + newCard);
				compHand.addCard(newCard);
				if (compHand.getGame21Value() > 21)
				{
					System.out.println("The Dealer busted, You win.");
					
					return true;
				} 
			}
		   
			 if (userChoice != 's')
			{
				Card newCard = deck.dealCard();
				yourHand.addCard(newCard);
				System.out.println("You choose to hit.");
				System.out.println("You drew the " + newCard);
				System.out.println("Your new total is " + yourHand.getGame21Value());
				if (yourHand.getGame21Value() > 21)
				{
					System.out.println("Over 21.  You Busted.");
					System.out.println("The Dealer's down card was: "
										+ compHand.getCard(1));
					
					return false;
				}
			}
			if (userChoice == 's')
		   

			System.out.println("The Dealer's score is: " + compHand.getGame21Value());
			if (compHand.getGame21Value() == yourHand.getGame21Value())
			{
				System.out.println("It's a tie, you lose.");
				
				return false;
			}
			else if (compHand.getGame21Value() > yourHand.getGame21Value())
			{
				System.out.println("The Dealer wins because, " + compHand.getGame21Value()
									+ " beats " + yourHand.getGame21Value() + ".");
				
				return false;
			}
			else
			{
				System.out.println("You win because, " + yourHand.getGame21Value()
								   + " beats " + compHand.getGame21Value() + ".");
				
				return true;
			}


		}
	  
	  return true;
	}
	

}
}
	









I know the problem lies in the Game21 class, I just can't get it.

Is This A Good Question/Topic? 0
  • +

Replies To: BlackJack Game

#2 wwood8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-December 07

Re: BlackJack Game

Posted 02 May 2008 - 11:32 AM

Someone please help me!!
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: BlackJack Game

Posted 02 May 2008 - 02:52 PM

View Postwwood8, on 2 May, 2008 - 11:32 AM, said:

Someone please help me!!

I'll have a look at it
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: BlackJack Game

Posted 02 May 2008 - 03:11 PM

The first possible problem I see is

do
{
   Scanner Keyboard = new Scanner(System.in);
   userChoice = Keyboard.next().charAt(0);			   
   if (userChoice != 'h' && userChoice != 's')
	   System.out.println("Please choose h or s:  ");
}
while (userChoice != 's');




In all you class you should have only one Scanner shared by everybody.
If you create more than 1 Scanner on the same InputStream you'll never know to which one the System will deliver the inputed characters.

Second your while only check on 's' not 'h' so you'll stay in the loop until "s" is entered

while(userChoice != 's' && userChoice != 'h');

This post has been edited by pbl: 02 May 2008 - 03:51 PM

Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5643
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: BlackJack Game

Posted 02 May 2008 - 04:33 PM

The logic in your while loop is a little odd.

This is what you have have.
if (userChoice == 's') {
	//...
}
// huh?, why not an else?
if (userChoice != 's') {
	//...
}

// now there's more
// we shouldn't be here
// everything after the if 
if (userChoice == 's')
	System.out.println("The Dealer's score is: " + compHand.getGame21Value());
//...




This probably what it should look like:
while (true) {
	// get choice
	if (userChoice == 's') {
	//...
	} else {
	//...
	}
}


Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: BlackJack Game

Posted 02 May 2008 - 04:41 PM

If you are talking of optimization I would also suggest

	final static String[] values = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}; 
	final static String[] suit = {"Spades", "Hearts", "Diamonds", "Clubs"};

	public String getValueAsString() 
	{
		return values[cardValue-1];
	}
	
	 public String getSuitAsString() 
	{
		 return suit[cardSuit];
	}



rather than the horrible useless switch statement

This post has been edited by pbl: 02 May 2008 - 07:13 PM

Was This Post Helpful? 0
  • +
  • -

#7 wwood8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-December 07

Re: BlackJack Game

Posted 04 May 2008 - 10:42 AM

Now I am getting a message saying that newCard is already defined.

/**
 * This class allows the user to play a game of 21 against the computer.
 * 
 * Chad Wood
 * 3/10/2008
 */
import java.util.Scanner;
import java.util.*;

public class Game21
{

	public static void main(String[] args)
	{ 
		boolean userWins;
		System.out.println("Get ready to play 21.");
		playGame21();
	}
	 static boolean playGame21()
	{
		Deck deck;
		Game21Hand compHand;
		Game21Hand yourHand;
		deck = new Deck();
		compHand = new Game21Hand();
		yourHand = new Game21Hand();
		deck.shuffle();
		compHand.addCard(deck.dealCard());
		compHand.addCard(deck.dealCard());
		yourHand.addCard(deck.dealCard());
		yourHand.addCard(deck.dealCard());
		if (compHand.getGame21Value() == 21)
		{
			System.out.println("The Dealer has the " + compHand.getCard(0)
							  + " and the " + compHand.getCard(1) + ".");
			System.out.println("You have the " + yourHand.getCard(0)
							  + " and the " + yourHand.getCard(1) + ".");
			System.out.println("The Dealer wins with 21!!");
			
			return false;
		}
		if (yourHand.getGame21Value() == 21)
		{
			System.out.println("The Dealer has the " + compHand.getCard(0)
							  + " and the " + compHand.getCard(1) + ".");
			System.out.println("The User has the " + yourHand.getCard(0)
							  + " and the " + yourHand.getCard(1) + ".");
			System.out.println("21, You win!!.");
			
			return true;
		}
		while (true)
		{
			System.out.println("You have:");
			for (int i = 0; i < yourHand.getCardCount(); i++)
				System.out.println("	" + yourHand.getCard(i));
			System.out.println("Your current score is: " + yourHand.getGame21Value());
			System.out.println();
			System.out.println("The Dealer is showing the " + compHand.getCard(0));
			System.out.println("Would You Like to Hit (h) or Stand (s)? ");
			char userChoice;
			do
			{
				Scanner Keyboard = new Scanner(System.in);
				userChoice = Keyboard.next( ).charAt(0);			   
				if (userChoice != 'h' && userChoice != 's')
					System.out.println("Please choose h or s:  ");
			}
			   while (userChoice != 's' && userChoice != 'h');
			  
			if (userChoice == 's')
			{
			  System.out.println("You choose to stand.");
			  System.out.println("The Dealer's hand is:");
			  System.out.println("	" + compHand.getCard(0));
			  System.out.println("	" + compHand.getCard(1));
			while (compHand.getGame21Value() <= 16)
			{
				Card newCard = deck.dealCard();
				System.out.println("The Dealer hits and receives the: " + newCard);
				compHand.addCard(newCard);
				if (compHand.getGame21Value() > 21)
				{
					System.out.println("The Dealer busted, You win.");
					
					return true;
				} 
			
		   
			  else if (userChoice == 'h')
			{
				Card newCard = deck.dealCard();
				yourHand.addCard(newCard);
				System.out.println("You choose to hit.");
				System.out.println("You drew the " + newCard);
				System.out.println("Your new total is " + yourHand.getGame21Value());
				if (yourHand.getGame21Value() > 21)
				{
					System.out.println("Over 21.  You Busted.");
					System.out.println("The Dealer's down card was: "
										+ compHand.getCard(1));
					
					return false;
				}
			}
			else if (userChoice == 's')
		   

			System.out.println("The Dealer's score is: " + compHand.getGame21Value());
			if (compHand.getGame21Value() == yourHand.getGame21Value())
			{
				System.out.println("It's a tie, you lose.");
				
				return false;
			}
			else if (compHand.getGame21Value() > yourHand.getGame21Value())
			{
				System.out.println("The Dealer wins because, " + compHand.getGame21Value()
									+ " beats " + yourHand.getGame21Value() + ".");
				
				return false;
			}
			else
			{
				System.out.println("You win because, " + yourHand.getGame21Value()
								   + " beats " + compHand.getGame21Value() + ".");
				
				return true;
			}


		}
	  
	  return true;
	}
	

}
}
}


Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: BlackJack Game

Posted 04 May 2008 - 11:09 AM

No comments on the previous replies ?

	while (compHand.getGame21Value() <= 16)
	{
		 Card newCard = deck.dealCard();   // <------- newCard defined here

		 System.out.println("The Dealer hits and receives the: " + newCard);
		 compHand.addCard(newCard);
		 if (compHand.getGame21Value() > 21)
		 {
		System.out.println("The Dealer busted, You win.");			
		return true;
		 } 
				   
		 else if (userChoice == 'h')
		 {
// newCard already exists defined at the beginning of the while you don't have to recreate it
/////		Card newCard = deck.dealCard();
		newCard = deck.dealCard();
		yourHand.addCard(newCard);
		System.out.println("You choose to hit.");
		System.out.println("You drew the " + newCard);



No comments on previous reply.
No "thanks"
I've spent a few time on your problem
Don't expect me to answer any other question.

This post has been edited by pbl: 04 May 2008 - 08:46 PM

Was This Post Helpful? 0
  • +
  • -

#9 krich87  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 03-December 08

Re: BlackJack Game

Posted 07 December 2008 - 08:35 PM

Out of curiosity, I am working on a blackjack game like this. Did the bugs ever get worked out of this one? I am curious to see the final product! Although I am not nearly as good at Java programming so mine looks nothing like this... It would just be nice to see the final logic and flow of the program

However this is my code so far and I don't even really know if I am going in the right direction. The only things that work as of right now are drawing the first 2 cards for both the dealer and the player. I think my documentation is above average so anyone that looks at this should be able to understand where I am at and where I am going.

import java.util.*;
import java.io.*;
import java.lang.*;

public class BlackJackClassProject
{
	public static void main(String[] args) throws IOException
	{
	
	BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
	
	//Declare Variables
	int again = 0;
	do
	{
	double range = 26;
	int randomGenNum;
	int kitty = 1000;
	int yourBet;
	int userHandValue = 0;
	int userDrawnValue;
	int dealerHandValue = 0;
	int dealerDrawnValue;
	String playAgain;
	String hit = "";
	String strBetAmount;
	String userCard, dealerCard;

	int[] arrayCardValues = {0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
	String[] arrayCardSuites = 
	{
	"","","Ace/Clubs","Ace/Diamonds","Ace/Hearts","Ace/Spades",
	"2/Clubs","2/Diamonds","2/Hearts","2/Spades","3/Clubs","3/Diamonds","3/Hearts","3/Spades",
	"4/Clubs","4/Diamonds","4/Hearts","4/Spades","5/Clubs","5/Diamonds","5/Hearts","5/Spades",
	"6/Clubs","6/Diamonds","6/Hearts","6/Spades","7/Clubs","7/Diamonds","7/Hearts","7/Spades",
	"8/Clubs","8/Diamonds","8/Hearts","8/Spades","9/Clubs","9/Diamonds","9/Hearts","9/Spades",
	"10/Clubs","10/Diamonds","10/Hearts","10/Spades","Jack/Clubs","Jack/Diamonds","Jack/Hearts","Jack/Spades"
	,"Queen/Clubs","Queen/Diamonds","Queen/Hearts","Queen/Spades","King/Clubs","King/Diamonds","King/Hearts","King/Spades"
	};

	//ask the user how much they want to bet
	System.out.println("How much do you want to bet?");
	strBetAmount = dataIn.readLine();
	yourBet = Integer.parseInt(strBetAmount);	

	//draw three cards (one card face up for dealer, two for player)
	
		//dealer first drawn card
		randomGenNum = (int)((range * Math.random()) + 1)*2;
		//assigning the dealer hand value & card, pulling index from array
		dealerHandValue = arrayCardValues[randomGenNum];
		//Check if the dealer got an ace
		if ((randomGenNum >= 2) && (randomGenNum <= 5))
			{
			dealerHandValue = dealerHandValue + 10;
			}
		int tempDealerHandValue = dealerHandValue;
		dealerCard = arrayCardSuites[randomGenNum];
		//displaying values to the screen
		System.out.println("The dealer is showing a " + dealerCard);
		//System.out.println("The value is " + dealerHandValue);
		
		//dealers second drawn card
		randomGenNum = (int)((range * Math.random()) + 1)*2;
		//assigning the dealer hand value & card, pulling index from array
		dealerHandValue = arrayCardValues[randomGenNum];
		//Check if the dealer got an ace
		if ((dealerHandValue != 11) && (randomGenNum >= 2) && (randomGenNum <= 5))
			{
			dealerHandValue = dealerHandValue + 10;
			}
		dealerCard = arrayCardSuites[randomGenNum];
		//displaying values to the screen
		//System.out.println("The dealers second card is " + dealerCard);
		//System.out.println("The dealers total hand value is: " + (tempDealerHandValue + dealerHandValue));

		
	
		//users first drawn card
		randomGenNum = (int)((range * Math.random()) + 1)*2;
		//assigning the user hand value & card, pulling index from array
		userHandValue = arrayCardValues[randomGenNum];
		//Check if the user got an ace
		if ((randomGenNum >= 2) && (randomGenNum <= 5))
			{
			userHandValue = userHandValue + 10;
			}
		int tempUserHandValue = userHandValue;
		userCard = arrayCardSuites[randomGenNum];
		//displaying values to the screen
		System.out.println("Your first card is " + userCard);
		
		
		//users second drawn card
		randomGenNum = (int)((range * Math.random()) + 1)*2;
		//assigning the user hand value & card, pulling index from array
		userHandValue = arrayCardValues[randomGenNum];
		//Check if the user got an ace
		if ((userHandValue != 11) && (randomGenNum >= 2) && (randomGenNum <= 5))
			{
			userHandValue = userHandValue + 10;
			}
		userCard = arrayCardSuites[randomGenNum];
		//displaying values to the screen
		System.out.println("Your second card is " + userCard);
		System.out.println("Your total hand value is: " + (tempUserHandValue + userHandValue));
	/*
		//check for the either player having a blackjack(hand value = 21)
		if ((dealerHandValue = 21) && (userHandValue != 21))
			{
			//dealer = 21 user != 21 dealer wins, kitty - bet, game over 
			}
		
		if ((dealerHandValue != 21) && (userHandValue = 21))
			{
			//user = 21 dealer != user wins, kitty + bet, game over
			}
		
		if ((dealerHandValue = 21) && (userHandValue = 21))
			{
			//dealer and user = 21 noone wins, users kitty is not changed, game over
			}
	*/
		
		//if neither player has 21 continue through the loop
		

	
	
	
	
	
	
	/*
	//start the users loop
	while(userHandValue < 21)
		System.out.println("Would you like to hit? (Y/N)");
		hit = dataIn.readLine();
		hit = hit.toUpperCase();
	if (hit.compareTo("Y") == 0 )
		again = 1;
	//placeholder for giving user another card.
	else
		 again = 0;

	//start the dealers loop
	while (dealerHandValue < 17)
		
	
	//perform calculations to users "kitty"
	
	//See if the user wants to play again.
	System.out.println("Would you like to play again? (Y/N)");
	playAgain = dataIn.readLine();
	playAgain = playAgain.toUpperCase();
	if (playAgain.compareTo("Y") == 0 )
		again = 1;
	else
		 again = 0;
*/
	}
	while (again == 1);
	
	
	
	}
}	


Was This Post Helpful? 0
  • +
  • -

#10 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: BlackJack Game

Posted 07 December 2008 - 08:41 PM

I had to write a blackjack program for a final project. Once its graded and my grade is finalized i'll be more then happy to share some source with you all.

edited for typos

This post has been edited by KYA: 07 December 2008 - 08:41 PM

Was This Post Helpful? 0
  • +
  • -

#11 krich87  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 03-December 08

Re: BlackJack Game

Posted 07 December 2008 - 08:48 PM

Even though you haven't turned yours in yet does it run correctly? (at least correctly to your knowledge, teachers can always find something!) Also when are you turning it in?
Was This Post Helpful? 0
  • +
  • -

#12 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: BlackJack Game

Posted 07 December 2008 - 08:55 PM

It's turned in already, should be graded within the next week. Yes it runs awesomely (image icons load a little slow on initial load though), screenie:


Posted Image
Was This Post Helpful? 0
  • +
  • -

#13 krich87  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 03-December 08

Re: BlackJack Game

Posted 07 December 2008 - 08:59 PM

that looks really cool, don't know if it would help me though, I'm not that advanced mine is text base and I am struggling with that... I have a ways to go!! But I deffinetly look forward to seeing how yours looks...
Was This Post Helpful? 0
  • +
  • -

#14 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,137
  • Joined: 14-September 07

Re: BlackJack Game

Posted 07 December 2008 - 09:01 PM

Take away the images and the principle is the same. In fact, for testing purposes i made it text based first.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1