O'Reilly logo

Kotlin Programming: The Big Nerd Ranch Guide, First Edition by David Greenhalgh, Josh Skeen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nested Classes

Not all classes defined within other classes are declared without a name. You can also use the class keyword to define a named class nested inside of 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required