diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 22:32:25 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-17 22:32:25 +0200 |
commit | a98f089035dbcc94c14c9cd6246c3150bee84241 (patch) | |
tree | 228ffa0d5e4a3e86c454cd297644c97abc994ef3 /src/scalevalapokalypsi/Client/Client.scala | |
parent | c954ca4d1ec677a34a6d787a23f9d01396f7e585 (diff) | |
download | scalevalapokalypsi-a98f089035dbcc94c14c9cd6246c3150bee84241.tar.gz scalevalapokalypsi-a98f089035dbcc94c14c9cd6246c3150bee84241.zip |
Improved client recovery from singing & added better logic for observations
The logic should still be implemented for all observations
Diffstat (limited to 'src/scalevalapokalypsi/Client/Client.scala')
-rw-r--r-- | src/scalevalapokalypsi/Client/Client.scala | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/scalevalapokalypsi/Client/Client.scala b/src/scalevalapokalypsi/Client/Client.scala index f37b1cc..aab6bc3 100644 --- a/src/scalevalapokalypsi/Client/Client.scala +++ b/src/scalevalapokalypsi/Client/Client.scala @@ -55,7 +55,7 @@ def newClient(name: String, ip: String, port: Int): Option[Client] = */ class Client(socket: Socket): - /** Essential IO variables */ + // Essential IO variables private val input = socket.getInputStream private val output = socket.getOutputStream private val buffer: Array[Byte] = Array.ofDim(MAX_MSG_SIZE) @@ -65,7 +65,7 @@ class Client(socket: Socket): private var serverLineState = ServerLineState.WaitingForTimeLimit - /** Variables about the status of the current turn for the client */ + // Variables about the status of the current turn for the client private var canAct = false // TODO: is really never true when it should private var timeLimit: Long = 0 private var lastTurnStart: Long = 0 @@ -100,7 +100,6 @@ class Client(socket: Socket): // TODO: we probably want to quit at EOF stdinReader.newLine().foreach((s: String) => - println("not singing anymore!") this.isSinging = false output.write(stringToByteArray(s+"\r\n")) ) @@ -127,16 +126,18 @@ class Client(socket: Socket): private def displayActions(): Unit = val somethingToShow = this.bufferedActions.nonEmpty - if !this.isSinging then - this.bufferedActions.foreach(println(_)) - this.bufferedActions.clear() - if !this.isSinging && this.canAct && somethingToShow then - print(this.actionGetterIndicator) + if somethingToShow then + if !this.isSinging then + this.bufferedActions.foreach(println(_)) + this.bufferedActions.clear() + if !this.isSinging && this.canAct && somethingToShow then + print(this.actionGetterIndicator) private def startSong(verse: String): Unit = this.isSinging = true print(s"\nLaula: “$verse”\n> ") + // TODO: this is sometimes in front of actions, use an indicator to test if newline before actions? private def actionGetterIndicator = val timeOfTurnEnd = this.lastTurnStart + this.timeLimit val timeToTurnEnd = -currentTimeMillis()/1000 + timeOfTurnEnd @@ -172,14 +173,11 @@ class Client(socket: Socket): case ServerLineState.ActionsAndSong => if line.headOption.exists(_.toString == SING_INDICATOR) then this.startSong(line.tail) - this.canAct = false else if line.headOption.contains(ACTION_BLOCKING_INDICATOR) then this.canAct = false this.bufferAction(line.tail) else if line.nonEmpty then this.bufferAction((line.tail)) - else - println("We should not get empty lines from the server!") case ServerLineState.TurnIndicator => this.serverLineState = ServerLineState.AreaDescription |