aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/Model/Adventure.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 21:41:53 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 21:41:53 +0200
commitdef8975617e5c6da431e41cc889d167b0f2e2bb0 (patch)
treef538102c17d81b596834fad7f47528fe2fc04b19 /src/main/scala/Model/Adventure.scala
parent891b6f877ba848a3f78851a757734ebd1f066798 (diff)
downloadscalevalapokalypsi-def8975617e5c6da431e41cc889d167b0f2e2bb0.tar.gz
scalevalapokalypsi-def8975617e5c6da431e41cc889d167b0f2e2bb0.zip
Added possibility to join in the middle of the game & fixed bugs and inaccuracies:
* Adding the player didn't add it to the starting area. Fixed. * Refactored some code a bit by extracting functions * Changed the areas of `Adventure` to be private
Diffstat (limited to 'src/main/scala/Model/Adventure.scala')
-rw-r--r--src/main/scala/Model/Adventure.scala33
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. */