Class KaiserActions

java.lang.Object
de.aikiit.game.kaiser.KaiserActions

public final class KaiserActions extends Object
Handles the console dialogue for buying and selling land, feeding the population and planting crops. Each action requests a quantity and delegates validation and changes to the game state to KaiserEngine.

Invalid numbers and quantities rejected by the engine produce an explanation and another prompt. Negative quantities end the game according to the BASIC rules; exhausted input also aborts the game rather than prompting indefinitely. All actions use the caller's shared scanner so buffered input is preserved between prompts. The scanner is not closed here because its lifetime belongs to the caller.

  • Method Details

    • buy

      public static boolean buy(KaiserEngine engine, Scanner input)
      Asks how many hectares to buy and retries until the engine accepts the quantity or the game is aborted. A positive purchase spends grain at the current land price; entering zero leaves stocks unchanged and allows the caller to offer selling land instead.
      Parameters:
      engine - game whose land and grain stocks are updated
      input - shared console scanner; decimal quantities use a point
      Returns:
      true after an accepted positive purchase; false for zero, a negative quantity or exhausted input. The caller must also check KaiserEngine.isGameOver() before offering another action.
    • sell

      public static void sell(KaiserEngine engine, Scanner input)
      Asks how many hectares to sell in exchange for grain at the current land price. Selling all owned land or more is rejected with a new prompt; zero is accepted without changing ownership or stocks. A negative quantity or exhausted input aborts the game and returns control to the caller.
      Parameters:
      engine - game whose land and grain stocks are updated
      input - shared console scanner; decimal quantities use a point
    • feed

      public static void feed(KaiserEngine engine, Scanner input)
      Asks how much stored grain to distribute to the population. The accepted amount is removed from stocks and retained by the engine for the later starvation calculation; this dialogue does not immediately change the population. Allocating more grain than is available causes another prompt. Zero is valid, while a negative quantity or exhausted input aborts the game.
      Parameters:
      engine - game whose stocks and food allocation are updated
      input - shared console scanner; quantities are in dt of grain
    • cultivate

      public static void cultivate(KaiserEngine engine, Scanner input)
      Asks how many hectares to plant and delegates seed consumption, harvest and rat losses to the engine. Rejected quantities produce an explanation about available land, seed grain or workers before asking again. Entering zero still processes the season's harvest and possible rat losses; a negative quantity or exhausted input aborts the game instead.
      Parameters:
      engine - game whose planting and harvest are processed
      input - shared console scanner; quantities are in hectares