Add optional %user% Field

This commit is contained in:
YannikG 2025-10-20 08:57:28 +02:00 committed by Yannik Giebenhain
parent 39ce7daefd
commit ded4ee717a

View File

@ -27,6 +27,7 @@ public class Main {
.collect(Collectors.joining(", "));
private static String currentScene = "start";
private static String userName = "Player";
public static void main(String[] args) {
if (args.length > 0) {
@ -47,6 +48,13 @@ public class Main {
textSpeed = TextSpeed.FAST;
}
System.out.println("What is your Name?");
System.out.print("> ");
String name = scanner.nextLine();
if(!name.isEmpty()) {
userName = name.strip().split(" ")[0];
}
run(currentScene);
}
@ -71,6 +79,7 @@ public class Main {
}
public static void writeText(String text) {
text = text.replace("%user%", userName);
try {
for (char c : text.toCharArray()) {
System.out.print(c);