Defining a Class
A class can be defined in its own file or alongside other elements, like functions or variables.
Defining a class in its own file gives it room to grow as the program scales up over time, and that is what you will do in NyetHack.
Create a new Player.kt file and declare your first class with the class keyword:
Listing 12.1 Defining the Player class (Player.kt)
class Player
A class is often declared in a file matching its name, but it does not have to be. You can define multiple classes in the same file – and you may want to if you have multiple classes used for a similar purpose.
With that, your class is defined. Now all you have to do is give it some work to do.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access