From d46176e8a274772800dc5dc9ad994be4bd96e654 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:48:31 +0100 Subject: [PATCH] Added the quit command This command quits the game with exit code 0. --- .../java/org/bitbiome/commands/CommandListener.java | 3 +++ src/main/java/org/bitbiome/commands/QuitCommand.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/QuitCommand.java diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index f10bdfe..2e62105 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -11,6 +11,9 @@ public class CommandListener { commands = new HashMap<>(); commands.put("help", new HelpCommand()); + + commands.put("exit", new QuitCommand()); + commands.put("quit", new QuitCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/QuitCommand.java b/src/main/java/org/bitbiome/commands/QuitCommand.java new file mode 100644 index 0000000..13e4e1e --- /dev/null +++ b/src/main/java/org/bitbiome/commands/QuitCommand.java @@ -0,0 +1,12 @@ +package org.bitbiome.commands; + +import java.util.Scanner; + +public class QuitCommand implements CommandAPI { + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message) { + System.out.println("You quitted!"); + System.exit(0); + } +}