diff options
Diffstat (limited to 'src/main/scala/Model/Adventure.scala')
-rw-r--r-- | src/main/scala/Model/Adventure.scala | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/main/scala/Model/Adventure.scala b/src/main/scala/Model/Adventure.scala index c13ff47..01f5d13 100644 --- a/src/main/scala/Model/Adventure.scala +++ b/src/main/scala/Model/Adventure.scala @@ -14,13 +14,13 @@ class Adventure(val playerNames: Vector[String]): /** the name of the game */ val title = "A Forest Adventure" - /*private*/ val middle = Area("Forest", "You are somewhere in the forest. There are a lot of trees here.\nBirds are singing.") - /*private*/ val northForest = Area("Forest", "You are somewhere in the forest. A tangle of bushes blocks further passage north.\nBirds are singing.") - /*private*/ val southForest = Area("Forest", "The forest just goes on and on.") - /*private*/ val clearing = Area("Forest Clearing", "You are at a small clearing in the middle of forest.\nNearly invisible, twisted paths lead in many directions.") - /*private*/ val tangle = Area("Tangle of Bushes", "You are in a dense tangle of bushes. It's hard to see exactly where you're going.") - /*private*/ val home = Area("Home", "Home sweet home! Now the only thing you need is a working remote control.") - /*private*/ val destination = home + private val middle = Area("Forest", "You are somewhere in the forest. There are a lot of trees here.\nBirds are singing.") + private val northForest = Area("Forest", "You are somewhere in the forest. A tangle of bushes blocks further passage north.\nBirds are singing.") + private val southForest = Area("Forest", "The forest just goes on and on.") + private val clearing = Area("Forest Clearing", "You are at a small clearing in the middle of forest.\nNearly invisible, twisted paths lead in many directions.") + private val tangle = Area("Tangle of Bushes", "You are in a dense tangle of bushes. It's hard to see exactly where you're going.") + private val home = Area("Home", "Home sweet home! Now the only thing you need is a working remote control.") + private val destination = home middle.setNeighbors(Vector("north" -> northForest, "east" -> tangle, "south" -> southForest, "west" -> clearing)) northForest.setNeighbors(Vector("east" -> tangle, "south" -> middle, "west" -> clearing)) @@ -38,7 +38,24 @@ class Adventure(val playerNames: Vector[String]): )) val players: Map[String, Entity] = Map() - playerNames.foreach(name => players += name -> Entity(name, middle)) + playerNames.foreach(this.addPlayer(_)) + + /** Adds a player entity with the specified name to the game. + * + * @param name the name of the player entity to add + * @return the created player entity + */ + def addPlayer(name: String): Entity = + val newPlayer = Entity(name, middle) + middle.addEntity(newPlayer) + players += name -> newPlayer + newPlayer + + /** Gets the player entity with the specified name. + * + * @param name name of the player to find + * @return the player, if one with the name was found + */ def getPlayer(name: String): Option[Entity] = this.players.get(name) /** Returns a message that is to be displayed to the player at the beginning of the game. */ |