October 2021
Intermediate to advanced
500 pages
16h 23m
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, to avoid naming collisions – and define a Fightable interface, using the keyword interface:
Listing 17.1 Defining an interface (Creature.kt)
interface Fightable {
val name: String
var healthPoints: Int
val diceCount: Int
val diceSides: Int
fun takeDamage(damage: Int)
fun attack(opponent: Fightable)
}
Your interface declaration ...
Read now
Unlock full access