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/Adventure.scala | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/scala/Model/Adventure.scala') diff --git a/src/main/scala/Model/Adventure.scala b/src/main/scala/Model/Adventure.scala index 7d5a061..dfcb100 100644 --- a/src/main/scala/Model/Adventure.scala +++ b/src/main/scala/Model/Adventure.scala @@ -1,6 +1,7 @@ package o1game.Model import scala.collection.mutable.Map + /** The class `Adventure` represents text adventure games. An adventure consists of a player and * a number of areas that make up the game world. It provides methods for playing the game one * turn at a time and for checking the state of the game. @@ -38,6 +39,9 @@ class Adventure(val playerNames: Vector[String]): playerNames.foreach(this.addPlayer(_)) val entities: Map[String, Entity] = Map() + private val gruu = Entity("Gruu", northForest) + northForest.addEntity(gruu) + this.entities += gruu.name -> gruu /** Adds a player entity with the specified name to the game. * @@ -57,6 +61,9 @@ class Adventure(val playerNames: Vector[String]): */ def getPlayer(name: String): Option[Player] = this.players.get(name) + def getEntity[A >: Entity](name: String) = + this.players.getOrElse(name, this.entities.get(name)) + /** Returns a message that is to be displayed to the player at the beginning of the game. */ def welcomeMessage = "Generic welcome message" -- cgit v1.2.3