• Log in or sign up for an account here: https://www.sythe.org/login

Blackjack Program Scoring Help?

Joined
Jul 17, 2008
Sythe Gold
0
Messages
455
I simply need help on how to make my scoring system work. I thought it would work, but I'm not sure how to retrieve it from my deck class. Do I used score.setText (???[getValue])?.......
Please don't criticize the way I made this program, I'm novice, & yes, I know arrays would have helped. I'm not going into inheritance yet either.

BLKJK
import javax.swing.ImageIcon;

public class blkjack extends JFrame implements ActionListener
{
private int numArray;
private JLabel score;//score player 2
private JLabel score2;//score player 1
private JLabel backGround;//background blackjack table
private JLabel card1;//first card
private JLabel card2;//second card
private JLabel card3;//third card
private JLabel card4;//fourth card
private JLabel card5;//fifth card
private JLabel card6;//dealers card
private JLabel card7;//dealers card
private JLabel card8;//dealers card
private JLabel card9;//dealers card
private JLabel card10;//dealers card
private JLabel hand1;//decoration
private JLabel hand2;//decoration
private JLabel hand3;//decoration
private JLabel hand4;//decoration
private JLabel hand5;//decoration
private int x = 1;//x = 1 for the hit button calculations working only 3 hits, then disabling completely
private int z = 0;//ignore for now
private int a = 0;//ignore for now
private JButton NewGame;//Starts up game... New Game, duh.
private JButton Stay;//stay
private JButton Deal;//deal
private JButton Hit;//hit
private Card card = new Card();
public Deck deck = new Deck(); //kunwoo told me this part and how it pulls info from the other files



public blkjack()
{

Container contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.setBackground(Color.green);

setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Super Title");
setSize(650,725);
setResizable(false);
setLocation(200,100);

//score p2
score = new JLabel("You: ");
score.setBounds(5,5,80,25);
score.setBorder(BorderFactory.createLineBorder(Color.black));
contentPane.add(score);

//score p1
score2 = new JLabel("Dealer: ");
score2.setBounds(5,30,80,25);
score2.setBorder(BorderFactory.createLineBorder(Color.black));
contentPane.add(score2);

//YOUR HAND
card1 = new JLabel("");
card1.setBounds(128,340,74,100);
card1.setIcon(new ImageIcon(""));
card1.setBorder(BorderFactory.createLineBorder(Color.yellow));
contentPane.add(card1);

//YOUR HAND
card2 = new JLabel("");
card2.setBounds(205,340,74,100);
card2.setIcon(new ImageIcon(""));
card2.setBorder(BorderFactory.createLineBorder(Color.yellow));
contentPane.add(card2);

//etc etc all of this is just the graphic user interface pane set up
// any name "hand1(2, 3, 4, 5).blahblah" is just for decoration
//card is used for the ACTUAL playing card.


}

public static void main(String args[])
{
blkjack frame = new blkjack();//BLKJACK FILE
frame.setVisible(true);//VISIBLE
}

public void actionPerformed(ActionEvent e)//ACTION PERFORMED
{

if(e.getSource() instanceof JButton)//SAME AS BELOW
{

JButton clicked = (JButton)e.getSource();//JBUTTON INSTANCE OF


if(clicked == NewGame)//will set up the button to lock all buttons except deal to prevent cheating
{
backGround.setIcon(new ImageIcon("E:\\blkjack\\blackjackback2.PNG"));//BACKGROUND
card1.setIcon(new ImageIcon(""));//EMPTY
card2.setIcon(new ImageIcon(""));//EMPTY
card3.setIcon(new ImageIcon(""));//EMPTY
card4.setIcon(new ImageIcon(""));//EMPTY
card5.setIcon(new ImageIcon(""));//EMPTY
hand1.setIcon(new ImageIcon(""));//EMPTY
hand2.setIcon(new ImageIcon(""));//EMPTY
hand3.setIcon(new ImageIcon(""));//EMPTY
hand4.setIcon(new ImageIcon(""));//EMPTY
hand5.setIcon(new ImageIcon(""));//EMPTY
card6.setIcon(new ImageIcon(""));//EMPTY
card7.setIcon(new ImageIcon(""));//EMPTY
card8.setIcon(new ImageIcon(""));//EMPTY
card9.setIcon(new ImageIcon(""));//EMPTY
card10.setIcon(new ImageIcon(""));//EMPTY
Stay.setEnabled(false);//lock
Hit.setEnabled(false);//locks also
Deal.setEnabled(true);//keeps unblock
x=1;
}


else if(clicked == Deal)//DEAL BUTTON
{
for(z = 0; z <= 7; z++)//please ignore this variable....................
{

card1.setIcon(new ImageIcon(deck.getNextCard().getImage()));//CARD IMAGE
card2.setIcon(new ImageIcon(deck.getNextCard().getImage()));//CARD IMAGE
hand1.setIcon(new ImageIcon("E:\\blkjack\\CardDocs\\untitled.PNG"));//BACK
hand2.setIcon(new ImageIcon("E:\\blkjack\\CardDocs\\untitled.PNG"));//BACK
hand3.setIcon(new ImageIcon("E:\\blkjack\\CardDocs\\untitled.PNG"));//BACK
hand4.setIcon(new ImageIcon("E:\\blkjack\\CardDocs\\untitled.PNG"));//BACK
hand5.setIcon(new ImageIcon("E:\\blkjack\\CardDocs\\untitled.PNG"));//BACK
card6.setIcon(new ImageIcon("E:\\blkjack\\CardDocs\\untitled.PNG"));//CARD IMAGE
card7.setIcon(new ImageIcon(deck.getNextCard().getImage()));//CARD IMAGE

}
Deal.setEnabled(false);
Hit.setEnabled(true);
Stay.setEnabled(true);
}


else if(clicked == Hit)//IF HIT IS CLICKED
{

if(x < 2)
{
hand1.setIcon(new ImageIcon(""));//NO IMAGE
card3.setIcon(new ImageIcon(deck.getNextCard().getImage()));//CLUB IMAGE
x++;//ONE MORE INT HIGHER
}
else if(x < 3)//SECOND CLICK
{
hand2.setIcon(new ImageIcon(""));//NO IMAGE
card4.setIcon(new ImageIcon(deck.getNextCard().getImage()));//CLUB IMAGE
x++;//ONE MORE INT HIGHER
}
else if(x < 4)//THIRD CLICK
{
hand3.setIcon(new ImageIcon(""));//NO IMAGE
card5.setIcon(new ImageIcon(deck.getNextCard().getImage()));//CLUB IMAGE
Hit.setEnabled(false);//locks for third click
}
}

else if(clicked == Stay)
{
card6.setIcon(new ImageIcon(deck.getNextCard().getImage()));//OPPONENT'S CARD/HAND KUNWOO HELPED ME ON THIS PART TOO AND EXPLAINED WHY THIS WORKS
card8.setIcon(new ImageIcon(deck.getNextCard().getImage()));
card9.setIcon(new ImageIcon(deck.getNextCard().getImage()));
card10.setIcon(new ImageIcon(deck.getNextCard().getImage()));
Stay.setEnabled(false);//locks stay button
Hit.setEnabled(false);

}


}
}
}

DECK CLSS
import java.util.Random;

public class Deck
{
private Card[] deck;
private int location;
private Random rand;
public Deck()
{
rand = new Random();
deck = new Card[52];
location = 0;

int i = 0;
while(i<52)
{
for (int j = 1; j < 14; j++)
{
Card temp = new Card();
temp.setValue(j);
temp.setImage("E:\\blkjack\\CardDocs\\" + i + ".PNG");//0.jpg[ace spades], 13.jpg[ace hearts]
deck = temp;
i++;

}
}

shuffle();
}
public void shuffle()
{


}

public Card getNextCard()
{
Card tempCard = new Card();
if (location < 52)
{
tempCard = deck[location];
location++;
}

return tempCard;

}

}



CARD CLSS
public class Card
{
private int value;
private String image;
private boolean shuffled;

public Card()
{
value = 0;
image = "";
shuffled = false;
}
public void setValue(int value)
{
this.value = value;
}

public int getValue()
{
return value;
}

public void setImage(String image)
{
this.image = image;
}

public String getImage()
{
return image;
}

public boolean beenShuffled()
{
return shuffled;
}

public void shuffled(boolean status)
{
shuffled = status;
}

}
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
Can you explain the issue a bit more? What value are you attempting to get and do what with it?
 
I really don't want to look through all that...what is your problem here? This is a player vs. player program right? If so, a blackjack program should be pretty simple...what exactly are you trying to score? If it's scoring of each hand then the lowest sum wins...if you're trying to score the overall game then you have to create your own scoring system seeing as there is no betting...

Anyways, I'm having a lot of trouble reading your code as it has poor OOP imo...there's no way your main should be that long for something so simple.
 
Do you mean how do you try and keep track of your score? I've made a couple of simple games and I usually just make a panel class called Score and make some fields and methods in there to put the scores on labels and such, then add them into the main panel. Like if you're using a border layout, my score panel is usually on the north or west. Hope this helped.
 
duelarena.gg
Back
Top