| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package eu.oschl.gui.actions;
- import eu.oschl.gui.Output;
- import eu.oschl.textadventure.Game;
- import eu.oschl.textadventure.objects.Button;
- import javafx.scene.paint.Color;
- /**
- * Action for pressing a button in the current room.
- *
- * @author Ondřej Schlaichert
- */
- public class PressButton implements Action {
- private final Game game;
- public PressButton(Game game) {
- this.game = game;
- }
- @Override
- public String getId() {
- return "press";
- }
- @Override
- public String getName() {
- return "Press";
- }
- @Override
- public String getDescription() {
- return "press a button";
- }
- @Override
- public void execute(String[] args) {
- for (var object : this.game.getCurrentRoom().getObjects()) {
- if (object.getName().equalsIgnoreCase(String.join(" ", args))) {
- if (object instanceof Button button) {
- var result = button.press();
- if (result) {
- Output.print(button.getPressText(), Color.MAGENTA);
- } else {
- Output.print("Button ", Color.RED);
- Output.print(button.getName(), Color.MAGENTA);
- Output.print(" has already been pressed.", Color.RED);
- }
- } else {
- Output.print("It's impossible to press ", Color.RED);
- Output.print(object.getName(), Color.MAGENTA);
- Output.print(". It's not a button.", Color.RED);
- }
- return;
- }
- }
- Output.print("That item is not here.", Color.RED);
- }
- }
|