diff options
Diffstat (limited to 'src/scalevalapokalypsi/Server/Server.scala')
-rw-r--r-- | src/scalevalapokalypsi/Server/Server.scala | 22 |
1 files changed, 22 insertions, 0 deletions
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 { |