Browse Source

refactoring: Outsourced code

When the player is new a outsourced method is called
remotes/origin/develop
David Hermann 2 years ago
parent
commit
d6ece832e7
  1. 30
      src/main/java/org/bitbiome/classes/InteractionLoop.java

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

@ -4,7 +4,6 @@ import org.bitbiome.Boot;
import org.json.JSONObject;
import java.util.Scanner;
public class InteractionLoop {
Scanner input = new Scanner(System.in);
@ -12,19 +11,16 @@ public class InteractionLoop {
public void run(TravelEngine travelEngine) {
boolean isRunning = true;
if (playerIsNew(travelEngine.getPlayer().getName())) {
print(Colors.ANSI_BLUE + "Oh, ein Fremder!\nBist du bereit für dein womöglich größtes Abenteuer?\nDann sag mir doch zunächst wie du heißt: " + Colors.ANSI_RESET);
String name = input.nextLine();
JsonParser jp = new JsonParser();
JSONObject playerconf = jp.getJSONObject("playerconfig.json");
playerconf.put("name", name);
travelEngine.getPlayer().setName(name);
jp.writeObject("playerconfig.json", playerconf);
newPlayerWelcome(travelEngine);
}
print(Colors.ANSI_BG_CYAN + Colors.ANSI_BLACK + "Willkommen zu BitBiome " + travelEngine.getPlayer().getName() + "!" + Colors.ANSI_RESET + "\n\n");
print(Colors.ANSI_BG_CYAN + Colors.ANSI_BLACK + "Willkommen zu BitBiome " + travelEngine.getPlayer().getName()
+ "!" + Colors.ANSI_RESET + "\n\n");
while (isRunning) {
String line = input.nextLine().toLowerCase();
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line, travelEngine)) {
print(Colors.ANSI_RED + "Unbekannter Befehl - Siehe " + Colors.ANSI_PURPLE + "help\n" + Colors.ANSI_RESET);
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line,
travelEngine)) {
print(Colors.ANSI_RED + "Unbekannter Befehl - Siehe " + Colors.ANSI_PURPLE + "help\n"
+ Colors.ANSI_RESET);
}
}
}
@ -38,6 +34,16 @@ public class InteractionLoop {
return name.equalsIgnoreCase("null");
}
public void newPlayerWelcome(TravelEngine travelEngine) {
print(Colors.ANSI_BLUE
+ "Oh, ein Fremder!\nBist du bereit für dein womöglich größtes Abenteuer?\nDann sag mir doch zunächst wie du heißt: "
+ Colors.ANSI_RESET);
String name = input.nextLine();
JsonParser jp = new JsonParser();
JSONObject playerconf = jp.getJSONObject("playerconfig.json");
playerconf.put("name", name);
travelEngine.getPlayer().setName(name);
jp.writeObject("playerconfig.json", playerconf);
}
}
Loading…
Cancel
Save