CharacterMenu.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package pathgame.gameplay.menu;
  2. import pathgame.gameplay.Gamestates;
  3. import pathgame.gameplay.PlayerAbilities;
  4. /**
  5. * A container for holding all options of the CharacterMenu
  6. *
  7. * @author julia
  8. */
  9. public class CharacterMenu extends BaseMenu
  10. {
  11. private final MenuButton[] options;
  12. /**
  13. * Contructor generating and initializing the CharacterMenu
  14. *
  15. * @param id the id of the CharacterMenu
  16. * @param mainId the id to the MainMenu
  17. */
  18. public CharacterMenu(int id, int mainId)
  19. {
  20. super(id);
  21. options = new MenuButton[PlayerAbilities.ABILITIES.length + 1];
  22. for(int i = 0; i < options.length - 1; ++i)
  23. {
  24. options[i] = getAbilityOption(PlayerAbilities.ABILITIES[i]);
  25. }
  26. options[options.length - 1] = new MenuButton("Back", (gamestate) ->
  27. {
  28. setReturnId(mainId);
  29. });
  30. }
  31. private static MenuButton getAbilityOption(PlayerAbilities pa)
  32. {
  33. return new MenuButton(pa.getName(), (gamestate, level) ->
  34. {
  35. level.reset();
  36. level.getPlayer().setAbilities(pa);
  37. gamestate.setState(Gamestates.GAMEPLAY);
  38. });
  39. }
  40. /**
  41. * Returns the options of the CharacterMenu
  42. *
  43. * @return the options of the CharacterMenu
  44. */
  45. @Override
  46. public MenuButton[] getOptions()
  47. {
  48. return options;
  49. }
  50. }