package scalevalapokalypsi.Model.Entities import scala.collection.mutable.Buffer import scalevalapokalypsi.Model.* /** A `Player` object represents a player character controlled by one real-life player * of the program. * * A player object’s state is mutable: the player’s location and possessions can change, * for instance. * * @param name the player's name * @param initialLocation the player’s initial location */ 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) def readAndClearObservations(): Vector[String] = 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