diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 02:38:55 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 02:38:55 +0200 |
commit | 8595e892abc0e0554f589ed2eb88c351a347fbd4 (patch) | |
tree | d86a85243be6719f30646094e7a86e5d3d87aa68 /src/main/scala/Model/Entity.scala | |
parent | e0e720c1b78506f1f9c00e2d275caa170becc927 (diff) | |
download | scalevalapokalypsi-8595e892abc0e0554f589ed2eb88c351a347fbd4.tar.gz scalevalapokalypsi-8595e892abc0e0554f589ed2eb88c351a347fbd4.zip |
Implemented talking
Diffstat (limited to 'src/main/scala/Model/Entity.scala')
-rw-r--r-- | src/main/scala/Model/Entity.scala | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main/scala/Model/Entity.scala b/src/main/scala/Model/Entity.scala index 37fdbc2..d8e8559 100644 --- a/src/main/scala/Model/Entity.scala +++ b/src/main/scala/Model/Entity.scala @@ -52,7 +52,8 @@ class Entity(val name: String, initialLocation: Area): def go(direction: String): (String, String) = val destination = this.location.neighbor(direction) if destination.isDefined then - this.currentLocation.removeEntity(this.name) + val removeSuccess = this.currentLocation.removeEntity(this.name) + assert(removeSuccess.isDefined) // Production - assertions off this.currentLocation = destination.getOrElse(this.currentLocation) destination.foreach(_.addEntity(this)) (s"You go $direction.", s"$name goes $direction") @@ -76,6 +77,13 @@ class Entity(val name: String, initialLocation: Area): (s"You drop the $itemName", s"$name drops the $itemName") case None => ("You don't have that!", s"$name reaches their backpack to drop $itemName but miserably fails to find it there.") + def sayTo(entity: Entity, message: String): (String, String) = + entity.observe(s"Alice: \"$message\"") + (s"You say so to ${entity.name}.", "") + + def say(message: String): (String, String) = + ("You say that aloud.", s"$name: \"$message\"") + /** Tells whether this entity can drop the specified item * (if an action were to specify so). * |