aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/main.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-09 16:32:09 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-09 16:32:09 +0200
commit129b49a3876ceb68f271c311d5e45efb2e205300 (patch)
tree246a47a5990167c73b95fc6e02452de7f6aca6b3 /src/main/scala/main.scala
parent239571e3408a3187953bef1dd5d516461bad0e31 (diff)
downloadscalevalapokalypsi-129b49a3876ceb68f271c311d5e45efb2e205300.tar.gz
scalevalapokalypsi-129b49a3876ceb68f271c311d5e45efb2e205300.zip
Made & implemented clearer protocol, added client functionality
Diffstat (limited to 'src/main/scala/main.scala')
-rw-r--r--src/main/scala/main.scala22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/main/scala/main.scala b/src/main/scala/main.scala
index 145dc1c..362c270 100644
--- a/src/main/scala/main.scala
+++ b/src/main/scala/main.scala
@@ -1,15 +1,25 @@
-import o1game.Client.Client
+import o1game.Client.newClient
import o1game.Server.Server
+import scala.concurrent.Future
+import scala.concurrent.ExecutionContext.Implicits.global
import scala.io.StdIn.readLine
// TODO: add proper logic for starting the game
@main def main(): Unit =
- print("Please choose:\n1) Client.Client\n2) Server\n> ")
- readLine().toIntOption match
- case Some(1) => Client("127.0.0.1", 2267).startClient()
- case Some(2) => Server(2267, 5, 30, true).startServer()
- case _ => println("Invalid input")
+ 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())
+ println("Server started in background.")
+ print("Choose a name:\n> ")
+ val name = readLine()
+ newClient(name, "127.0.0.1", 2267).map(_.startClient())
+ case Some(2) =>
+ print("Choose a name:\n> ")
+ val name = readLine()
+ newClient(name, "127.0.0.1", 2267).map(_.startClient())
+ case _ => println("Invalid input")