Class KaiserActions
java.lang.Object
de.aikiit.game.kaiser.KaiserActions
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 Summary
Modifier and TypeMethodDescriptionstatic booleanbuy(KaiserEngine engine, Scanner input) Asks how many hectares to buy and retries until the engine accepts the quantity or the game is aborted.static voidcultivate(KaiserEngine engine, Scanner input) Asks how many hectares to plant and delegates seed consumption, harvest and rat losses to the engine.static voidfeed(KaiserEngine engine, Scanner input) Asks how much stored grain to distribute to the population.static voidsell(KaiserEngine engine, Scanner input) Asks how many hectares to sell in exchange for grain at the current land price.
-
Method Details
-
buy
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 updatedinput- shared console scanner; decimal quantities use a point- Returns:
trueafter an accepted positive purchase;falsefor zero, a negative quantity or exhausted input. The caller must also checkKaiserEngine.isGameOver()before offering another action.
-
sell
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 updatedinput- shared console scanner; decimal quantities use a point
-
feed
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 updatedinput- shared console scanner; quantities are in dt of grain
-
cultivate
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 processedinput- shared console scanner; quantities are in hectares
-