diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java index 046c3d6..fa5c3bf 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/game/Game.java @@ -5,6 +5,7 @@ import thb.jeanluc.adventure.command.Command; import thb.jeanluc.adventure.command.CommandParser; import thb.jeanluc.adventure.command.CommandRegistry; import thb.jeanluc.adventure.command.ParsedCommand; +import thb.jeanluc.adventure.io.text.Hud; import java.util.Optional; @@ -28,10 +29,14 @@ public class Game { /** Loop flag. Flipped to false by {@link #stop()}. */ private boolean running = true; + /** Number of commands processed this session; shown in the HUD. */ + private int turn = 0; + /** * Runs the loop until {@link #stop()} is called or input is exhausted. */ public void run() { + publishHud(); while (running) { String input = ctx.getIo().readLine(); if (input == null) { @@ -46,10 +51,20 @@ public class Game { ctx.getIo().write("I don't understand '" + parsed.verb() + "'. Type 'help'."); } else { cmd.get().execute(ctx, parsed.args()); + turn++; } + publishHud(); } } + private void publishHud() { + ctx.getIo().setHud(new Hud( + ctx.getPlayer().getCurrentRoom().getName(), + ctx.getPlayer().getGold(), + turn, + false)); + } + /** * Signals the loop to terminate after the current iteration. */