/**
 * All the states in the game.
 */
public enum State {
    START_MENU,
    PLAYER_ONE_MENU,
    PLAYER_ONE_CATEGORY,
    PLAYER_TWO_MENU,
    PLAYER_TWO_CATEGORY,
    WIN_SCREEN,
    LOSE_SCREEN,
    PLAY_SCREEN
}这是我为我正在设计的绞刑者游戏制作的枚举。然而,我对枚举是个新手,但是有人建议我使用枚举来表示游戏状态。然而,我不知道如何跟踪播放器当前所处的状态。有人能解释一下跟踪哪个状态被选中的方法吗?
发布于 2013-03-08 13:30:46
只需保留当前状态的States类型的变量即可。
class Player {
 States currentState=States.STARTMENU;
 void doSomething() {
  switch (currentState) {
   case STARTMENU:...;
   case PLAYERONEMENU:...;
   //etc
  }
 }
 void playMenu() {
  if (currentState==States.PLAYMENU) {...}
 }
}https://stackoverflow.com/questions/15287334
复制相似问题