diff options
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Entity.scala')
-rw-r--r-- | src/scalevalapokalypsi/Model/Entities/Entity.scala | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/Entity.scala b/src/scalevalapokalypsi/Model/Entities/Entity.scala index 336a6b1..aa2a2e2 100644 --- a/src/scalevalapokalypsi/Model/Entities/Entity.scala +++ b/src/scalevalapokalypsi/Model/Entities/Entity.scala @@ -12,6 +12,7 @@ import scala.collection.immutable * @param initialLocation the Area where the entity is instantiated */ class Entity( + val adventure: Adventure, val name: String, initialLocation: Area, initialHP: Int = 100, @@ -31,10 +32,24 @@ class Entity( */ def getVerseAgainst: String = "Esimerkkirivi laulettavaksi" + def isAlive = this.hp > 0 + def takeDamage(amount: Int): Unit = hp -= amount - if hp < 0 then - println("Voi ei, kuolin!") + val event = if this.isAlive then + Event( + Vector(this -> this.condition(0)).toMap, + this.condition(1) + ) + else + println(s"Could remove myself: ${this.adventure.removeEntity(this.name)}") + Event( + Vector(this -> + "Olet täysin menettänyt toimintakykysi. Kaadut elottomana maahan." + ).toMap, + s"${this.name} kaatuu elottomana maahan." + ) + this.location.observeEvent(event) /** Returns a description of the physical condition of this entity, * i.e. the damage it has taken. |