diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-15 16:45:09 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-15 16:45:09 +0200 |
commit | eeb83ca379e7f4ab1a86596b80e206df48371454 (patch) | |
tree | 0f595308b7ba9077650e8a368b94ba75c5683c71 /src/main/scala/Model/Action.scala | |
parent | ea18a265a22ffc4c3f6ec3ca9d2f542552da9705 (diff) | |
download | scalevalapokalypsi-eeb83ca379e7f4ab1a86596b80e206df48371454.tar.gz scalevalapokalypsi-eeb83ca379e7f4ab1a86596b80e206df48371454.zip |
Added observations for Players in model & implemented sending them to other clients
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)" |