Skip to content

Commit

Permalink
Add game layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ottlinger committed Dec 15, 2023
1 parent 68dd6bb commit 19c9ebf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
<defaultGoal>clean install</defaultGoal>
Expand Down
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
clear
echo "Building the game ...."
./mvnw &> /dev/null
echo "Starting the game ...."
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/de/aikiit/game/kaiser/KaiserEngine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.aikiit.game.kaiser;

import lombok.Getter;

@Getter
public class KaiserEngine {
private Long population = 0L;
private Long area = 0L;
Expand All @@ -13,7 +16,7 @@ public class KaiserEngine {
private final Integer zYear; // why z in original?
private final Long deathToll;
private Long deathTollSum; // d1 in original
private Long percentDeathToll;
private Long percentDeathToll; // p1 in original
private final Long increase; // birthRate?

/// Missing:
Expand All @@ -35,6 +38,7 @@ public KaiserEngine() {
this.area = Long.divideUnsigned(this.humans, this.supplies);
this.increase = 5L;
this.deathToll = 0L;
this.percentDeathToll = 0L;
}

}
28 changes: 25 additions & 3 deletions src/main/java/de/aikiit/game/kaiser/KaiserEnginePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,34 @@ public class KaiserEnginePrinter {
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public String getStatus(KaiserEngine engine) {

private final KaiserEngine engine;

public KaiserEnginePrinter(KaiserEngine engine) {
this.engine = engine;
}

public String getStatus(int round) {
StringBuilder status = new StringBuilder();

status.append(ANSI_GREEN).append("STATUS").append(ANSI_RESET);
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(" DZ/Hektar").append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_RED).append("Ratten haben gefressen ").append(this.engine.getYield()).append(" DZ").append(ANSI_RESET).append(System.lineSeparator());
status.append(ANSI_RED).append("Die Vorräte betragen ").append(this.engine.getSupplies()).append(" DZ").append(ANSI_RESET).append(System.lineSeparator());
return status.toString();
}

public String getResults() {
StringBuilder result = new StringBuilder();

result.append("In Ihrer ").append(KaiserGame.MAX_ROUNDS).append("-jährigen Amtszeit sind ");
result.append(this.engine.getPercentDeathToll()).append(System.lineSeparator());

return result.toString();

return status.toString();
}


}
18 changes: 14 additions & 4 deletions src/main/java/de/aikiit/game/kaiser/KaiserGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

public class KaiserGame {

private static final int MAX_ROUNDS = 10;
public static final int MAX_ROUNDS = 10;
private final KaiserEngine engine;
private final KaiserEnginePrinter printer;
private int round = 0;

public KaiserGame() {
this.engine = new KaiserEngine();
this.printer = new KaiserEnginePrinter();
this.printer = new KaiserEnginePrinter(this.engine);
}

public void start() {
Expand All @@ -23,12 +23,22 @@ public void start() {
while (round <= MAX_ROUNDS) {
System.out.println(KaiserEnginePrinter.ANSI_BLUE + "### Starte in Runde " + ++round + "...." + KaiserEnginePrinter.ANSI_RESET);
status();
actions();
}

finish();
}

public void status() {
System.out.println("Status nach Runde " + round);
System.out.println(printer.getStatus(this.engine));
System.out.println(printer.getStatus(round));
}

public void actions() {

}

public void finish() {
System.out.println(printer.getResults());
}


Expand Down

0 comments on commit 19c9ebf

Please sign in to comment.