diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-09 22:32:01 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2024-11-09 22:32:01 +0200 |
commit | c87263e9e493fe6c130f5ad6a523871c08987f4c (patch) | |
tree | d7ee9df308a80c7a1b58ae413a7e5217fba89e6c | |
parent | 129b49a3876ceb68f271c311d5e45efb2e205300 (diff) | |
download | scalevalapokalypsi-c87263e9e493fe6c130f5ad6a523871c08987f4c.tar.gz scalevalapokalypsi-c87263e9e493fe6c130f5ad6a523871c08987f4c.zip |
Minor change in concurrency model
-rw-r--r-- | src/main/scala/Client/Client.scala | 9 | ||||
-rw-r--r-- | src/main/scala/main.scala | 3 |
2 files changed, 4 insertions, 8 deletions
diff --git a/src/main/scala/Client/Client.scala b/src/main/scala/Client/Client.scala index ef98ef3..2503cdf 100644 --- a/src/main/scala/Client/Client.scala +++ b/src/main/scala/Client/Client.scala @@ -147,24 +147,19 @@ class Client(socket: Socket): val directionDesc = "There are exits to " + this.possibleDirections.mkString(", ") (s"\n$actionDesc\n\n$areaDescription\n$directionDesc\n" + - s"\n$itemDesc\n$entityDesc") + s"\n$itemDesc\n$entityDesc\n") def startClient(): Unit = stdinReader.startReading() - // TODO: read data from server and store it in the turn description - // TODO: if turn isn't executed since lastturnstart, display the data - // and clean STDIN - // TODO: write data from stdin and send it to the server - // TODO: display timer to next turn end while true do sleep(POLL_INTERVAL) this.readAndParseDataFromServer() if this.lastExecutedTurn < this.lastTurnStart then - println(this.giveTurn()) + print(this.giveTurn()) stdinReader.newLine().foreach((s: String) => output.write(stringToByteArray(s+"\r\n")) diff --git a/src/main/scala/main.scala b/src/main/scala/main.scala index 362c270..d68664a 100644 --- a/src/main/scala/main.scala +++ b/src/main/scala/main.scala @@ -1,6 +1,7 @@ import o1game.Client.newClient import o1game.Server.Server +import java.lang.Thread import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global @@ -11,7 +12,7 @@ import scala.io.StdIn.readLine print("How do you want to play?\n1) Host and join local game\n2) Join local game\n> ") readLine().toIntOption match case Some(1) => - Future(Server(2267, 5, 30, true).startServer()) + Thread(() => Server(2267, 5, 30, true).startServer()).start() println("Server started in background.") print("Choose a name:\n> ") val name = readLine() |