diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 17:06:56 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 17:06:56 +0200 |
commit | c954ca4d1ec677a34a6d787a23f9d01396f7e585 (patch) | |
tree | c6b00b5046bde3a98c18f9557198f852b4ce9d46 /src/scalevalapokalypsi/Model/Entities/Entity.scala | |
parent | a6b0330c845d4edad87c7059bac56e194a276c6f (diff) | |
download | scalevalapokalypsi-c954ca4d1ec677a34a6d787a23f9d01396f7e585.tar.gz scalevalapokalypsi-c954ca4d1ec677a34a6d787a23f9d01396f7e585.zip |
Template for singing, WIP.
* The line to sing is always the same.
* The client recovers weirdly from singing before the next turn and my brain is currently too fried to figure out why
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Entity.scala')
-rw-r--r-- | src/scalevalapokalypsi/Model/Entities/Entity.scala | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/Entity.scala b/src/scalevalapokalypsi/Model/Entities/Entity.scala index b90a61a..1592f2e 100644 --- a/src/scalevalapokalypsi/Model/Entities/Entity.scala +++ b/src/scalevalapokalypsi/Model/Entities/Entity.scala @@ -1,22 +1,44 @@ package scalevalapokalypsi.Model.Entities -import scala.collection.mutable.Map +import scala.collection.mutable.{Buffer,Map} import scalevalapokalypsi.Model.* + /** An in-game entity. * * @param name the name of the entity * @param initialLocation the Area where the entity is instantiated */ -class Entity(val name: String, initialLocation: Area): +class Entity( + val name: String, + initialLocation: Area, + initialHP: Int = 100, + val maxHP: Int = 100 +): + private var currentLocation: Area = initialLocation private var quitCommandGiven = false // one-way flag private val inventory: Map[String, Item] = Map() + private var hp = initialHP + + def takeDamage(amount: Int): Unit = + hp -= amount + if hp < 0 then + println("Oh no, I died!") + + def condition: String = + if hp < maxHP * .25 then + s"$name näyttää maansa myyneeltä." + else if hp < maxHP * .50 then + s"$name näyttää sinnittelevän yhä." + else if hp < maxHP * .75 then + s"$name näyttää aavistuksen lannistuneelta." + else + s"$name on yhä täysissä voimissaan." /** Does nothing, except possibly in inherited classes. */ def observe(observation: String): Unit = - println("no observation made.") - () + println("[debug] entity got observation & discarded it") /** Returns the player’s current location. */ def location = this.currentLocation |