The game starts off by distributing 4 cards for the deck such a way that the player receives the card first, then the dealer..and so on.

round 1.
the program will display the first two cards of the player and dealer
the first card of the dealer faced down and dealer and compare player's and dealer's second card.
if the dealer second card > player second card. the dealer will make a random bet.
if the player second card > dealer second card. the player will decide a bet.
move on to round 2.

round 2.
the program will display the first three cards of the player and dealer
the first card of the dealer faced down and compare player's and dealer's third card.
if the dealer third card > player third card. the dealer will make a random bet.
if the player third card > dealer third card. the player will decide a bet.
move on to round 3.

round 3.
the program will display the first four cards of the player and dealer
the first card of the dealer faced down and compare player's and dealer's fourth card.
if the dealer fourth card > player fourth card. the dealer will make a random bet.
if the player fourth card > dealer fourth card. the player will decide a bet.
move on to round 3.

round 4.
the program will will display all five cards of the player and dealer compare player's and dealer's fifth card.
the first card of the dealer faced down.
if the dealer fifth card > player fifth card. the dealer will make a random bet.
if the player fifth card > dealer fifth card. the player will decide a bet.
the first card of the dealer is revealed.
the winner will be the one who has the highest points of the 5 cards.

I just need to know how to code it such a way that the program will wait for the dealer or the player
to bet first before moving on to the next round.

part of my codes on how I display the UI. the problem with my codes is, it will just
display all 5 dealer's and player's cards without waiting to bet first before moving on to the next round.

final random r = new random();
ArrayList<String> cardType = new ArrayList<String>();
final ArrayList<card> cards = new ArrayList<card>();
String newCard = " ";
JTextField tf = new JTextField(7);
JButton btn = new JButton("Bet");
final JPanel playerPanel = new JPanel();
final JPanel dealerPanel = new JPanel();

//random 10 cards.
while (cardType.size() < 10 ) {      
        cardSuits randomSuits = cardSuits.getRandomSuits();
        cardRank randomRank = cardRank.getRandomCardRank();
        newCard = randomSuits.name() + randomRank.name();

        if (!cardType.contains(newCard))
        {       
            cardType.add(newCard);
            cards.add(new card(randomSuits,randomRank));
        }
    }

    int i = 0;
    for(int k = 0; k < 4; k++) {
        playerPanel.removeAll();
        dealerPanel.removeAll();
        playerPanel.updateUI();
        dealerPanel.updateUI();
        for(i = 0; i < (k+2)*2; i++) {
            System.out.println(i);
            if(i%2 == 0) {
                JLabel playerHand = new JLabel(new ImageIcon(r.getImage(cards.get(i).toString(),i)));
                playerPanel.add(playerHand);
            }
            else {
                JLabel dealerHand = new JLabel(new ImageIcon(r.getImage(cards.get(i).toString(),i)));
                dealerPanel.add(dealerHand);
            }
        }

        if((cards.get(i-2).getCardRank().ordinal() < cards.get(i-1).getCardRank().ordinal()) || (cards.get(i-2).getCardRank().ordinal() == cards.get(i-1).getCardRank().ordinal() && cards.get(i-2).getCardSuit().ordinal() < cards.get(i-1).getCardSuit().ordinal())) {
            System.out.println(r.dealerRandomBet());                
        }
        else {
            betPanel.add(tf);
            betPanel.add(btn);
        }
    }

    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            betPanel.removeAll();
            betPanel.updateUI();
        }
    });

please help if possible thanks

Recommended Answers

All 4 Replies

What exactly do you want to happen in the user interface (as seen from the user's viewpoint). Eg in round 1 if the dealer makes a bet exactly what do you hope to see happening on the screen?

after the dealer makes a bet, the user will see the first three cards of the dealer and player at round 2. Initially it will 2 cards at round 1.

... and if the dealer gets to make the next bet...?

one solution is to have a "next..." button that the user has to press each time before the system moves on to the next step

In short, your program structure is that you have an action listener for the next button. Each time time that runs it checks which stage you are at, and does whatever is appropriate to move on to the next step.

right. thanks for your suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.