mirror of
https://github.com/schmaeddes/untitledTextAdventure.git
synced 2024-12-27 09:00:11 +01:00
initial stuff
This commit is contained in:
commit
6a34cf4813
11 changed files with 233 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
target
|
||||
.idea
|
10
pom.xml
Normal file
10
pom.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>schmaeddes</groupId>
|
||||
<artifactId>untitledTextAdventure</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</project>
|
19
src/main/java/Commands.java
Normal file
19
src/main/java/Commands.java
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
14
src/main/java/Environment.java
Normal file
14
src/main/java/Environment.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
25
src/main/java/Main.java
Normal file
25
src/main/java/Main.java
Normal file
|
@ -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<String> input = Arrays.stream(scanner.nextLine().split(" ")).map(o -> o.toLowerCase(Locale.ROOT)).toList();
|
||||
|
||||
parser.parse(input);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
15
src/main/java/Parser.java
Normal file
15
src/main/java/Parser.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
import areas.GetArea;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Parser {
|
||||
|
||||
public void parse(List<String> parameter) {
|
||||
|
||||
switch (parameter.get(0)) {
|
||||
case "go" -> Commands.go(GetArea.getArea(parameter.get(1)));
|
||||
case "info" -> Commands.info();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
24
src/main/java/TextColors.java
Normal file
24
src/main/java/TextColors.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
54
src/main/java/areas/Area.java
Normal file
54
src/main/java/areas/Area.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package areas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Area {
|
||||
|
||||
private List<String> enterText;
|
||||
private String name;
|
||||
private String article;
|
||||
private List<String> reachableAreas = new ArrayList<>();
|
||||
|
||||
public List<String> getEnterText() {
|
||||
return enterText;
|
||||
}
|
||||
|
||||
public void setEnterText(List<String> 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<String> getReachableAreas() {
|
||||
return reachableAreas;
|
||||
}
|
||||
|
||||
public void setReachableAreas(List<String> reachableAreas) {
|
||||
this.reachableAreas = reachableAreas;
|
||||
}
|
||||
|
||||
public String getNameWithArticle() {
|
||||
return this.article + " " + this.name;
|
||||
}
|
||||
}
|
22
src/main/java/areas/Forrest.java
Normal file
22
src/main/java/areas/Forrest.java
Normal file
|
@ -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<String> enterText = new ArrayList<>();
|
||||
|
||||
enterText.add("Du betrittst den Wald.");
|
||||
enterText.add("Eine kleine Lichtung befindet sich genau in der Mitte.");
|
||||
|
||||
this.setEnterText(enterText);
|
||||
}
|
||||
|
||||
}
|
23
src/main/java/areas/GetArea.java
Normal file
23
src/main/java/areas/GetArea.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
25
src/main/java/areas/House.java
Normal file
25
src/main/java/areas/House.java
Normal file
|
@ -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<String> 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue