package cz.davza.studentadventure.rooms; import cz.davza.studentadventure.Items.StickyNote; import cz.davza.studentadventure.base.RoomBase; import cz.davza.studentadventure.objects.CommandResult; import cz.davza.studentadventure.objects.GameData; import cz.davza.studentadventure.objects.Player; /** * A university lecture hall. Entry requires the player to be carrying a book. * *

If the player attempts to enter without a {@code book} in their inventory, * the professor blocks them at the door and inflicts a stress penalty. * Sleeping in class is allowed but carries a {@code 30%} chance of a game-over.

* * @see cz.davza.studentadventure.commands.SleepCommand */ public class ClassroomRoom extends RoomBase { /** Creates the classroom room. */ public ClassroomRoom(GameData gameContext) { super("Classroom", "classroom", "Rows of seats face a whiteboard. The professor drones on at the front. " + "Several students look just as tired as you.", 10); getItems().Add(new StickyNote("Computer lab password: " + gameContext.getComputerPassword()), 1); allowedCommands.add("sleep"); } /** * {@inheritDoc} * *

Checks the player's inventory for a {@code book}. If none is found, * prints a refusal message, applies a stress penalty, and cancels the room * change via {@code context.getMap().setNextRoom(null)}.

* * @return */ @Override public CommandResult onEnter(GameData context) { Player player = context.getPlayer(); boolean hasBook = player.getInventory().GetByItemCode("book") != null; if (!hasBook) { player.getStress().increase(15); context.getMap().setNextRoom(null); return CommandResult.failed( "The professor stops you at the door.\n" + "\"No textbook? Get out of my classroom!\"\n" + "Stress +15. " + player.getStress()); } return CommandResult.success(""); } }