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