Results 1 to 2 of 2
Thread: Designing a blackjack game
- 01-15-2012, 07:22 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 9
- Rep Power
- 0
Designing a blackjack game
Hey all, I'm designing a game of blackjack in Java. The way I have to have it set up is with a Card class and a DeckOfCards class. I have designed both of these. The problem I'm having is displaying each card in the deck. I want it set up so that the toString method of the Card class displays a card in the form "value - suit". Value is an int and suit is a string, and are parameters entered in a new Card's constructor. The DeckOfCards class contains a method, create, which makes an array of 52 cards, and uses a for loop nested with if-else statements to create each card with its respective value and suit. Here is the code for the for loop:
for (int count = 0; count < 52; count++)
{
if (count < 13)
{
if (count == 0)
deck[count] = new Card(A, "Hearts");
else if (count > 0 && count < 9)
deck[count] = new Card(count + 1, "Hearts");
else
deck[count] = new Card(10, "Hearts");
}
else if (count < 26)
{
if (count == 13)
deck[count] = new Card(A, "Diamonds");
else if (count > 13 && count < 22)
deck[count] = new Card(count % 12, "Diamonds");
else
deck[count] = new Card(10, "Diamonds");
}
else if (count < 39)
{
if (count == 26)
deck[count] = new Card(A, "Spades");
else if (count > 26 && count < 35)
deck[count] = new Card(count % 25, "Spades");
else
deck[count] = new Card(10, "Spades");
}
else if (count < 52)
{
if (count == 39)
deck[count] = new Card(A, "Clubs");
else if (count > 39 && count < 48)
deck[count] = new Card(count % 38, "Clubs");
else
deck[count] = new Card(10, "Clubs");
}
}
The problem is, Jack, Queen and King all have a value of 10, but they need to be displayed as different cards (I have the above loop set up so that there are simply 3 cards with a value of 10 created (excluding the numerical 10)). I can't tell the toString method of the Card class to check whether the card's value is 10 and display J, Q, or K for this reason. I also can't reference the deck in the Card class and reference these problem cards by their array indices. Any ideas?
- 01-15-2012, 07:32 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Need help...blackjack not working.
By g2mediagroup in forum New To JavaReplies: 5Last Post: 05-03-2011, 06:40 AM -
Creating a game of blackjack
By adjit in forum New To JavaReplies: 3Last Post: 04-29-2011, 02:14 PM -
Help With BlackJack Game !
By TangoMango in forum New To JavaReplies: 1Last Post: 01-24-2011, 05:40 PM -
blackjack help
By jordaejava in forum New To JavaReplies: 1Last Post: 12-11-2009, 05:44 AM -
Need ideas and help for a simple BlackJack Game
By Dannii in forum New To JavaReplies: 5Last Post: 04-27-2009, 10:53 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks