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 | |
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')
-rw-r--r-- | src/scalevalapokalypsi/Model/Entities/Entity.scala | 30 | ||||
-rw-r--r-- | src/scalevalapokalypsi/Model/Entities/Player.scala | 23 |
2 files changed, 49 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 diff --git a/src/scalevalapokalypsi/Model/Entities/Player.scala b/src/scalevalapokalypsi/Model/Entities/Player.scala index 6e82837..7e441c1 100644 --- a/src/scalevalapokalypsi/Model/Entities/Player.scala +++ b/src/scalevalapokalypsi/Model/Entities/Player.scala @@ -15,6 +15,7 @@ import scalevalapokalypsi.Model.* class Player(name: String, initialLocation: Area) extends Entity(name, initialLocation): private val observations: Buffer[String] = Buffer.empty + private var pendingSingEffect: Option[Float => String] = None override def observe(observation: String): Unit = this.observations.append(observation) @@ -23,5 +24,27 @@ class Player(name: String, initialLocation: Area) extends Entity(name, initialLo val res = this.observations.toVector observations.clear() res + + /** Returns whether this player has a pending sing effect. */ + def isSinging: Boolean = this.pendingSingEffect.isDefined + /** Makes this player start singing, i.e. gives it this sing effect to + * complete. + * + * @param effect the effect to apply based on the song. + */ + def setSingEffect(effect: Float => String): Unit = + this.pendingSingEffect = Some(effect) + + /** Applies the pending sing effect. + * + * @param singQuality the quality of the song + * @return a textual description of the effects of the song, + * or None if there was no pending sing effect. + */ + def applySingEffect(singQuality: Float): Option[String] = + val res = this.pendingSingEffect.map(f => f(singQuality)) + this.pendingSingEffect = None + res + end Player |