Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vsa.game.framework.impl;
- import vsa.game.framework.Action;
- import vsa.game.framework.Configuration;
- import vsa.game.framework.Looper;
- import vsa.game.framework.State;
- import vsa.game.framework.StateDriver;
- public class StateManager<GameData> implements Looper
- {
- private boolean running = true;;
- private State<GameData> currentState;
- private Configuration<GameData> conf;
- private GameData context;
- public StateManager(Configuration<GameData> conf, GameData context)
- {
- this.conf = conf;
- this.context = context;
- }
- @Override
- public void runEventLoop()
- {
- currentState.initialize(conf, context);
- while (running)
- {
- if (!(transition(currentState)))
- {
- Action<GameData> a = conf.getActionSelector().selectAction(conf, currentState, context);
- a.execute(conf, context);
- transition(a);
- }
- }
- }
- private boolean transition(StateDriver<GameData> driver)
- {
- State<GameData> next = driver.getNextState();
- if (next != null)
- {
- currentState = next;
- currentState.initialize(conf, context);
- return true;
- }
- return false;
- }
- public void setStartState(State<GameData> state)
- {
- currentState = state;
- }
- @Override
- public void stopEventLoop()
- {
- running = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement