-6

I'm pretty new in programming, but i need to program the game Minesweeper. basically the game is running, but there are some parts that wont work at all.

The first problem are the flags. My Minesweeper is able to set flag by right clicking on a field, but everytime i do a left-click on a field with a flag, the field will override the flag.

Field after a right click Flagged field after a left click
Is there any way to set the flag "absolute" or final or something? Here is the code:

@Override
public void mouseClicked(MouseEvent arg0) {
    if (SwingUtilities.isRightMouseButton(arg0)) {

        setFlag();

    } else if (SwingUtilities.isLeftMouseButton(arg0)) {

        checkMine();

    }

public void setFlag() {

    button.setEnabled(false);
    button.setText(flag);
    button.setBackground(Color.LIGHT_GRAY);

}

public void checkMine() {

    button.setEnabled(false);
    display();
    check = false;
    if (value == 0)
        log.emptyCells();

    if (value == -1)
        log.fail();

    if (value == -3)
        log.lucky();

}

I hope that someone here can help me.

tanks :)

1 Answers1

0

When you are using methods with button, you are never specifying which button you are disabling. I recommend adding a JButton parameter to your methods so you can change them.

Also, the check boolean is never initialized as a boolean, unless it's an instance variable you are using, in which case you need to edit your post to include your instance variables.

SamelCamel
  • 67
  • 2
  • 9