// Abstract class representing a starship
abstract class Starship(val name: String, var shieldStrength: Int, val phaserPower: Int) {
abstract fun attack(enemy: Starship)
open fun takeDamage(damage: Int) {
shieldStrength -= damage
if (shieldStrength <= 0) {
println("$name has been destroyed!")
}
}
}
// Interface to represent defensive systems
interface DefensiveSystem {
val shieldStrength: Int
fun reinforceShields()
} // Interface to represent communication protocols
interface Communication {
fun hail()
} // Class representing a Federation starship
class FederationStarship(name: String, shieldStrength: Int, phaserPower: Int) : Starship(name, shieldStrength, phaserPower), DefensiveSystem, Communication {
override fun attack(enemy: Starship) {
println("$name fires phasers ($phaserPower) at ${enemy.name}.")
enemy.takeDamage(phaserPower)
}
override fun reinforceShields() {
// Code to reinforce shields
println("$name is reinforcing shields.")
}
override fun hail() {
// Code to initiate communication
println("$name is initiating communication.")
}
} // Class representing a Romulan starship
class RomulanStarship(name: String, shieldStrength: Int, phaserPower: Int) : Starship(name, shieldStrength, phaserPower), DefensiveSystem {
override fun attack(enemy: Starship) {
println("$name fires phasers ($phaserPower) at ${enemy.name}.")
enemy.takeDamage(phaserPower)
}
override fun takeDamage(damage: Int) {
super.takeDamage(damage * 2) // Romulan ships have advanced shielding technology
}
override fun reinforceShields() {
// Code to reinforce shields
println("$name is reinforcing shields with advanced technology.")
}