0

I'm having difficulties seeing why one way works and way doesn't.

I have;

switch (key)
        {
            //If Game over Label is visible, enable the m and e buttons
            if(mGameOverLabel->GetVisible())
            {
                case 'm': case 'M':
                    ResetScreen();
                    break;

                case 'e': case 'E':
                //  //Exit the game
                    Stop();
                    break;
            } else {

                case ' ':
                    mSpaceship->Shoot();
                    break;

                default:
                    break;
            }

For the case of the m and e, even though mGameOverLabel is set to false at this current time, I can still press M and E and these will react according to the methods, but If I change it to this for M it will then only work when I need it too. Am I missing something here?!

switch (key)
        {
            //If Game over Label is visible, enable the m and e buttons

            case 'm': case 'M':
                if(mGameOverLabel->GetVisible()) ResetScreen();
                break;
            }   
1
  • Can you do you before swicth statement? Commented Feb 25, 2012 at 17:01

1 Answer 1

7

The switch basically does a goto to the appropriate case label. Any logic above the case will not be executed.

Sign up to request clarification or add additional context in comments.

1 Comment

ah, that would explain all! Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.