mirror of
				https://github.com/inf112-v20/Fiasko.git
				synced 2025-11-04 03:33:45 +01:00 
			
		
		
		
	la til ekstra information til constuktør
This commit is contained in:
		@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user