From 29e3bbe9bd647710eb415a6597da99e2695e170f Mon Sep 17 00:00:00 2001 From: schmaeddes Date: Wed, 3 Aug 2022 14:03:51 +0200 Subject: [PATCH] removed classes and added environment --- src/main/java/Commands.java | 4 +-- src/main/java/Environment.java | 14 -------- src/main/java/Main.java | 7 +++- src/main/java/Parser.java | 7 ++-- .../java/areas/{Forrest.java => Forest.java} | 6 ++-- src/main/java/areas/GetArea.java | 23 ------------ src/main/java/areas/House.java | 4 +-- src/main/java/startup/Environment.java | 36 +++++++++++++++++++ src/main/java/startup/LoadStuff.java | 25 +++++++++++++ 9 files changed, 76 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/Environment.java rename src/main/java/areas/{Forrest.java => Forest.java} (81%) delete mode 100644 src/main/java/areas/GetArea.java create mode 100644 src/main/java/startup/Environment.java create mode 100644 src/main/java/startup/LoadStuff.java diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java index 2c7a09b..084d9f5 100644 --- a/src/main/java/Commands.java +++ b/src/main/java/Commands.java @@ -9,9 +9,9 @@ public class Commands { public static void info() { String infoText = TextColors.PURPLE.colorize("Du bist hier: " + - Environment.getArea().getNameWithArticle()) + "\n" + + Main.environment.getCurrentArea().getNameWithArticle()) + "\n" + "Du kannst folgende Bereiche von hier erreichen: " + - String.join(", ", Environment.getArea().getReachableAreas()); + String.join(", ", Main.environment.getCurrentArea().getReachableAreas()); System.out.println(infoText); } diff --git a/src/main/java/Environment.java b/src/main/java/Environment.java deleted file mode 100644 index da896e3..0000000 --- a/src/main/java/Environment.java +++ /dev/null @@ -1,14 +0,0 @@ -import areas.Area; - -public class Environment { - - private static Area area; - - public static Area getArea() { - return area; - } - - public void setArea(Area area) { - this.area = area; - } -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 651613d..19c0a36 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,3 +1,6 @@ +import startup.Environment; +import startup.LoadStuff; + import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -10,8 +13,10 @@ public class Main { public static void main(String[] args) { - String greenPrompt = TextColors.BLUE.colorize(">"); + LoadStuff loadStuff = new LoadStuff(); + loadStuff.load(environment); + String greenPrompt = TextColors.BLUE.colorize(">"); Scanner scanner = new Scanner(System.in); while(true) { diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 34808de..707eee7 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,13 +1,12 @@ -import areas.GetArea; - import java.util.List; public class Parser { public void parse(List parameter) { + String command = parameter.get(0); - switch (parameter.get(0)) { - case "go" -> Commands.go(GetArea.getArea(parameter.get(1))); + switch (command) { + case "go" -> Commands.go(Main.environment.getAreaByString(parameter.get(1))); case "info" -> Commands.info(); } diff --git a/src/main/java/areas/Forrest.java b/src/main/java/areas/Forest.java similarity index 81% rename from src/main/java/areas/Forrest.java rename to src/main/java/areas/Forest.java index d1c0b00..131742a 100644 --- a/src/main/java/areas/Forrest.java +++ b/src/main/java/areas/Forest.java @@ -3,11 +3,11 @@ package areas; import java.util.ArrayList; import java.util.List; -public class Forrest extends Area { +public class Forest extends Area { - public Forrest() { + public Forest() { this.setArticle("Der"); - this.setName("Wald"); + this.setName("wald"); this.getReachableAreas().add("Das Haus"); diff --git a/src/main/java/areas/GetArea.java b/src/main/java/areas/GetArea.java deleted file mode 100644 index 6b7d989..0000000 --- a/src/main/java/areas/GetArea.java +++ /dev/null @@ -1,23 +0,0 @@ -package areas; - -public class GetArea { - - public static Area getArea(String area) { - switch (area){ - case "house" -> { - return new House(); - } - case "forrest" -> { - return new Forrest(); - } - default -> { - System.out.println("Area not found"); - return null; - } - } - - - } - - -} diff --git a/src/main/java/areas/House.java b/src/main/java/areas/House.java index d9d1fd7..f086401 100644 --- a/src/main/java/areas/House.java +++ b/src/main/java/areas/House.java @@ -1,7 +1,5 @@ package areas; -import com.sun.tools.javac.Main; - import java.util.ArrayList; import java.util.List; @@ -9,7 +7,7 @@ public class House extends Area { public House() { this.setArticle("Das"); - this.setName("Haus"); + this.setName("haus"); this.getReachableAreas().add("Der Wald"); this.getReachableAreas().add("Der See"); diff --git a/src/main/java/startup/Environment.java b/src/main/java/startup/Environment.java new file mode 100644 index 0000000..b57aaa0 --- /dev/null +++ b/src/main/java/startup/Environment.java @@ -0,0 +1,36 @@ +package startup; + +import areas.Area; + +import java.util.List; + +public class Environment { + + private Area currentArea; + private List gameAreas; + + public Area getCurrentArea() { + return currentArea; + } + + public Area getAreaByString(String area) { + return gameAreas.stream().filter(item -> item.getName().equals(area)).findFirst().get(); + } + + public void setArea(Area area) { + this.currentArea = area; + } + + public List getGameAreas() { + return gameAreas; + } + + // Game Relevant Stuff + public void setGameAreas(List gameAreas) { + this.gameAreas = gameAreas; + } + + public void setCurrentArea(Area currentArea) { + this.currentArea = currentArea; + } +} diff --git a/src/main/java/startup/LoadStuff.java b/src/main/java/startup/LoadStuff.java new file mode 100644 index 0000000..1d16a13 --- /dev/null +++ b/src/main/java/startup/LoadStuff.java @@ -0,0 +1,25 @@ +package startup; + +import areas.Area; +import areas.Forest; +import areas.House; + +import java.util.ArrayList; +import java.util.List; + +public class LoadStuff { + + public void load(Environment environment) { + initializeAreas(environment); + } + + private void initializeAreas(Environment environment) { + List areas = new ArrayList<>(); + + areas.add(new House()); + areas.add(new Forest()); + + environment.setGameAreas(areas); + } + +}