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