Skip to content

Commit

Permalink
Pad output and increment counter
Browse files Browse the repository at this point in the history
  • Loading branch information
ottlinger committed Dec 16, 2023
1 parent 9543b9a commit 7f8da30
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
75 changes: 40 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.aikiit</groupId>
<artifactId>game.kaiser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>game-kaiser-java</name>
<description>An adaption of the old Kaiser/Sumeria game</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.aikiit</groupId>
<artifactId>game.kaiser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>game-kaiser-java</name>
<description>An adaption of the old Kaiser/Sumeria game</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>

<build>
<defaultGoal>clean install</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<build>
<defaultGoal>clean install</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
2 changes: 1 addition & 1 deletion src/main/java/de/aikiit/game/kaiser/KaiserEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void play() {
System.out.println(KaiserEnginePrinter.ANSI_RESET);
}

this.c = new Random().nextInt();
this.c = new Random().nextInt(11) + 1;
this.yield = Long.valueOf(c) + 17;
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/de/aikiit/game/kaiser/KaiserEnginePrinter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.aikiit.game.kaiser;

import org.apache.commons.lang3.StringUtils;

public class KaiserEnginePrinter {

// inspired by https://talyian.github.io/ansicolors/
Expand All @@ -23,11 +25,11 @@ public String getStatus(int round) {
StringBuilder status = new StringBuilder();

status.append(ANSI_GREEN).append("### STATUS nach Runde ").append(round).append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_CYAN).append("Die Einwohnerzahl ist jetzt ").append(this.engine.getPopulation()).append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_CYAN).append("Die Stadt besitzt an Land ").append(this.engine.getArea()).append(" Hektar").append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_CYAN).append("Die Ernte betrug ").append(this.engine.getYield()).append(" dzt/Hektar").append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_RED).append("Ratten haben gefressen ").append(this.engine.getYield()).append(" dzt").append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_RED).append("Die Vorräte betragen ").append(this.engine.getSupplies()).append(" dzt").append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_CYAN).append("Die Einwohnerzahl beträgt jetzt ").append(StringUtils.leftPad(String.valueOf(this.engine.getPopulation()), 10)).append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_CYAN).append("Die Stadt besitzt an Land (Hektar)").append(StringUtils.leftPad(String.valueOf(this.engine.getArea()), 10)).append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_CYAN).append("Die Ernte betrug (dzt/Hektar) ").append(StringUtils.leftPad(String.valueOf(this.engine.getYield()), 10)).append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_RED).append("Ratten haben gefressen (dzt) ").append(StringUtils.leftPad(String.valueOf(this.engine.getYield()), 10)).append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_RED).append("Eure Vorräte betragen (dzt) ").append(StringUtils.leftPad(String.valueOf(this.engine.getSupplies()), 10)).append(ANSI_RESET).append(System.lineSeparator());
return status.toString();
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/de/aikiit/game/kaiser/KaiserGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ public KaiserGame() {
this.printer = new KaiserEnginePrinter(this.engine);
}

private void incrementRoundCounter() {
round++;
}

public void run() {
intro();
status();
while (round < MAX_ROUNDS) {
incrementRoundCounter();
engine.play();
status();
actions();
engine.play();
}

finish();
byeByeBanner();
}

private void incrementRoundCounter() {
round++;
}

public void intro() {
banner();
System.out.println("Versuchen Sie die antike Stadt " + KaiserEnginePrinter.ANSI_YELLOW + ">SUMERIA<" + KaiserEnginePrinter.ANSI_RESET + " zu regieren!");
Expand Down

0 comments on commit 7f8da30

Please sign in to comment.