July 2018
Intermediate to advanced
400 pages
12h 14m
English
Now that you have organized NyetHack’s logic in functions, you can proceed as planned to implement the new fireball spell. At the bottom of Game.kt, define a function called castFireball that takes no parameters. Make its visibility private. castFireball should have no return statement, but it should print the results of casting the spell.
Listing 4.1 Adding a castFireball function (Game.kt)
...
private fun auraColor(isBlessed: Boolean,
healthPoints: Int,
isImmortal: Boolean): String {
val auraVisible = isBlessed && healthPoints > 50 || isImmortal
val auraColor = if (auraVisible) "GREEN" else "NONE"
return auraColor
}
private fun castFireball() {
println("A glass of Fireball springs into existence.") ...Read now
Unlock full access