我需要帮助将伪代码转换为 Java(状态机示例)

I require assistance for converting pseudo code to Java (State machine examples)

你好,我正在写这篇文章是因为我已经尝试将下面的伪代码转换为 java 大约 2 天的格式。我试图转换的代码来自这篇精彩的文章:

http://gamedevelopment.tutsplus.com/articles/how-to-build-a-jrpg-a-primer-for-game-developers--gamedev-6676

密码是

class StateMachine

Map<String, IState> mStates = new Map<String, IState>();
IState mCurrentState = EmptyState;

public void Update(float elapsedTime)
{
    mCurrentState.Update(elapsedTime);
}

public void Render()
{
    mCurrentState.Render();
}

public void Change(String stateName, optional var params)
{
    mCurrentState.OnExit();
    mCurrentState = mStates[stateName];
    mCurrentState.OnEnter(params);
}

public void Add(String name, IState state)
{
    mStates[name] = state;
}

和这个代码

public class StateStack

Map<String, IState> mStates = new Map<String, IState>();
List<IState> mStack = List<IState>();

public void Update(float elapsedTime)
{
    IState top = mStack.Top()
    top.Update(elapsedTime)
}

public void Render()
{
    IState top = mStack.Top()
    top.Render()
}

public void Push(String name)
{
    IState state = mStates[name];
    mStack.Push(state);
}

public IState Pop()
{
    return mStack.Pop();
}

我不介意有人给我最终结果或者有人指导我正确的方向。我只想解决这个XD

额外位

  StateMachine gGameMode = new StateMachine();

// A state for each game mode
gGameMode.Add("mainmenu",   new MainMenuState(gGameMode));
gGameMode.Add("localmap",   new LocalMapState(gGameMode));
gGameMode.Add("worldmap",   new WorldMapState(gGameMode));
gGameMode.Add("battle",     new BattleState(gGameMode));
gGameMode.Add("ingamemenu", new InGameMenuState(gGameMode));

gGameMode.Change("mainmenu");

// Main Game Update Loop
public void Update()
{
    float elapsedTime = GetElapsedFrameTime();
    gGameMode.Update(elapsedTime);
    gGameMode.Render();
}

额外位结束

如果你能指导我,那对我也会有帮助:P

-再次感谢

这基本上是 Java,您只需将代码放入适当的 .java 文件并编写构造函数即可。

public class StateMachine(){
  public StateMachine(){
        
  }
}

问题是您没有任何 MainMenuState 的代码...类