aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities/Player.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Player.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Player.scala23
1 files changed, 23 insertions, 0 deletions
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