July 2018
Intermediate to advanced
400 pages
12h 14m
English
To define how combat is performed, you will first create an interface that specifies the functions and properties used for entities in the game when performing combat. Your player will face goblins, but you will define a combat system that can be applied to any type of creature – not just goblins.
Create a new file called Creature.kt in the com.bignerdranch.nyethack package (remember that this pattern is to avoid naming collisions), and define a Fightable interface, using the keyword interface:
Listing 16.1 Defining an interface (Creature.kt)
interface Fightable {
var healthPoints: Int
val diceCount: Int
val diceSides: Int
val damageRoll: Int
fun attack(opponent: Fightable): Int
}
Your interface declaration ...
Read now
Unlock full access