October 2021
Intermediate to advanced
500 pages
16h 23m
English
With the loot scaffolding in place, you are ready to scatter precious items throughout NyetHack for your player to collect and sell. Start out by giving the player pockets to store their valuables.
Listing 18.15 Adding an inventory (Player.kt)
class Player(
initialName: String,
val hometown: String = "Neversummer",
override var healthPoints: Int,
val isImmortal: Boolean
) : Fightable {
...
val prophecy by lazy {
...
}
val inventory = mutableListOf<Loot>()
var gold = 0
...
}
Next, add a companion object to LootBox and create a random function to randomly generate a variety of loot boxes for the player to discover.
Listing 18.16 Randomizing loot (Loot.kt)
class LootBox<out T : Loot>(val contents: ...
Read now
Unlock full access