0

所以我需要 ac#if()语句,它应该看起来像这样,也许?代码:

...
if(CurrentGameState != gameState.gameLoading && gameState.mainMenu && keyboardState.IsKeyDown(Keys.Escape))
{
      CurrentGameState = gameState.mainmenu;

}
//I get error in: CurrentGameState != gameState.gameLoading && gameState.mainMenu part
...

这就是我使用上述变量的代码:

    //Game States
    enum gameState
    {
        gameLoading,
        mainMenu,
        gameOptions,
        levelSelect,
        gamePlaying,
        gameOver
    }
    gameState CurrentGameState = gameState.gameLoading;
    //Keyboard State
    KeyboardState keyboardState = Keyboard.GetState();

有什么建议么?

4

3 回答 3

4

gameState.mainMenu是枚举值,而不是布尔值。你不能以你想要的方式使用它。你的意思是这样做吗?

if (CurrentGameState != gameState.gameLoading && 
    CurrentGameState != gameState.mainMenu &&
    keyboardState.IsKeyDown(Keys.Escape))
于 2013-08-16T16:36:20.693 回答
1

我很抱歉格式化但用我的手机写,但我认为你使用 xna,你应该在 switch 语句中拥有你的游戏状态,否则你的代码会很快变得混乱并且效率低下

 Switch(currentgamestate)
 {
      Case gamestate.loading:
          If(pressing escape)
              Currentgamestate = gamestate.mainmenu;
       Break;
       Case gamestate.mainmenu;
            //todo
        Break;
   }

您的错误是因为您试图将两个条件链接在一起..如果 currentgamestate 没有加载并且是主菜单,您需要为每个条件引用当前游戏状态.. 如果 currentgamestate 没有加载并且 currentgamestate 是 mainmenu

于 2013-08-16T16:47:56.840 回答
0
if(CurrentGameState != gameState.gameLoading 
   && gameState.mainMenu && keyboardState.IsKeyDown(Keys.Escape))

或许

if(CurrentGameState != gameState.gameLoading && 
   CurrentGameState==gameState.mainMenu && keyboardState.IsKeyDown(Keys.Escape))
于 2013-08-16T16:36:43.397 回答