From 129b49a3876ceb68f271c311d5e45efb2e205300 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 9 Nov 2024 16:32:09 +0200 Subject: Made & implemented clearer protocol, added client functionality --- src/main/scala/main.scala | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/main/scala/main.scala') 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") -- cgit v1.2.3