Nested Classes
Not all classes defined within other classes are declared as objects.
You can also use the class
keyword to define a regular class nested inside another class.
In this section, you will define a new GameInput class nested within the Game object.
Now that you have defined a game loop, you will want to apply some control over the user input passed to your game. NyetHack is a text adventure, driven by the user entering commands to the readLine function. There are two things you need to ensure about the user’s commands: First, that they are valid commands. Second, that commands with multiple parts, like “move east,” are handled correctly: You want “move” to trigger a move function and “east” to provide the move function ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.