This site requires JavaScript, please enable it in your browser!
Greenfoot back
1920
1920 wrote ...

2015/2/20

Help with Blackjack game

1920 1920

2015/2/20

#
Can anyone help me in implementing the world subclass in order to establish the rules of the game?
danpost danpost

2015/2/20

#
Write an outline of the events that are to take place. Then build your act method of the world based on that outline. Do not worry about what code needs to go in supporting methods for now. Just work on the act method calling methods that are to do certain actions. For example:
public void act()
{
    if (phase == 0 /** new hand */)
    {
        // initialize phase 1 (initialize fields and reset/shuffle deck if needed)
        phase = 1;
    }
    if (phase == 1 /** dealing */)
    {
        dealACard();
        if (dealingComplete()) 
        {
            // initialize phase 2 (initialize fields)
            phase = 2;
        }
    }
    if (phase == 2 /** players play*/)
    {
        if (hitDetected())
        {
            dealACard();
        }
        if (player.isBusted() || player.isStaying()) nextPlayer(); // change phase in 'nextPlayer' if no more players
    }
    if (phase == 3 /** dealer plays */)
    {
        dealACard();
        if (seventeenPlus) phase = 4;
    }
    if (phase == 4 /** showdown */)
    {
        if (dealer.isBusted()) allWin();
        else
        {
            for each player
            {
                if ( ! player.isBusted() && dealer.getHandValue() < player.getHandValue()) playerWins();
            }
        }
        phase = -1;
    }
    if (phase == -1 /** end hand */ && resetRequested()) phase = 0;
}
This is just a brief summary of how I would start out and is no where near to being complete code. I am only showing this as a technique that you can follow.
You need to login to post a reply.