ClassroomRoom.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package cz.davza.studentadventure.rooms;
  2. import cz.davza.studentadventure.Items.StickyNote;
  3. import cz.davza.studentadventure.base.RoomBase;
  4. import cz.davza.studentadventure.objects.CommandResult;
  5. import cz.davza.studentadventure.objects.GameData;
  6. import cz.davza.studentadventure.objects.Player;
  7. /**
  8. * A university lecture hall. Entry requires the player to be carrying a book.
  9. *
  10. * <p>If the player attempts to enter without a {@code book} in their inventory,
  11. * the professor blocks them at the door and inflicts a stress penalty.
  12. * Sleeping in class is allowed but carries a {@code 30%} chance of a game-over.</p>
  13. *
  14. * @see cz.davza.studentadventure.commands.SleepCommand
  15. */
  16. public class ClassroomRoom extends RoomBase {
  17. /** Creates the classroom room. */
  18. public ClassroomRoom(GameData gameContext) {
  19. super("Classroom",
  20. "classroom",
  21. "Rows of seats face a whiteboard. The professor drones on at the front. " +
  22. "Several students look just as tired as you.",
  23. 10);
  24. getItems().Add(new StickyNote("Computer lab password: " + gameContext.getComputerPassword()), 1);
  25. allowedCommands.add("sleep");
  26. }
  27. /**
  28. * {@inheritDoc}
  29. *
  30. * <p>Checks the player's inventory for a {@code book}. If none is found,
  31. * prints a refusal message, applies a stress penalty, and cancels the room
  32. * change via {@code context.getMap().setNextRoom(null)}.</p>
  33. *
  34. * @return
  35. */
  36. @Override
  37. public CommandResult onEnter(GameData context) {
  38. Player player = context.getPlayer();
  39. boolean hasBook = player.getInventory().GetByItemCode("book") != null;
  40. if (!hasBook) {
  41. player.getStress().increase(15);
  42. context.getMap().setNextRoom(null);
  43. return CommandResult.failed(
  44. "The professor stops you at the door.\n" +
  45. "\"No textbook? Get out of my classroom!\"\n" +
  46. "Stress +15. " + player.getStress());
  47. }
  48. return CommandResult.success("");
  49. }
  50. }