Sorry, don't have the time to do much on this, but start with a Card class (52 instances!) and a Player class (that holds a list of the Cards that the player holds, the player's current cash and bet, and has the logic for stick/twist etc). Maybe a Dealer class that has the logic to "deal" Cards to Players and perform it's own versions of the stick/twist logic, and compute payouts (subclass Player to avoid duplication).
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Normally the idea on this forum is to not do things via PM since the goal is to make everything public, so you'll probably get a better response if you post the rules of the game on the thread.
I imagine you'll need a function to shuffle cards though, probably a function in the Deck class. I have a couple of code snippets in the C++ section dealing with that:
http://www.daniweb.com/code/snippet1019.html
http://www.daniweb.com/code/snippet1034.html
The first one is probably useless for Java since it involves pointers, but the second may come in handy and could be transformed into Java fairly easily.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
When I programmed Blackjack I used an ArrayList to hold all my cards. To shuffle I simply had a for loop run about 1000 times, randomly picking a number 0-51, removing the object at that spot while at the same time adding it to the end. Just another idea for a shuffle 'algorithm'. I wouldn't use this with a lot of elements but with 52 it works well.
public void shuffle(){
for(int i=0;i<1000;i++){
int rand = (int)(Math.random()*50)+1;
deck.add(deck.remove(rand));
}
}
It took about 0.003169118 seconds to shuffle.
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
Iv uploaded the code so far on rapidshare if you could just download it and check it out that would be greatly appreciated, it dont seem to compile...
You need to post the section of code that is giving you trouble here, not the whole thing, only where you are getting an error (don't forget to tell us what error/exception you are getting.) A great skill to have is the ability to go through your code and figure out why "it don't seem to compile", if you ask for help every time the answer doesn't dance around naked in front of your face, you'll never develop that skill.
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
import java.util.*;
import java.util.Collection.*;
class DeckOfCards
{
private ArrayList<Card> card = new ArrayList<card>();
public DeckOfCards()
{
for(int i=0; i < 52; i++)
{
if(i < 13)
card.add(new Card(i%13+1,'S'));
else
if(i < 26)
card.add(new Card(i%13+1, 'H'));
else
if(i < 39)
card.add(new Card(i%13+1, 'D'));
else
card.add(new Card(i%13+1, 'C'));
}
}
public void shuffle()
{
Collection.shuffle(card);
}
public Card pickNextCard()
{
return card.remove(0);
}
}
class Card
{
private int rank;
private char suit;
public int getRank()
{
return(rank);
}
public int getSuit()
{
return(suit);
}
public Card(int r, char s)
{
rank = r;
suit = s;
}
public boolean equals(Card otherCard)
{
if((rank == otherCard.rank) && (suit == otherCard.suit))
return(true);
else
return(false);
}
}
Since these are in separate files, try putting the word "public" at the top next to the name of the class. I would think that you would get some other errors besides just the one you listed, but stick the word "public" in front of the word "class" in your java files and see if the errors go away.
[Edit]
Note: Java is case sensitive:
private ArrayList<Card> card = new ArrayList<card>();
Red above should be capitalized.
[/Edit]
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711