12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package pathgame.gameplay.menu;
- import java.util.function.BiConsumer;
- import java.util.function.Consumer;
- import pathgame.gameplay.Gamestate;
- import pathgame.gameplay.Level;
- /**
- * A container for holding everything about a menu button
- *
- * @author julia
- */
- public class MenuButton
- {
- private final String name;
- private final BiConsumer<Gamestate, Level> r;
- /**
- * Contructor initializing a menu button
- *
- * @param name the name of the button to be shown to the player
- * @param r function that is executed when pressed on the button
- */
- public MenuButton(String name, BiConsumer<Gamestate, Level> r)
- {
- this.name = name;
- this.r = r;
- }
- /**
- * Contructor initializing a menu button
- *
- * @param name the name of the button to be shown to the player
- * @param r function that is executed when pressed on the button
- */
- public MenuButton(String name, Consumer<Gamestate> r)
- {
- this(name, (gamestate, level) -> r.accept(gamestate));
- }
- /**
- * Returns the name of the button
- *
- * @return the name of the button
- */
- public String getName()
- {
- return name;
- }
- /**
- * runs the button function
- *
- * @param gamestate the gamestate
- * @param level the current level
- */
- public void run(Gamestate gamestate, Level level)
- {
- r.accept(gamestate, level);
- }
- }
|