diff options
Diffstat (limited to 'src/main/scala/Model/Action.scala')
-rw-r--r-- | src/main/scala/Model/Action.scala | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main/scala/Model/Action.scala b/src/main/scala/Model/Action.scala index 11b0bc8..9f81256 100644 --- a/src/main/scala/Model/Action.scala +++ b/src/main/scala/Model/Action.scala @@ -23,15 +23,30 @@ class Action(input: String): * of the action (such as “You go west.”). The description is returned in an `Option` * wrapper; if the command was not recognized, `None` is returned. */ def execute(actor: Entity): Option[String] = - this.verb match + val oldLocation = actor.location + val resOption: Option[(String, String)] = this.verb match case "go" => Some(actor.go(this.modifiers)) case "rest" => Some(actor.rest()) case "get" => Some(actor.pickUp(this.modifiers)) case "drop" => Some(actor.drop(this.modifiers)) - case "xyzzy" => Some("The grue tastes yummy.") - case "quit" => Some(actor.quit()) + case "xyzzy" => Some(( + "The grue tastes yummy.", + s"${actor.name} tastes some grue.") + ) case other => None +// println(resOption) +// println(actor.location.getEntities) + resOption.map(_(1)).filter(_.length > 0) + .foreach(s => + actor.location.getEntities.filter(_ != actor).foreach(_.observe(s)) + if oldLocation != actor.location then + oldLocation.getEntities.foreach(_.observe(s)) + ) + + resOption.map(_(0)) + + /** Returns a textual description of the action object, for debugging purposes. */ override def toString = s"$verb (modifiers: $modifiers)" |