Help - Search - Members - Calendar
Full Version: Java Poker War Application Help
Zymic Webmaster Forums > General Discussion > Chatter Box
aussiemcgr
EDIT: Poker War -- Beta V2.0 download: http://www.mediafire.com/?13mymhudzwh
NOTE: Takes 10-20 seconds for program to load. Dont worry, it is just doing all the GUI loading so user doesnt have to suffer through lag during gameplay. Full Houses and 2 Pairs still do not work. Still only single suit.
Changes:
1. Fixed Program Crash Bugs
2. Fixed Program Frame Title
3. Greatly Updated Graphics

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


I'm writing a card game my friends and I sort of created called "Poker War" (you can probably guess how its played) using java, and I could use some help from people who know how to program.

The problem I am having is that I have no idea how to go about programming Full Houses and 2 Pairs. Below is a snippet of how I programmed the other hands so you can get an idea of my design.

CODE
class ...
{
ArrayList<Cards> hand;
ArrayList<Cards> selection;
boolean FOUROFKIND = false;
boolean FULLHOUSE = false;
boolean STRAIGHT = false;
boolean THREEOFKIND = false;
boolean TWOPAIR = false;
boolean ONEPAIR = false;
boolean userChance;
int value = 0;

public ...(...)
{

isOnePair();

if(...)
{...}
else if(ONEPAIR)
        {
            selection = isOnePair();
            value = 1;
        }    
        else
        {
            ArrayList<Cards> c = new ArrayList<Cards>();
            c.add(hand.remove(hand.size()-1));
            selection = c;
            value = 0;
        }
}

public ArrayList<Cards> isFourOfKind()
    {
        ArrayList<Cards> play = new ArrayList<Cards>();
        for(int i=hand.size()-1;i>2;i--)
        {
            int start = hand.get(i).getCardValue();
            if(start == hand.get(i-1).getCardValue() && start == hand.get(i-2).getCardValue() && start == hand.get(i-3).getCardValue())
            {
                if(FOUROFKIND)
                {
                    if(userChance)
                    {
                        play.add(hand.get(i));
                        play.add(hand.get(i-1));
                        play.add(hand.get(i-2));
                        play.add(hand.get(i-3));    

                    }
                    else
                    {
                        play.add(hand.remove(i));
                        play.add(hand.remove(i-1));
                        play.add(hand.remove(i-2));
                        play.add(hand.remove(i-3));
                    }
                }
                FOUROFKIND = true;
                return play;
            }
        }
        FOUROFKIND = false;
        return play;
    }
    
    public ArrayList<Cards> isFullHouse()
    {
        ArrayList<Cards> play = new ArrayList<Cards>();
        for(int i=hand.size()-1;i>3;i--)
        {
            //No Code
        }
        FULLHOUSE = false;
        return play;
    }
    
    public ArrayList<Cards> isStraight()
    {
        ArrayList<Cards> play = new ArrayList<Cards>();
        
        for(int i=hand.size()-1;i>3;i--)
        {
            int start = hand.get(i).getCardValue();
            if((hand.get(i-1).getCardValue() == start-1)&&(hand.get(i-2).getCardValue() == start-2)&&(hand.get(i-3).getCardValue() == start-3)&&(hand.get(i-4).getCardValue() == start-4))
            {
                if(STRAIGHT)
                {
                    if(userChance)
                    {
                        play.add(hand.get(i));
                        play.add(hand.get(i-1));
                        play.add(hand.get(i-2));
                        play.add(hand.get(i-3));
                        play.add(hand.get(i-4));    

                    }
                    else
                    {
                        play.add(hand.remove(i));
                        play.add(hand.remove(i-1));
                        play.add(hand.remove(i-2));
                        play.add(hand.remove(i-3));
                        play.add(hand.remove(i-4));
                    }
                }
                STRAIGHT = true;
                return play;
            }
        }
        STRAIGHT = false;
        return play;
    }
    
    public ArrayList<Cards> isThreeOfKind()
    {
        ArrayList<Cards> play = new ArrayList<Cards>();
        
        for(int i=hand.size()-1;i>1;i--)
        {
            int start = hand.get(i).getCardValue();
            if(start == hand.get(i-1).getCardValue() && start == hand.get(i-2).getCardValue())
            {
                if(THREEOFKIND)
                {
                    if(userChance)
                    {
                        play.add(hand.get(i));
                        play.add(hand.get(i-1));
                        play.add(hand.get(i-2));
                    }
                    else
                    {
                        play.add(hand.remove(i));
                        play.add(hand.remove(i-1));
                        play.add(hand.remove(i-2));
                    }
                }
                THREEOFKIND = true;
                return play;
            }
        }
        THREEOFKIND = false;
        return play;
    }
    
    public ArrayList<Cards> isTwoPairs()
    {
        ArrayList<Cards> play = new ArrayList<Cards>();
        for(int i=hand.size()-1;i>2;i--)
        {
            //No code
        }
        TWOPAIR = false;
        return play;
    }
    
    public ArrayList<Cards> isOnePair()
    {
        ArrayList<Cards> play = new ArrayList<Cards>();
        
        for(int i=hand.size()-1;i>0;i--)
        {
            if(hand.get(i).getCardValue() == hand.get(i-1).getCardValue())
            {
                if(ONEPAIR)
                {
                    if(userChance)
                    {
                        play.add(hand.get(i));
                        play.add(hand.get(i-1));
                    }
                    else
                    {
                        play.add(hand.remove(i));
                        play.add(hand.remove(i-1));
                    }
                    
                }    
                ONEPAIR = true;
                return play;
            }
        }
        ONEPAIR = false;
        return play;
    }
}


So with that snippet (yes, its not all the code in that file), is anyone able to help me program the final two hands in a similar fashion I have done with the others. Also, there is a little bit of additional code in each method to allow it to work correctly every time that I did not include in the above snippet.

And for those curious, it is 1 of 9 classes used to make my program work. The program is a total of around 884 lines. It contains several small bugs and one major bug that I plan on fixing alongside the addition of actual graphics (instead of my squares,colors,and numbers I have now), player history, and a more complex design (click and drag interface instead of current click and click interface) in Beta V2.0.

If you want to play around with it and give suggestions, you can find the download for Beta V1.0 (ignore the title at top of program) here: http://www.mediafire.com/?nomim0ndtte. Beta V1.0 is the product of about a total of 6 hours of programming in a span of a week and a half, so dont expect to be too impressed.

Cheers
aussiemcgr
All problems fixed...

Most updated version with all supported single-suit hands: http://www.mediafire.com/?23gwoo5xjy2

Now also includes gameplay instructions and update information.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.