MenuButton.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package pathgame.gameplay.menu;
  2. import java.util.function.BiConsumer;
  3. import java.util.function.Consumer;
  4. import pathgame.gameplay.Gamestate;
  5. import pathgame.gameplay.Level;
  6. /**
  7. * A container for holding everything about a menu button
  8. *
  9. * @author julia
  10. */
  11. public class MenuButton
  12. {
  13. private final String name;
  14. private final BiConsumer<Gamestate, Level> r;
  15. /**
  16. * Contructor initializing a menu button
  17. *
  18. * @param name the name of the button to be shown to the player
  19. * @param r function that is executed when pressed on the button
  20. */
  21. public MenuButton(String name, BiConsumer<Gamestate, Level> r)
  22. {
  23. this.name = name;
  24. this.r = r;
  25. }
  26. /**
  27. * Contructor initializing a menu button
  28. *
  29. * @param name the name of the button to be shown to the player
  30. * @param r function that is executed when pressed on the button
  31. */
  32. public MenuButton(String name, Consumer<Gamestate> r)
  33. {
  34. this(name, (gamestate, level) -> r.accept(gamestate));
  35. }
  36. /**
  37. * Returns the name of the button
  38. *
  39. * @return the name of the button
  40. */
  41. public String getName()
  42. {
  43. return name;
  44. }
  45. /**
  46. * runs the button function
  47. *
  48. * @param gamestate the gamestate
  49. * @param level the current level
  50. */
  51. public void run(Gamestate gamestate, Level level)
  52. {
  53. r.accept(gamestate, level);
  54. }
  55. }