la til ekstra information til constuktør

This commit is contained in:
Tobydrama 2020-04-06 17:10:11 +02:00
parent b644617a18
commit 700ebdeb6b

View File

@ -3,14 +3,18 @@ package inf112.fiasko.roborally.networking;
import com.esotericsoftware.kryonet.Client; import com.esotericsoftware.kryonet.Client;
import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener; 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 inf112.fiasko.roborally.utility.NetworkUtil;
import java.io.IOException; import java.io.IOException;
public class RoboRallyClient { public class RoboRallyClient {
Client client; Client client;
public RoboRallyClient(String IPaddresse) throws IOException { RoboRallyWrapper wrapper;
public RoboRallyClient(String IPaddresse,RoboRallyWrapper wrapper) throws IOException {
client = new Client(); client = new Client();
this.wrapper=wrapper;
client.start(); client.start();
NetworkUtil.registerClasses(client.getKryo()); NetworkUtil.registerClasses(client.getKryo());
client.connect(5000, IPaddresse, 54555, 54777); client.connect(5000, IPaddresse, 54555, 54777);
@ -19,7 +23,7 @@ public class RoboRallyClient {
request.text = "Here is the request"; request.text = "Here is the request";
client.sendTCP(request); client.sendTCP(request);
client.addListener(new RoboRallyClientListener()); client.addListener(new RoboRallyClientListener(wrapper));
} }
public void sendElement(Object obj) { public void sendElement(Object obj) {
client.sendTCP(obj); client.sendTCP(obj);
@ -27,6 +31,11 @@ public class RoboRallyClient {
} }
class RoboRallyClientListener extends Listener { class RoboRallyClientListener extends Listener {
RoboRallyWrapper wrapper;
public RoboRallyClientListener( RoboRallyWrapper wrapper){
super();
this.wrapper=wrapper;
}
@Override @Override
public void received (Connection connection, Object object) { public void received (Connection connection, Object object) {
if (object instanceof SomeResponse) { if (object instanceof SomeResponse) {
@ -36,6 +45,11 @@ class RoboRallyClientListener extends Listener {
ErrorResponse errorResponse = (ErrorResponse) object; ErrorResponse errorResponse = (ErrorResponse) object;
System.out.println(errorResponse.getErrorMessage()); 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);
}
} }
} }