From 700ebdeb6bf8a07e1afa720c30e1b4949a0d4fd9 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Mon, 6 Apr 2020 17:10:11 +0200 Subject: [PATCH] =?UTF-8?q?la=20til=20ekstra=20information=20til=20constuk?= =?UTF-8?q?t=C3=B8r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/networking/RoboRallyClient.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java index 0c1f806..e151ab4 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java @@ -3,14 +3,18 @@ package inf112.fiasko.roborally.networking; import com.esotericsoftware.kryonet.Client; import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Listener; +import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper; +import inf112.fiasko.roborally.objects.RoboRallyGame; import inf112.fiasko.roborally.utility.NetworkUtil; import java.io.IOException; public class RoboRallyClient { Client client; - public RoboRallyClient(String IPaddresse) throws IOException { + RoboRallyWrapper wrapper; + public RoboRallyClient(String IPaddresse,RoboRallyWrapper wrapper) throws IOException { client = new Client(); + this.wrapper=wrapper; client.start(); NetworkUtil.registerClasses(client.getKryo()); client.connect(5000, IPaddresse, 54555, 54777); @@ -19,7 +23,7 @@ public class RoboRallyClient { request.text = "Here is the request"; client.sendTCP(request); - client.addListener(new RoboRallyClientListener()); + client.addListener(new RoboRallyClientListener(wrapper)); } public void sendElement(Object obj) { client.sendTCP(obj); @@ -27,6 +31,11 @@ public class RoboRallyClient { } class RoboRallyClientListener extends Listener { + RoboRallyWrapper wrapper; + public RoboRallyClientListener( RoboRallyWrapper wrapper){ + super(); + this.wrapper=wrapper; + } @Override public void received (Connection connection, Object object) { if (object instanceof SomeResponse) { @@ -36,6 +45,11 @@ class RoboRallyClientListener extends Listener { ErrorResponse errorResponse = (ErrorResponse) object; System.out.println(errorResponse.getErrorMessage()); } + else if(object instanceof GameStartInfo){ + GameStartInfo info = (GameStartInfo) object; + wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerlist(),info.getBoardname(), + wrapper.server!=null); + } } }