diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/LookCommand.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/LookCommand.java index ecc918d..2a1fb5b 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/LookCommand.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/command/impl/LookCommand.java @@ -2,49 +2,27 @@ package thb.jeanluc.adventure.command.impl; import thb.jeanluc.adventure.command.Command; import thb.jeanluc.adventure.game.GameContext; +import thb.jeanluc.adventure.io.text.RoomView; import thb.jeanluc.adventure.model.Direction; import thb.jeanluc.adventure.model.Npc; import thb.jeanluc.adventure.model.Room; import thb.jeanluc.adventure.model.item.Item; import java.util.List; -import java.util.stream.Collectors; /** - * Prints a full description of the room the player is currently in: - * name, description, visible items, visible NPCs, and available exits. - * Usage: {@code look}. + * Describes the current room by emitting a {@link RoomView}; the active + * frontend decides how to render it. Usage: {@code look}. */ public class LookCommand implements Command { @Override public void execute(GameContext ctx, List args) { Room room = ctx.getPlayer().getCurrentRoom(); - StringBuilder sb = new StringBuilder(); - sb.append("== ").append(room.getName()).append(" ==\n"); - sb.append(room.getDescription().stripTrailing()); - - if (!room.getItems().isEmpty()) { - String items = room.getItems().values().stream() - .map(Item::getName) - .collect(Collectors.joining(", ")); - sb.append("\nYou see: ").append(items).append('.'); - } - if (!room.getNpcs().isEmpty()) { - String npcs = room.getNpcs().values().stream() - .map(Npc::getName) - .collect(Collectors.joining(", ")); - sb.append("\nHere is: ").append(npcs).append('.'); - } - if (room.getExits().isEmpty()) { - sb.append("\nThere are no obvious exits."); - } else { - String exits = room.getExits().keySet().stream() - .map(Direction::getLabel) - .collect(Collectors.joining(", ")); - sb.append("\nExits: ").append(exits).append('.'); - } - ctx.getIo().write(sb.toString()); + List items = room.getItems().values().stream().map(Item::getName).toList(); + List npcs = room.getNpcs().values().stream().map(Npc::getName).toList(); + List exits = room.getExits().keySet().stream().map(Direction::getLabel).toList(); + ctx.getIo().showRoom(new RoomView(room.getName(), room.getDescription(), items, npcs, exits)); } @Override