mirror of
https://github.com/schmaeddes/untitledTextAdventure.git
synced 2024-11-23 16:10:18 +01:00
removed classes and added environment
This commit is contained in:
parent
6a34cf4813
commit
29e3bbe9bd
9 changed files with 76 additions and 50 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import areas.GetArea;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Parser {
|
||||
|
||||
public void parse(List<String> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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");
|
||||
|
|
36
src/main/java/startup/Environment.java
Normal file
36
src/main/java/startup/Environment.java
Normal 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;
|
||||
}
|
||||
}
|
25
src/main/java/startup/LoadStuff.java
Normal file
25
src/main/java/startup/LoadStuff.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue