aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Client/RoomState.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 12:29:43 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 12:29:43 +0200
commit98407b35ff477f372baa92bf582b90a961d4ad16 (patch)
treebb58925090075d1e9e30dd1593547db2cbe03bb6 /src/scalevalapokalypsi/Client/RoomState.scala
parent38900e0b291d5e0f59afaaa239cd237f733b6588 (diff)
downloadscalevalapokalypsi-98407b35ff477f372baa92bf582b90a961d4ad16.tar.gz
scalevalapokalypsi-98407b35ff477f372baa92bf582b90a961d4ad16.zip
Added part of story & improved singing with multiple verses & hemingway distance
Diffstat (limited to 'src/scalevalapokalypsi/Client/RoomState.scala')
-rw-r--r--src/scalevalapokalypsi/Client/RoomState.scala25
1 files changed, 17 insertions, 8 deletions
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