From 98407b35ff477f372baa92bf582b90a961d4ad16 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Wed, 27 Nov 2024 12:29:43 +0200 Subject: Added part of story & improved singing with multiple verses & hemingway distance --- src/scalevalapokalypsi/Client/RoomState.scala | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/scalevalapokalypsi/Client/RoomState.scala') diff --git a/src/scalevalapokalypsi/Client/RoomState.scala b/src/scalevalapokalypsi/Client/RoomState.scala index 02fe11b..7eb3d5b 100644 --- a/src/scalevalapokalypsi/Client/RoomState.scala +++ b/src/scalevalapokalypsi/Client/RoomState.scala @@ -20,13 +20,22 @@ class RoomState: var visibleEntities: Array[String] = Array.empty override def toString: String = - val itemDesc = "You can see the following items: " + - this.visibleItems.mkString(", ") - val entityDesc = "The following entities reside in the room: " + - this.visibleEntities.mkString(", ") - val directionDesc = "There are exits to " + - this.possibleDirections.mkString(", ") - (s"$areaDescription\n$directionDesc\n" + - s"\n$itemDesc\n$entityDesc") + val directionDesc = iterableToString(this.possibleDirections) + .map(s => s"Täältä pääsee $s.\n") + .getOrElse("") + val itemDesc = iterableToString(this.visibleItems) + .map(s => s"Täällä on $s.\n") + .getOrElse("") + val entityDesc = iterableToString(this.visibleEntities) + .map(s => s"Seuraavat olennot ovat täällä: $s.\n") + .getOrElse("") + s"$areaDescription\n$directionDesc$itemDesc$entityDesc".dropRight(1) + + private def iterableToString(iterable: Iterable[String]): Option[String] = + Some("") + .map(_ + iterable.dropRight(1).mkString(", ")) + .map(_ + (if iterable.size >= 2 then " ja " else "")) + .map(_ + iterable.takeRight(1).headOption.getOrElse("")) + .filter(_ != "") end RoomState -- cgit v1.2.3