From a41c720736ae194f4c67637d9e822d2d4ded09f9 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Wed, 27 Nov 2024 17:49:14 +0200 Subject: Last commit from me --- src/scalevalapokalypsi/Server/Server.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/scalevalapokalypsi/Server') diff --git a/src/scalevalapokalypsi/Server/Server.scala b/src/scalevalapokalypsi/Server/Server.scala index d0bb402..6877876 100644 --- a/src/scalevalapokalypsi/Server/Server.scala +++ b/src/scalevalapokalypsi/Server/Server.scala @@ -55,6 +55,8 @@ class Server( this.writeClientDataToClients() this.writeObservations() this.endGameForDeadClients() + if adventure.exists(_.isWon) then + this.winGame() if this.canExecuteTurns then this.clients.foreach(_.giveTurn()) this.adventure.foreach(_.takeNpcTurns()) @@ -189,6 +191,26 @@ class Server( ) ) + private def winGame(): Unit = + this.clients.foreach(c => + val winEvent = c.player.map(p => Event( + Map.empty, + s"Onneksi olkoon, voititte pelin!" + )) + winEvent.foreach(ev => this.clients.foreach(cl => + if cl != c then + cl.player.foreach(_.observe(ev)) + )) + ) + sleep(1000) + this.clients.foreach(c => + c.player.foreach((p: Player) => + this.writeToClient(s"$GAME_END_INDICATOR\r\n", c) + false + ) + ) + + private def writeToClient(message: String, client: Client): Unit = try { -- cgit v1.2.3