From 8595e892abc0e0554f589ed2eb88c351a347fbd4 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 17 Nov 2024 02:38:55 +0200 Subject: Implemented talking --- src/main/scala/Model/Area.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/scala/Model/Area.scala') diff --git a/src/main/scala/Model/Area.scala b/src/main/scala/Model/Area.scala index 5a8de2a..6721957 100644 --- a/src/main/scala/Model/Area.scala +++ b/src/main/scala/Model/Area.scala @@ -22,7 +22,8 @@ class Area(val name: String, var description: String): def getNeighborNames: Iterable[String] = this.neighbors.keys def getItemNames: Iterable[String] = this.items.keys - def getEntityNames: Iterable[String] = this.entities.keys + def getEntityNames: Iterable[String] = this.entities.values.map(_.name) + def getEntity(name: String): Option[Entity] = this.entities.get(name) def getEntities: Iterable[Entity] = this.entities.values /** Tells whether this area has a neighbor in the given direction. @@ -73,7 +74,8 @@ class Area(val name: String, var description: String): * * @param entity the entity to add. */ - def addEntity(entity: Entity): Unit = this.entities += entity.name -> entity + def addEntity(entity: Entity): Unit = + this.entities += entity.name.toLowerCase -> entity /** Removes the entity with the name `entityName`. * @@ -81,7 +83,7 @@ class Area(val name: String, var description: String): * @return an option containing the removed entity if it was in the area */ def removeEntity(entityName: String): Option[Entity] = - this.entities.remove(entityName) + this.entities.remove(entityName.toLowerCase()) /** Returns a multi-line description of the area as a player sees it. This includes a basic * description of the area as well as information about exits and items. If there are no @@ -92,7 +94,7 @@ class Area(val name: String, var description: String): def fullDescription: String = val exitList = this.neighbors.keys.mkString(" ") val itemList = this.items.keys.mkString(" ") - val entityList = this.entities.keys.mkString(" ") + val entityList = this.getEntityNames.mkString(" ") val itemDescription = if this.items.nonEmpty then s"\nYou see here: ${itemList}" -- cgit v1.2.3