vendredi 14 juin 2019

Can't get JFrame message to pop up under certain circumstances

I created a method for getting silver in my game. The message pops up when it is suppose to except under these circumstances: All score buttons have been clicked except for one, when that last score button is clicked and you answer incorrectly and still have at least 1 life left, no message will pop up. I don't know why it does not work, I thought I programmed an if statement that would detect a silver win there but it does not.

So my if statement is if you have 0 lives left or all buttons are disabled and an answer button has been pressed and you have greater than or equal to 2200 and less than 3000 points, pop up the silver message. The method is pasted in all of the button handlers. If it makes it easier to understand, here is a legend for the variables: lives = the amount of lives the user has left, dis = whether or not a score button is disabled (to make the code easier to understand, I only put one variable for dis but in the actual code, each score button has a dis), pressed: whether or not a answer button has been pressed (to make the code easier to understand, I only put one variable for pressed but in the actual code, each answer button has a pressed), score = the score the user has (how many points they have.

public static void CheckAnswer ()
{
    if (((lives == 0) || ((dis == true) && (pressed = true))) && ((score >= 2200) && (score < 3000)))
    {
        frame3.setVisible (true);
        resultsMessage.setText ("Congratulations, you won silver!");
    }
}

So the message is suppose to pop up when all score buttons have been clicked except for one, when that last score button is clicked and you answer incorrectly and still have at least 1 life left but it does not. All help is appreciated. Thank you.

Aucun commentaire:

Enregistrer un commentaire