aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-14 19:52:24 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-14 19:52:24 +0200
commitea18a265a22ffc4c3f6ec3ca9d2f542552da9705 (patch)
treed1c9c832d9fdb2592227c5a05254a28d178a0efd
parenta43812ed462630850edbf29bda182fbf1e5e1263 (diff)
downloadscalevalapokalypsi-ea18a265a22ffc4c3f6ec3ca9d2f542552da9705.tar.gz
scalevalapokalypsi-ea18a265a22ffc4c3f6ec3ca9d2f542552da9705.zip
Added immediate turn start for client, required minor protocol tweak
-rw-r--r--protocol.txt1
-rw-r--r--src/main/scala/Client/Client.scala9
-rw-r--r--src/main/scala/Model/Adventure.scala3
-rw-r--r--src/main/scala/Server/Server.scala6
4 files changed, 11 insertions, 8 deletions
diff --git a/protocol.txt b/protocol.txt
index 7b13ab2..bbeae64 100644
--- a/protocol.txt
+++ b/protocol.txt
@@ -2,6 +2,7 @@ Client: [version number]CRLF[client name|]
Server: [good/version old]
...
Server: [time limit in int/secs]CRLF # signifies game start
+ [instantly gives turn info]
Before turn:
N x [Action blocker indicator][Description of action during previous turn]CRLF
diff --git a/src/main/scala/Client/Client.scala b/src/main/scala/Client/Client.scala
index e9d3074..7b0f8b2 100644
--- a/src/main/scala/Client/Client.scala
+++ b/src/main/scala/Client/Client.scala
@@ -17,7 +17,7 @@ import java.lang.System.currentTimeMillis
/** A helper enum for `Client` to keep track of communications with the server
*/
enum ServerLineState:
- case WaitingForGameStart,
+ case WaitingForTimeLimit,
ActionDescription,
TurnIndicator,
AreaDescription,
@@ -63,7 +63,7 @@ class Client(socket: Socket):
private val serverLineParser = ReceivedLineParser()
private val stdinReader = StdinLineReader()
- private var serverLineState = ServerLineState.WaitingForGameStart
+ private var serverLineState = ServerLineState.WaitingForTimeLimit
/** Variables about the status of the current turn for the client */
private var canAct = false
@@ -140,12 +140,13 @@ class Client(socket: Socket):
serverLineState match
- case ServerLineState.WaitingForGameStart =>
+ case ServerLineState.WaitingForTimeLimit =>
val time = line.toLongOption
time match
case Some(t) => this.timeLimit = t
case None => print("Invalid time limit, oh no!!!")
- this.serverLineState = ServerLineState.ActionDescription
+ this.serverLineState = ServerLineState.TurnIndicator
+ this.lastTurnStart = currentTimeMillis / 1000
case ServerLineState.ActionDescription =>
if line.head == ACTION_BLOCKING_INDICATOR then
diff --git a/src/main/scala/Model/Adventure.scala b/src/main/scala/Model/Adventure.scala
index 01f5d13..4d0a256 100644
--- a/src/main/scala/Model/Adventure.scala
+++ b/src/main/scala/Model/Adventure.scala
@@ -11,9 +11,6 @@ import scala.collection.mutable.Map
* games, you will need to modify or replace the source code of this class. */
class Adventure(val playerNames: Vector[String]):
- /** the name of the game */
- val title = "A Forest Adventure"
-
private val middle = Area("Forest", "You are somewhere in the forest. There are a lot of trees here.\nBirds are singing.")
private val northForest = Area("Forest", "You are somewhere in the forest. A tangle of bushes blocks further passage north.\nBirds are singing.")
private val southForest = Area("Forest", "The forest just goes on and on.")
diff --git a/src/main/scala/Server/Server.scala b/src/main/scala/Server/Server.scala
index a03bc53..5eb15cb 100644
--- a/src/main/scala/Server/Server.scala
+++ b/src/main/scala/Server/Server.scala
@@ -82,13 +82,17 @@ class Server(
assert(this.adventure.isDefined)
c.gameStart()
val name = c.getName
+
val entity: Option[Entity] = name match
case Some(n) => this.adventure match
case Some(a) => a.getPlayer(n)
case None => None
case None => None
entity.foreach(c.giveEntity(_))
- this.writeToClient(s"$timeLimit\r\n", c)
+
+ this.writeToClient(
+ s"$timeLimit\r\n${this.turnStartInfo(c)}", c
+ )
/** Helper function to determine if the next turn can be taken */