diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-27 17:49:14 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-27 17:49:42 +0200 |
commit | a41c720736ae194f4c67637d9e822d2d4ded09f9 (patch) | |
tree | ceee825b2b53f2e1babee842ab45e397b88f6cf7 /src/scalevalapokalypsi/Server/Server.scala | |
parent | b50a8e42b6b69ce4e15773c73cf68d2ac8f2175d (diff) | |
download | scalevalapokalypsi-master.tar.gz scalevalapokalypsi-master.zip |
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 { |