package scalevalapokalypsi.Client /** `Turn`s represent information the client has got about a turn. * This class exists essentially so that the client has somewhere * to store data about turns and something to format that data with. */ class RoomState: /** Description of the area the player controlled by the client is in * at the end of the turn. */ var areaDescription: String = "" /** Directions the player controlled by the client can go to. */ var possibleDirections: Array[String] = Array.empty /** Items the player controlled by the client can see. */ var visibleItems: Array[String] = Array.empty /** Entities the player controlled by the client can see. */ var visibleEntities: Array[String] = Array.empty override def toString: String = 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