Choosing interfaces for a given class

Report a typo

Imagine we're involved in some kind of game development, and you're working on a fantasy-genre game, which involves defining statistics and actions for different characters, monsters, and NPCs...

Choosing interfaces for a given class

The programmers of the team have provided you with a bunch of interfaces, such as Melee for the characters who attack with melee weapons, while the team's game designers (not very familiar with the programmers) created classes of in-game entities they would like to add, listing required functions and properties. The thing is, for the whole system to work, interfaces must be connected to game entities: therefore, your task is to check the functionality of the interfaces and add the interfaces to the list of inheritance or implementation of the provided classes. For example, the game designers made an Archer class:

class Archer: // ?
{  
 // Hm this seems to be a part of "Ranged" interface...  
 override var usesAmmo: Boolean = true  
 override var ammoAmount: Int = 20  
 override var hp: Int = 3  
 override var armorClass: Int = 10  
  
 // And that corresponds to "NPC"!  
 override val xp: Int = 5  
 override var location: String = "Camp"  
}

Therefore, you'll need to add the following interfaces to the class:

class Archer: Ranged, NPC {
 override var usesAmmo: Boolean = true
...
Write a program in Kotlin
interface Entity {
var hp: Int
var armorClass: Int
}

interface NPC : Entity {
val xp: Int
var location: String
}

interface Magical : Entity {
var mana: Int
var hasSpells: Boolean
}

interface Divine : Entity {
var mana: Int
var hasPowers: Boolean
}

interface Ranged : Entity {
var usesAmmo: Boolean
var ammoAmount: Int
fun rangedAttack() {}
fun retreat() {}
}

interface Melee : Entity {
var amountOfWeapons: Int
fun meleeAttack() {}
fun meleeDodge() {}
fun sheatheWeapon() {}
}

interface Healing {
fun healAlly() {}
___

Create a free account to access the full topic