From 6a34cf4813d3a7620e24f930af6e54fc55f9ff7b Mon Sep 17 00:00:00 2001 From: schmaeddes Date: Wed, 3 Aug 2022 12:30:37 +0200 Subject: [PATCH] initial stuff --- .gitignore | 2 ++ pom.xml | 10 ++++++ src/main/java/Commands.java | 19 +++++++++++ src/main/java/Environment.java | 14 +++++++++ src/main/java/Main.java | 25 +++++++++++++++ src/main/java/Parser.java | 15 +++++++++ src/main/java/TextColors.java | 24 ++++++++++++++ src/main/java/areas/Area.java | 54 ++++++++++++++++++++++++++++++++ src/main/java/areas/Forrest.java | 22 +++++++++++++ src/main/java/areas/GetArea.java | 23 ++++++++++++++ src/main/java/areas/House.java | 25 +++++++++++++++ 11 files changed, 233 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/Commands.java create mode 100644 src/main/java/Environment.java create mode 100644 src/main/java/Main.java create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/TextColors.java create mode 100644 src/main/java/areas/Area.java create mode 100644 src/main/java/areas/Forrest.java create mode 100644 src/main/java/areas/GetArea.java create mode 100644 src/main/java/areas/House.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c507849 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +.idea diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..aabf3d2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + + schmaeddes + untitledTextAdventure + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java new file mode 100644 index 0000000..2c7a09b --- /dev/null +++ b/src/main/java/Commands.java @@ -0,0 +1,19 @@ +import areas.Area; + +public class Commands { + + public static void go(Area area) { + Main.environment.setArea(area); + area.enterArea(); + } + + public static void info() { + String infoText = TextColors.PURPLE.colorize("Du bist hier: " + + Environment.getArea().getNameWithArticle()) + "\n" + + "Du kannst folgende Bereiche von hier erreichen: " + + String.join(", ", Environment.getArea().getReachableAreas()); + + System.out.println(infoText); + } + +} diff --git a/src/main/java/Environment.java b/src/main/java/Environment.java new file mode 100644 index 0000000..da896e3 --- /dev/null +++ b/src/main/java/Environment.java @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..651613d --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,25 @@ +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Scanner; + +public class Main { + + public static Environment environment = new Environment(); + public static Parser parser = new Parser(); + + public static void main(String[] args) { + + String greenPrompt = TextColors.BLUE.colorize(">"); + + Scanner scanner = new Scanner(System.in); + + while(true) { + System.out.printf("%s ", greenPrompt); + List input = Arrays.stream(scanner.nextLine().split(" ")).map(o -> o.toLowerCase(Locale.ROOT)).toList(); + + parser.parse(input); + } + + } +} diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000..34808de --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,15 @@ +import areas.GetArea; + +import java.util.List; + +public class Parser { + + public void parse(List parameter) { + + switch (parameter.get(0)) { + case "go" -> Commands.go(GetArea.getArea(parameter.get(1))); + case "info" -> Commands.info(); + } + + } +} diff --git a/src/main/java/TextColors.java b/src/main/java/TextColors.java new file mode 100644 index 0000000..1b0c5a0 --- /dev/null +++ b/src/main/java/TextColors.java @@ -0,0 +1,24 @@ +import org.w3c.dom.Text; + +public enum TextColors { + + RESET("\u001B[0m"), + BLACK("\u001B[30m"), + RED("\u001B[31m"), + GREEN("\u001B[32m"), + YELLOW("\u001B[33m"), + BLUE("\u001B[34m"), + PURPLE("\u001B[35m"), + CYAN("\u001B[36m"), + WHITE("\u001B[37m"); + + public String value; + + TextColors(String value) { + this.value = value; + } + + public String colorize(String word) { + return this.value + word + TextColors.RESET.value; + } +} diff --git a/src/main/java/areas/Area.java b/src/main/java/areas/Area.java new file mode 100644 index 0000000..c572cbb --- /dev/null +++ b/src/main/java/areas/Area.java @@ -0,0 +1,54 @@ +package areas; + +import java.util.ArrayList; +import java.util.List; + +public class Area { + + private List enterText; + private String name; + private String article; + private List reachableAreas = new ArrayList<>(); + + public List getEnterText() { + return enterText; + } + + public void setEnterText(List enterText) { + this.enterText = enterText; + } + + public void enterArea() { + for(String text: this.getEnterText()) { + System.out.println(text); + } + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getArticle() { + return article; + } + + public void setArticle(String article) { + this.article = article; + } + + public List getReachableAreas() { + return reachableAreas; + } + + public void setReachableAreas(List reachableAreas) { + this.reachableAreas = reachableAreas; + } + + public String getNameWithArticle() { + return this.article + " " + this.name; + } +} diff --git a/src/main/java/areas/Forrest.java b/src/main/java/areas/Forrest.java new file mode 100644 index 0000000..d1c0b00 --- /dev/null +++ b/src/main/java/areas/Forrest.java @@ -0,0 +1,22 @@ +package areas; + +import java.util.ArrayList; +import java.util.List; + +public class Forrest extends Area { + + public Forrest() { + this.setArticle("Der"); + this.setName("Wald"); + + this.getReachableAreas().add("Das Haus"); + + List enterText = new ArrayList<>(); + + enterText.add("Du betrittst den Wald."); + enterText.add("Eine kleine Lichtung befindet sich genau in der Mitte."); + + this.setEnterText(enterText); + } + +} diff --git a/src/main/java/areas/GetArea.java b/src/main/java/areas/GetArea.java new file mode 100644 index 0000000..6b7d989 --- /dev/null +++ b/src/main/java/areas/GetArea.java @@ -0,0 +1,23 @@ +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 new file mode 100644 index 0000000..d9d1fd7 --- /dev/null +++ b/src/main/java/areas/House.java @@ -0,0 +1,25 @@ +package areas; + +import com.sun.tools.javac.Main; + +import java.util.ArrayList; +import java.util.List; + +public class House extends Area { + + public House() { + this.setArticle("Das"); + this.setName("Haus"); + + this.getReachableAreas().add("Der Wald"); + this.getReachableAreas().add("Der See"); + + List enterText = new ArrayList<>(); + + enterText.add("Du betrittst das Haus."); + enterText.add("Ein leichter Luftzug geht durch den Eingangsbereich. Irgendjemand hat ein Fenster aufgelassen."); + + this.setEnterText(enterText); + } + +}