aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Client/RoomState.scala
diff options
context:
space:
mode:
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