command line

How you implement “commands” in a console based game? I though about some sort of parse(String input) method to take in input and “guess” what the user wishes to do. However, differrent commands are available depending on whch stage of the game you are? How to go round this?

Thanks.

This is a science in itself.

Parsing the command is not that hard, but interpreting is.

There are RPG-games now that can parse commands like:
“Drop the yellow book in my pocket”
but it will be years of coding before your interpreter gains any remotely usable understanding-capabilities.

It’s far easier to pick an item and show some options.

I see, well, my game is cards.

What you suggest I use of input? Is a console game for now.

Think of it like a menu-structure.

You first select what to do (select, drop, bet) then pick an action, if there are still options left, let the player choose. Just go deeper and deeper, until you find out enough about what the player wants.

You have to code this behaviour in a tree-like structure.
You could process the input as “5.3.4.2.1.1”
(user picked 5, then 3 then 4 then 2 then 1 then 1)
The user ofcourse won’t be seeing these numbers.

Command line interface is already available as the default System.in. While running in your main loop, simply call System.in.readLine() to get the user command line input.
The user will press the “enter” or “return” keystroke to validate, while the System.in.readLine() while block until that key stroke is pressed. :smiley: