aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities/Entity.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Entity.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Entity.scala30
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