removed classes and added environment

This commit is contained in:
schmaeddes 2022-08-03 14:03:51 +02:00
parent 6a34cf4813
commit 29e3bbe9bd
9 changed files with 76 additions and 50 deletions

View file

@ -9,9 +9,9 @@ public class Commands {
public static void info() { public static void info() {
String infoText = TextColors.PURPLE.colorize("Du bist hier: " + String infoText = TextColors.PURPLE.colorize("Du bist hier: " +
Environment.getArea().getNameWithArticle()) + "\n" + Main.environment.getCurrentArea().getNameWithArticle()) + "\n" +
"Du kannst folgende Bereiche von hier erreichen: " + "Du kannst folgende Bereiche von hier erreichen: " +
String.join(", ", Environment.getArea().getReachableAreas()); String.join(", ", Main.environment.getCurrentArea().getReachableAreas());
System.out.println(infoText); System.out.println(infoText);
} }

View file

@ -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;
}
}

View file

@ -1,3 +1,6 @@
import startup.Environment;
import startup.LoadStuff;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -10,8 +13,10 @@ public class Main {
public static void main(String[] args) { 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); Scanner scanner = new Scanner(System.in);
while(true) { while(true) {

View file

@ -1,13 +1,12 @@
import areas.GetArea;
import java.util.List; import java.util.List;
public class Parser { public class Parser {
public void parse(List<String> parameter) { public void parse(List<String> parameter) {
String command = parameter.get(0);
switch (parameter.get(0)) { switch (command) {
case "go" -> Commands.go(GetArea.getArea(parameter.get(1))); case "go" -> Commands.go(Main.environment.getAreaByString(parameter.get(1)));
case "info" -> Commands.info(); case "info" -> Commands.info();
} }

View file

@ -3,11 +3,11 @@ package areas;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Forrest extends Area { public class Forest extends Area {
public Forrest() { public Forest() {
this.setArticle("Der"); this.setArticle("Der");
this.setName("Wald"); this.setName("wald");
this.getReachableAreas().add("Das Haus"); this.getReachableAreas().add("Das Haus");

View file

@ -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;
}
}
}
}

View file

@ -1,7 +1,5 @@
package areas; package areas;
import com.sun.tools.javac.Main;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -9,7 +7,7 @@ public class House extends Area {
public House() { public House() {
this.setArticle("Das"); this.setArticle("Das");
this.setName("Haus"); this.setName("haus");
this.getReachableAreas().add("Der Wald"); this.getReachableAreas().add("Der Wald");
this.getReachableAreas().add("Der See"); this.getReachableAreas().add("Der See");

View file

@ -0,0 +1,36 @@
package startup;
import areas.Area;
import java.util.List;
public class Environment {
private Area currentArea;
private List<Area> 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<Area> getGameAreas() {
return gameAreas;
}
// Game Relevant Stuff
public void setGameAreas(List<Area> gameAreas) {
this.gameAreas = gameAreas;
}
public void setCurrentArea(Area currentArea) {
this.currentArea = currentArea;
}
}

View file

@ -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<Area> areas = new ArrayList<>();
areas.add(new House());
areas.add(new Forest());
environment.setGameAreas(areas);
}
}