diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-26 14:03:23 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-26 14:10:45 +0200 |
commit | 38900e0b291d5e0f59afaaa239cd237f733b6588 (patch) | |
tree | ee04f697ab17a75c9563ee87763cbcdcde8d297b /src/scalevalapokalypsi/Model/Adventure.scala | |
parent | 27dd937617cce1e43df1c16e12050f6e88763d54 (diff) | |
download | scalevalapokalypsi-38900e0b291d5e0f59afaaa239cd237f733b6588.tar.gz scalevalapokalypsi-38900e0b291d5e0f59afaaa239cd237f733b6588.zip |
Dying properly
Diffstat (limited to 'src/scalevalapokalypsi/Model/Adventure.scala')
-rw-r--r-- | src/scalevalapokalypsi/Model/Adventure.scala | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/scalevalapokalypsi/Model/Adventure.scala b/src/scalevalapokalypsi/Model/Adventure.scala index ba45abe..b10f7d9 100644 --- a/src/scalevalapokalypsi/Model/Adventure.scala +++ b/src/scalevalapokalypsi/Model/Adventure.scala @@ -46,7 +46,7 @@ class Adventure(val playerNames: Vector[String]): ("Rotten zombie", tangle, 10) ) zombieAttrs.foreach(z => - val zombie = Zombie(z(0), z(1), z(2)) + val zombie = Zombie(this, z(0), z(1), z(2)) npcs += z(0) -> zombie z(1).addEntity(zombie) ) @@ -54,7 +54,7 @@ class Adventure(val playerNames: Vector[String]): def takeNpcTurns(): Unit = npcs.values.foreach(_.act()) - private val gruu = Entity("Gruu", northForest) + private val gruu = Entity(this, "Gruu", northForest) northForest.addEntity(gruu) this.entities += gruu.name -> gruu @@ -67,12 +67,29 @@ class Adventure(val playerNames: Vector[String]): * @return the created player entity */ def addPlayer(name: String): Player = - val newPlayer = Player(name, middle) + val newPlayer = Player(this, name, middle) middle.addEntity(newPlayer) this.entities += name -> newPlayer players += name -> newPlayer newPlayer - + + /** Removes the given entity without further observations. Makes sense in the + * game mostly if the entity's HP is nonpositive. + * + * Removes the entity both from the adventure and the game world + * (i.e. the entitys area). + * + * @param name the name of the entity to remove + * @return whether there was an entity to remove with the given name + */ + def removeEntity(name: String): Boolean = + this.players.remove(name) + this.entities.remove(name).orElse(this.npcs.remove(name)) match + case Some(e) => + e.location.removeEntity(name) + true + case None => false + /** Gets the player entity with the specified name. * * @param name name of the player to find |