July 2018
Intermediate to advanced
400 pages
12h 14m
English
Begin by creating a new file in NyetHack called Room.kt. Room.kt will contain a new class called Room that will represent one square in NyetHack’s coordinate plane. Later, you will define a particular kind of room in a class that inherits qualities from Room.
To begin, Room will have one property – name – and two functions, description and load. description returns a String describing the room. load returns a String that will be printed to the console when you enter the room. These are features you want for every room in NyetHack.
Add the Room class definition to Room.kt, as shown:
Listing 14.1 Declaring the Room class (Room.kt)
class Room(val name: String) {
fun description() = "Room: $name"
fun load() ...Read now
Unlock full access