2012-02-25 254 views
0

我很難看出爲什麼一種方式的作品和方式沒有。switch語句中的if語句?

我有;

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; 
      } 

對於M和E,即使mGameOverLabel在這個當前時間設置爲false的情況下,我仍然可以按M和E和這些將根據方法反應,但如果我將其更改爲這對M來說,它只會在我需要它的時候才起作用。我在這裏錯過了什麼?

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

      case 'm': case 'M': 
       if(mGameOverLabel->GetVisible()) ResetScreen(); 
       break; 
      } 
+0

在swicth語句之前,你能做到嗎? – Andrew 2012-02-25 17:01:00

+1

@安德魯:什麼? – Ryan 2012-02-25 17:02:23

回答

7

switch基本上沒有一個goto到適當的情況下的標籤。高於case的任何邏輯都不會被執行。

+0

啊,那會解釋一切!謝謝! – r0bb077 2012-02-25 17:16:46