I have a Battle class and a RightPanel class. What i'm lacking is the code to connect the two classes. Basically, what I want to do is to say, Okay select your weapon and then after clicking the button, I will set the piece's weapon and then the code will proceed to my if else statement, which I already finished.
public class Battle {
private MovePiece mpref;
//constructors
public Battle(MovePiece mpref){
this.mpref =mpref;
}
//the battle system
public Piece winner (Piece piecetwo, Piece pieceone){
while(pieceone.getRemlife()>0||piecetwo.getRemlife()>0){
//what i want to code is Click wind, fire or earth button then
pieceone.setAttack("wind");
//then...
if (pieceone.getAttack().equals("fire")){
if(piecetwo.getAttack().equals("wind")){
int life = piecetwo.getLife();
life=life-1;
piecetwo.setLife(life);
System.out.println("Player 1 wins");
}
else if(piecetwo.getAttack().equals("earth")){
int life = pieceone.getLife();
life=life-1;
pieceone.setLife(life);
System.out.println("Player 2 wins");
}
//and so forth
}
My Right Panel class which has all the buttons looks like this...
public class RightPanel extends JPanel {
public RightPanel(){
this.setPreferredSize(dimension);
this.setLayout(new GridBagLayout());
JLabel option = new JLabel("Choose your weapon: ");
gbc.gridx = 0;
gbc.gridy = 5;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 20, 0, 20);
wpanel.add(option, gbc);
//----Attack Buttons----//
JPanel wabuttons = new JPanel(new GridLayout(0, 3, 3, 3));
wabuttons.setEnabled(false);
gbc.gridx = 0;
gbc.gridy = 6;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 20, 10, 20);
wpanel.add(wabuttons, gbc);
//Wind
ImageIcon icnWind = new ImageIcon(imageFolderPath + "button/wind.png");
Image imgWind = icnWater.getImage() ;
Image newWind = imgWater.getScaledInstance(25, 25, SCALE_SMOOTH ) ;
icnWind = new ImageIcon(newWind);
btnWind = new JButton("",icnWind);
btnWind.setEnabled(false);
btnWind.setForeground(Color.BLUE);
btnWind.setFont(new Font("Lucida Sans Unicode", Font.ITALIC, 15));
btnWind.addActionListener(new actWind());
wabuttons.add(btnWind);
//Fire//
ImageIcon icnFire = new ImageIcon(imageFolderPath + "button/fire.png");
Image imgFire = icnFire.getImage() ;
Image newFire = imgFire.getScaledInstance(25, 25, SCALE_SMOOTH ) ;
icnFire = new ImageIcon(newFire);
btnFire = new JButton("",icnFire);
btnFire.setEnabled(false);
btnFire.setForeground(Color.RED);
btnFire.setFont(new Font("Lucida Sans Unicode", Font.ITALIC, 15));
btnFire.addActionListener(new actFire());
wabuttons.add(btnFire);
//Earth//
ImageIcon icnEarth = new ImageIcon(imageFolderPath + "button/earth.png");
Image imgEarth = icnEarth.getImage() ;
Image newEarth = imgEarth.getScaledInstance(25, 25, SCALE_SMOOTH ) ;
icnEarth = new ImageIcon(newEarth);
btnEarth = new JButton("",icnEarth);
btnEarth.setEnabled(false);
btnEarth.setForeground(Color.GREEN);
btnEarth.setFont(new Font("Lucida Sans Unicode", Font.ITALIC, 15));
btnEarth.addActionListener(new actEarth());
wabuttons.add(btnEarth);
}
class actWind implements ActionListener {
public void actionPerformed (ActionEvent e) {
}
class actFire implements ActionListener {
public void actionPerformed (ActionEvent e) {
}
class actEarth implements ActionListener {
public void actionPerformed (ActionEvent e) {
}
}