Browse Source

Added the travel engine to the InteractionLoop

remotes/origin/locations
David Hermann 2 years ago
parent
commit
3cedb71e90
  1. 6
      src/main/java/org/bitbiome/Boot.java
  2. 5
      src/main/java/org/bitbiome/classes/InteractionLoop.java
  3. 4
      src/main/java/org/bitbiome/commands/CommandAPI.java
  4. 6
      src/main/java/org/bitbiome/commands/CommandListener.java
  5. 3
      src/main/java/org/bitbiome/commands/HelpCommand.java
  6. 4
      src/main/java/org/bitbiome/commands/QuitCommand.java

6
src/main/java/org/bitbiome/Boot.java

@ -1,7 +1,9 @@
package org.bitbiome;
import org.bitbiome.classes.InteractionLoop;
import org.bitbiome.classes.TravelEngine;
import org.bitbiome.commands.CommandListener;
import org.bitbiome.entities.Player;
public class Boot {
@ -11,7 +13,9 @@ public class Boot {
instance = this;
cmdListener = new CommandListener();
InteractionLoop game = new InteractionLoop();
game.run();
Player player = new Player("Dave");
TravelEngine travelEngine = new TravelEngine(player);
game.run(travelEngine);
}
public CommandListener getCmdListener(){

5
src/main/java/org/bitbiome/classes/InteractionLoop.java

@ -8,11 +8,12 @@ public class InteractionLoop {
Scanner input = new Scanner(System.in);
public void run() {
public void run(TravelEngine travelEngine) {
boolean isRunning = true;
System.out.println("Willkommen zu BitBiome " + travelEngine.getPlayer().getName() + "!\n\n");
while (isRunning) {
String line = input.nextLine().toLowerCase();
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line)) {
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line, travelEngine)) {
System.out.println("Unknown Command");
}
}

4
src/main/java/org/bitbiome/commands/CommandAPI.java

@ -1,8 +1,10 @@
package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import java.util.Scanner;
public interface CommandAPI {
public void performCommand(Scanner scanner, boolean isRunning, String message);
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine);
}

6
src/main/java/org/bitbiome/commands/CommandListener.java

@ -1,5 +1,7 @@
package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import java.util.HashMap;
import java.util.Scanner;
@ -21,11 +23,11 @@ public class CommandListener {
}
public boolean perform(String command, Scanner scanner, boolean isRunning, String message) {
public boolean perform(String command, Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
CommandAPI cmd;
if ((cmd = commands.get(command)) != null) {
cmd.performCommand(scanner, isRunning, message);
cmd.performCommand(scanner, isRunning, message, travelEngine);
return true;
}
return false;

3
src/main/java/org/bitbiome/commands/HelpCommand.java

@ -1,6 +1,7 @@
package org.bitbiome.commands;
import org.bitbiome.Boot;
import org.bitbiome.classes.TravelEngine;
import java.util.HashMap;
import java.util.Scanner;
@ -9,7 +10,7 @@ public class HelpCommand implements CommandAPI {
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message) {
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println(getHelpMessage());
}

4
src/main/java/org/bitbiome/commands/QuitCommand.java

@ -1,11 +1,13 @@
package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import java.util.Scanner;
public class QuitCommand implements CommandAPI {
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message) {
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println(getQuitMessage());
System.exit(0);
}

Loading…
Cancel
Save