From 38900e0b291d5e0f59afaaa239cd237f733b6588 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Tue, 26 Nov 2024 14:03:23 +0200 Subject: Dying properly --- src/scalevalapokalypsi/Server/Server.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/scalevalapokalypsi/Server/Server.scala') 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 -- cgit v1.2.3