Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package vsa.game.framework.impl;
  2.  
  3. import vsa.game.framework.Action;
  4. import vsa.game.framework.Configuration;
  5. import vsa.game.framework.Looper;
  6. import vsa.game.framework.State;
  7. import vsa.game.framework.StateDriver;
  8.  
  9. public class StateManager<GameData> implements Looper
  10. {
  11. private boolean running = true;;
  12. private State<GameData> currentState;
  13. private Configuration<GameData> conf;
  14. private GameData context;
  15.  
  16. public StateManager(Configuration<GameData> conf, GameData context)
  17. {
  18. this.conf = conf;
  19. this.context = context;
  20. }
  21.  
  22. @Override
  23. public void runEventLoop()
  24. {
  25. currentState.initialize(conf, context);
  26. while (running)
  27. {
  28. if (!(transition(currentState)))
  29. {
  30. Action<GameData> a = conf.getActionSelector().selectAction(conf, currentState, context);
  31. a.execute(conf, context);
  32. transition(a);
  33. }
  34. }
  35. }
  36.  
  37. private boolean transition(StateDriver<GameData> driver)
  38. {
  39. State<GameData> next = driver.getNextState();
  40. if (next != null)
  41. {
  42. currentState = next;
  43. currentState.initialize(conf, context);
  44. return true;
  45. }
  46. return false;
  47. }
  48.  
  49. public void setStartState(State<GameData> state)
  50. {
  51. currentState = state;
  52. }
  53.  
  54. @Override
  55. public void stopEventLoop()
  56. {
  57. running = false;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement