mirror of
				https://github.com/inf112-v20/Fiasko.git
				synced 2025-11-04 03:33:45 +01:00 
			
		
		
		
	La til noen metoder for å gi spillernavn videre til de klassene som trenger dem.
This commit is contained in:
		@@ -8,8 +8,9 @@ import inf112.fiasko.roborally.utility.NetworkUtil;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
public class RoboRallyClient {
 | 
			
		||||
    Client client;
 | 
			
		||||
    public RoboRallyClient(String IPaddresse) throws IOException {
 | 
			
		||||
        Client client = new Client();
 | 
			
		||||
        client = new Client();
 | 
			
		||||
        client.start();
 | 
			
		||||
        NetworkUtil.registerClasses(client.getKryo());
 | 
			
		||||
        client.connect(5000, IPaddresse, 54555, 54777);
 | 
			
		||||
@@ -20,6 +21,9 @@ public class RoboRallyClient {
 | 
			
		||||
 | 
			
		||||
        client.addListener(new RoboRallyClientListener());
 | 
			
		||||
    }
 | 
			
		||||
    public void sendElement(Object obj) {
 | 
			
		||||
        client.sendTCP(obj);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class RoboRallyClientListener extends Listener {
 | 
			
		||||
@@ -33,4 +37,5 @@ class RoboRallyClientListener extends Listener {
 | 
			
		||||
            System.out.println(errorResponse.getErrorMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,13 @@ public class RoboRallyServer {
 | 
			
		||||
        programmingCardDeck = DeckLoaderUtil.loadProgrammingCardsDeck();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Map<Connection, RobotID> getRobotID() {
 | 
			
		||||
        return listener.getRobotID();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Map<Connection, String> getPlayerNames() {
 | 
			
		||||
        return listener.getPlayerNames();
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Sends an object to all clients
 | 
			
		||||
     * @param object The object to send
 | 
			
		||||
@@ -54,10 +61,20 @@ public class RoboRallyServer {
 | 
			
		||||
class RoboRallyServerListener extends Listener {
 | 
			
		||||
    protected Connection host;
 | 
			
		||||
    protected Map<Connection, RobotID> clients;
 | 
			
		||||
    protected Map<Connection, String> playerNames;
 | 
			
		||||
 | 
			
		||||
    public RoboRallyServerListener() {
 | 
			
		||||
        super();
 | 
			
		||||
        clients = new HashMap<>();
 | 
			
		||||
        playerNames = new HashMap<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Map<Connection, String> getPlayerNames() {
 | 
			
		||||
        return playerNames;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Map<Connection, RobotID> getRobotID() {
 | 
			
		||||
        return clients;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -70,6 +87,10 @@ class RoboRallyServerListener extends Listener {
 | 
			
		||||
            response.text = "Thanks";
 | 
			
		||||
            connection.sendTCP(response);
 | 
			
		||||
        }
 | 
			
		||||
        else if (object instanceof String) {
 | 
			
		||||
            String playerName = (String) object;
 | 
			
		||||
            playerNames.put(connection, playerName);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user