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/Server/Server.scala | |
parent | 27dd937617cce1e43df1c16e12050f6e88763d54 (diff) | |
download | scalevalapokalypsi-38900e0b291d5e0f59afaaa239cd237f733b6588.tar.gz scalevalapokalypsi-38900e0b291d5e0f59afaaa239cd237f733b6588.zip |
Dying properly
Diffstat (limited to 'src/scalevalapokalypsi/Server/Server.scala')
-rw-r--r-- | src/scalevalapokalypsi/Server/Server.scala | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/scalevalapokalypsi/Server/Server.scala b/src/scalevalapokalypsi/Server/Server.scala index 2ea8bd4..16a2128 100644 --- a/src/scalevalapokalypsi/Server/Server.scala +++ b/src/scalevalapokalypsi/Server/Server.scala @@ -54,6 +54,7 @@ class Server( this.writeClientDataToClients() this.makeClientsSing() this.writeObservations() + this.endGameForDeadClients() if this.canExecuteTurns then this.clients.foreach(_.giveTurn()) this.adventure.foreach(_.takeNpcTurns()) @@ -183,6 +184,18 @@ class Server( output.flush() ) + private def endGameForDeadClients(): Unit = + this.clients.removeNonSatisfying(c => + c.player.forall((p: Player) => + if !p.isAlive then + this.writeToClient(s"$GAME_END_INDICATOR\r\n", c) + false + else + true + ) + ) + + private def writeToClient(message: String, client: Client): Unit = try { val output = client.socket.getOutputStream |