diff options
Diffstat (limited to 'src/scalevalapokalypsi/Client')
-rw-r--r-- | src/scalevalapokalypsi/Client/Client.scala | 6 | ||||
-rw-r--r-- | src/scalevalapokalypsi/Client/RoomState.scala | 25 |
2 files changed, 22 insertions, 9 deletions
diff --git a/src/scalevalapokalypsi/Client/Client.scala b/src/scalevalapokalypsi/Client/Client.scala index 5364405..1ca4e7e 100644 --- a/src/scalevalapokalypsi/Client/Client.scala +++ b/src/scalevalapokalypsi/Client/Client.scala @@ -189,7 +189,11 @@ class Client(socket: Socket): this.serverLineState = ServerLineState.Directions case ServerLineState.Directions => - this.turnInfo.possibleDirections = line.split(LIST_SEPARATOR) + val dirs = line.split(LIST_SEPARATOR) + if dirs(0) == "" && dirs.length == 1 then + this.turnInfo.possibleDirections = Array.empty + else + this.turnInfo.possibleDirections = dirs this.serverLineState = ServerLineState.Items case ServerLineState.Items => 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 |