From c954ca4d1ec677a34a6d787a23f9d01396f7e585 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 17 Nov 2024 17:06:56 +0200 Subject: 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 --- src/scalevalapokalypsi/Model/Entities/Player.scala | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/scalevalapokalypsi/Model/Entities/Player.scala') 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 -- cgit v1.2.3