merge Development into test #27
@@ -6,6 +6,10 @@
|
|||||||
import pp.mdga.client.animation.AnimationHandler;
|
import pp.mdga.client.animation.AnimationHandler;
|
||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
import pp.mdga.client.view.*;
|
import pp.mdga.client.view.*;
|
||||||
|
import pp.mdga.message.server.ServerInterpreter;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main application class for the MdgaApp game.
|
* Main application class for the MdgaApp game.
|
||||||
@@ -49,6 +53,18 @@ public class MdgaApp extends SimpleApplication {
|
|||||||
/** The ceremony view. */
|
/** The ceremony view. */
|
||||||
private MdgaView ceremonyView;
|
private MdgaView ceremonyView;
|
||||||
|
|
||||||
|
/** The client game logic. */
|
||||||
|
private final ClientGameLogic clientGameLogic;
|
||||||
|
|
||||||
|
private ExecutorService executor;
|
||||||
|
|
||||||
|
private ServerConnection networkConnection;
|
||||||
|
|
||||||
|
private MdgaApp() {
|
||||||
|
networkConnection = new NetworkSupport(this);
|
||||||
|
this.clientGameLogic = new ClientGameLogic(networkConnection);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point for the application.
|
* Main entry point for the application.
|
||||||
* Configures settings and starts the application.
|
* Configures settings and starts the application.
|
||||||
@@ -59,8 +75,8 @@ public static void main(String[] args) {
|
|||||||
AppSettings settings = new AppSettings(true);
|
AppSettings settings = new AppSettings(true);
|
||||||
settings.setSamples(128);
|
settings.setSamples(128);
|
||||||
settings.setCenterWindow(true);
|
settings.setCenterWindow(true);
|
||||||
settings.setWidth(1920);
|
settings.setWidth(1080);
|
||||||
settings.setHeight(1080);
|
settings.setHeight(720);
|
||||||
settings.setVSync(false);
|
settings.setVSync(false);
|
||||||
|
|
||||||
MdgaApp app = new MdgaApp();
|
MdgaApp app = new MdgaApp();
|
||||||
@@ -219,5 +235,22 @@ public NotificationSynchronizer getNotificationSynchronizer() {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientGameLogic getGameLogic() {
|
||||||
|
return clientGameLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ExecutorService getExecutor() {
|
||||||
|
if (this.executor == null) {
|
||||||
|
this.executor = Executors.newCachedThreadPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerConnection getNetworkSupport() {
|
||||||
|
return networkConnection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
import pp.mdga.client.acoustic.MdgaSound;
|
import pp.mdga.client.acoustic.MdgaSound;
|
||||||
|
import pp.mdga.client.server.MdgaServer;
|
||||||
import pp.mdga.client.view.CeremonyView;
|
import pp.mdga.client.view.CeremonyView;
|
||||||
import pp.mdga.client.view.GameView;
|
import pp.mdga.client.view.GameView;
|
||||||
import pp.mdga.client.view.LobbyView;
|
import pp.mdga.client.view.LobbyView;
|
||||||
@@ -31,7 +32,7 @@ public class ModelSynchronizer {
|
|||||||
private int test = 0;
|
private int test = 0;
|
||||||
|
|
||||||
public void animationEnd() {
|
public void animationEnd() {
|
||||||
|
app.getGameLogic().selectAnimationEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectSwap(UUID a, UUID b) {
|
public void selectSwap(UUID a, UUID b) {
|
||||||
@@ -82,13 +83,14 @@ public void confirm() {
|
|||||||
GameView gameView = (GameView) app.getView();
|
GameView gameView = (GameView) app.getView();
|
||||||
|
|
||||||
if(a != null && b != null) {
|
if(a != null && b != null) {
|
||||||
//swap
|
selectPiece(a);
|
||||||
|
selectPiece(b);
|
||||||
gameView.getBoardHandler().clearSelectable();
|
gameView.getBoardHandler().clearSelectable();
|
||||||
} else if (a != null) {
|
} else if (a != null) {
|
||||||
//piece
|
selectPiece(a);
|
||||||
gameView.getBoardHandler().clearSelectable();
|
gameView.getBoardHandler().clearSelectable();
|
||||||
} else if (card != null){
|
} else if (card != null){
|
||||||
//card
|
selectCard(card);
|
||||||
gameView.getGuiHandler().clearSelectableCards();
|
gameView.getGuiHandler().clearSelectableCards();
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("nothing to confirm");
|
throw new RuntimeException("nothing to confirm");
|
||||||
@@ -98,50 +100,33 @@ public void confirm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void selectTsk(Color color) {
|
public void selectTsk(Color color) {
|
||||||
// TODO call from somewhere
|
app.getGameLogic().selectTsk(color);
|
||||||
LOGGER.log(Level.INFO, "selectTsk: {0}", color);
|
|
||||||
LobbyView view = (LobbyView) app.getView();
|
|
||||||
view.setTaken(color, true, true, "OwnPlayerName");
|
|
||||||
testColor = color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unselectTsk() {
|
public void unselectTsk() {
|
||||||
// TODO call from somewhere
|
app.getGameLogic().selectTsk(Color.NONE);
|
||||||
LOGGER.log(Level.INFO, "unselectTsk");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rolledDice() {
|
public void rolledDice() {
|
||||||
// TODO call from somewhere
|
app.getGameLogic().selectDice();
|
||||||
LOGGER.log(Level.INFO, "rolledDice");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
// TODO call from somewhere
|
// TODO call from somewhere
|
||||||
LOGGER.log(Level.INFO, "setName: {0}", name);
|
LOGGER.log(Level.INFO, "setName: {0}", name);
|
||||||
|
app.getGameLogic().selectName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReady(boolean ready) {
|
public void setReady(boolean ready) {
|
||||||
LOGGER.log(Level.INFO, "setReady");
|
app.getGameLogic().selectReady(ready);
|
||||||
LobbyView view = (LobbyView) app.getView();
|
|
||||||
view.setReady(testColor, ready);
|
|
||||||
test++;
|
|
||||||
|
|
||||||
if(test > 2) {
|
|
||||||
test = 0;
|
|
||||||
enter(MdgaState.GAME);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(int port) {
|
public void setHost(int port) {
|
||||||
// TODO call from somewhere
|
app.getGameLogic().selectJoin("");
|
||||||
LOGGER.log(Level.INFO, "setHost: {0}", port);
|
|
||||||
enter(MdgaState.LOBBY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJoin(String ip, int port) {
|
public void setJoin(String ip, int port) {
|
||||||
// TODO call from somewhere
|
app.getGameLogic().selectJoin(ip);
|
||||||
LOGGER.log(Level.INFO, "setJoin with IP: {0}, Port: {1}", new Object[]{ip, port});
|
|
||||||
enter(MdgaState.LOBBY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leave() {
|
public void leave() {
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package pp.mdga.client;
|
||||||
|
|
||||||
|
import com.jme3.network.*;
|
||||||
|
import pp.mdga.message.client.ClientMessage;
|
||||||
|
import pp.mdga.message.server.ServerMessage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class NetworkSupport implements MessageListener<Client>, ClientStateListener, ServerConnection {
|
||||||
|
private static final System.Logger LOGGER = System.getLogger(NetworkSupport.class.getName());
|
||||||
|
private final MdgaApp app;
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
public NetworkSupport(MdgaApp app) {
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MdgaApp getApp() {
|
||||||
|
return this.app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return this.client != null && this.client.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connect() {
|
||||||
|
if (this.client != null) {
|
||||||
|
throw new IllegalStateException("trying to join a game again");
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
this.initNetwork("localhost", 2345);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.log(System.Logger.Level.ERROR, "could not connect to server", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
if (this.client != null) {
|
||||||
|
this.client.close();
|
||||||
|
this.client = null;
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "client closed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initNetwork(String host, int port) throws IOException {
|
||||||
|
if (this.client != null) {
|
||||||
|
throw new IllegalStateException("trying to join a game again");
|
||||||
|
} else {
|
||||||
|
this.client = Network.connectToServer(host, port);
|
||||||
|
this.client.start();
|
||||||
|
this.client.addMessageListener(this);
|
||||||
|
this.client.addClientStateListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void messageReceived(Client client, Message message) {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "message received from server: {0}", new Object[]{message});
|
||||||
|
if (message instanceof ServerMessage serverMessage) {
|
||||||
|
this.app.enqueue(() -> serverMessage.accept(this.app.getGameLogic()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clientConnected(Client client) {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Client connected: {0}", new Object[]{client});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clientDisconnected(Client client, ClientStateListener.DisconnectInfo disconnectInfo) {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Client {0} disconnected: {1}", new Object[]{client, disconnectInfo});
|
||||||
|
if (this.client != client) {
|
||||||
|
throw new IllegalArgumentException("parameter value must be client");
|
||||||
|
} else {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "client still connected: {0}", new Object[]{client.isConnected()});
|
||||||
|
this.client = null;
|
||||||
|
this.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(ClientMessage message) {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "sending {0}", new Object[]{message});
|
||||||
|
if (this.client == null) {
|
||||||
|
LOGGER.log(System.Logger.Level.WARNING, "client not connected");
|
||||||
|
} else {
|
||||||
|
this.client.send(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,8 +24,8 @@ public void addTestNotification(Notification n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
//TODO fetch model notifications
|
Notification n = app.getGameLogic().getNotification();
|
||||||
for (Notification n : notifications) {
|
if(n != null) {
|
||||||
switch (app.getState()) {
|
switch (app.getState()) {
|
||||||
case MAIN:
|
case MAIN:
|
||||||
handleMain(n);
|
handleMain(n);
|
||||||
@@ -43,14 +43,13 @@ public void update() {
|
|||||||
throw new RuntimeException("no notification expected: " + n.toString());
|
throw new RuntimeException("no notification expected: " + n.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifications.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMain(Notification notification) {
|
private void handleMain(Notification notification) {
|
||||||
if (notification instanceof LobbyDialogNotification) {
|
if (notification instanceof LobbyDialogNotification) {
|
||||||
app.enter(MdgaState.LOBBY);
|
app.enter(MdgaState.LOBBY);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("notification not expected: " + notification.toString());
|
throw new RuntimeException("notification not expected: ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +61,8 @@ private void handleLobby(Notification notification) {
|
|||||||
lobbyView.setTaken(n.getColor(), true, false, n.getName());
|
lobbyView.setTaken(n.getColor(), true, false, n.getName());
|
||||||
} else if (notification instanceof TskUnselectNotification n) {
|
} else if (notification instanceof TskUnselectNotification n) {
|
||||||
lobbyView.setTaken(n.getColor(), false, false, null);
|
lobbyView.setTaken(n.getColor(), false, false, null);
|
||||||
//} else if(notification instanceof LobbyReadyNotification lobbyReadyNotification) {
|
} else if(notification instanceof LobbyReadyNotification lobbyReadyNotification) {
|
||||||
//lobbyView.setReady(lobbyReadyNotification.getColor(), lobbyReadyNotification.isReady()):
|
lobbyView.setReady(lobbyReadyNotification.getColor(), lobbyReadyNotification.isReady());
|
||||||
} else if (notification instanceof GameNotification) {
|
} else if (notification instanceof GameNotification) {
|
||||||
app.enter(MdgaState.GAME);
|
app.enter(MdgaState.GAME);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -317,7 +317,6 @@ public void setTaken(Taken taken, String name) {
|
|||||||
} else {
|
} else {
|
||||||
label.setText(name);
|
label.setText(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnHover();
|
onUnHover();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import pp.mdga.client.MdgaApp;
|
import pp.mdga.client.MdgaApp;
|
||||||
|
import pp.mdga.client.NetworkSupport;
|
||||||
import pp.mdga.client.button.ButtonLeft;
|
import pp.mdga.client.button.ButtonLeft;
|
||||||
import pp.mdga.client.button.ButtonRight;
|
import pp.mdga.client.button.ButtonRight;
|
||||||
import pp.mdga.client.button.InputButton;
|
import pp.mdga.client.button.InputButton;
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
|
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
public class HostDialog extends Dialog {
|
public class HostDialog extends NetworkDialog {
|
||||||
private InputButton portInput;
|
private InputButton portInput;
|
||||||
|
|
||||||
private ButtonRight hostButton;
|
private ButtonRight hostButton;
|
||||||
@@ -22,7 +23,7 @@ public class HostDialog extends Dialog {
|
|||||||
private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
|
private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
|
||||||
|
|
||||||
public HostDialog(MdgaApp app, Node node, MainView view) {
|
public HostDialog(MdgaApp app, Node node, MainView view) {
|
||||||
super(app, node);
|
super(app, node, (NetworkSupport) app.getNetworkSupport());
|
||||||
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ public void update() {
|
|||||||
|
|
||||||
public String getPort() {
|
public String getPort() {
|
||||||
prefs.put("hostPort", portInput.getString());
|
prefs.put("hostPort", portInput.getString());
|
||||||
|
setPortNumber(Integer.parseInt(portInput.getString()));
|
||||||
return portInput.getString();
|
return portInput.getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,4 +67,13 @@ public void resetPort() {
|
|||||||
portInput.reset();
|
portInput.reset();
|
||||||
prefs.put("hostPort", "11111");
|
prefs.put("hostPort", "11111");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hostServer() {
|
||||||
|
startServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connectServerAsClient() {
|
||||||
|
connectServer();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import pp.mdga.client.MdgaApp;
|
import pp.mdga.client.MdgaApp;
|
||||||
|
import pp.mdga.client.NetworkSupport;
|
||||||
import pp.mdga.client.acoustic.AcousticHandler;
|
import pp.mdga.client.acoustic.AcousticHandler;
|
||||||
import pp.mdga.client.button.ButtonLeft;
|
import pp.mdga.client.button.ButtonLeft;
|
||||||
import pp.mdga.client.button.ButtonRight;
|
import pp.mdga.client.button.ButtonRight;
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
|
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
public class JoinDialog extends Dialog {
|
public class JoinDialog extends NetworkDialog {
|
||||||
private InputButton ipInput;
|
private InputButton ipInput;
|
||||||
private InputButton portInput;
|
private InputButton portInput;
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ public class JoinDialog extends Dialog {
|
|||||||
private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
|
private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class);
|
||||||
|
|
||||||
public JoinDialog(MdgaApp app, Node node, MainView view) {
|
public JoinDialog(MdgaApp app, Node node, MainView view) {
|
||||||
super(app, node);
|
super(app, node, (NetworkSupport) app.getNetworkSupport());
|
||||||
|
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ public void update() {
|
|||||||
|
|
||||||
public String getIpt() {
|
public String getIpt() {
|
||||||
prefs.put("joinIp", ipInput.getString());
|
prefs.put("joinIp", ipInput.getString());
|
||||||
|
setHostname(ipInput.getString());
|
||||||
return ipInput.getString();
|
return ipInput.getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +80,7 @@ public void resetIp() {
|
|||||||
|
|
||||||
public String getPort() {
|
public String getPort() {
|
||||||
prefs.put("joinPort", portInput.getString());
|
prefs.put("joinPort", portInput.getString());
|
||||||
|
setPortNumber(Integer.parseInt(portInput.getString()));
|
||||||
return portInput.getString();
|
return portInput.getString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,4 +88,8 @@ public void resetPort() {
|
|||||||
portInput.reset();
|
portInput.reset();
|
||||||
prefs.put("joinPort", "11111");
|
prefs.put("joinPort", "11111");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void connectToServer() {
|
||||||
|
connectServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package pp.mdga.client.dialog;
|
||||||
|
|
||||||
|
import com.jme3.scene.Node;
|
||||||
|
import pp.mdga.client.MdgaApp;
|
||||||
|
import pp.mdga.client.NetworkSupport;
|
||||||
|
import pp.mdga.client.server.MdgaServer;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
public abstract class NetworkDialog extends Dialog {
|
||||||
|
|
||||||
|
private NetworkSupport network;
|
||||||
|
private String hostname;
|
||||||
|
private int portNumber;
|
||||||
|
private Future<Object> connectionFuture;
|
||||||
|
|
||||||
|
public NetworkDialog(MdgaApp app, Node node, NetworkSupport network) {
|
||||||
|
super(app, node);
|
||||||
|
this.network = network;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostname(String hostname) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPortNumber(int portNumber) {
|
||||||
|
this.portNumber = portNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Object initNetwork() {
|
||||||
|
try {
|
||||||
|
this.network.initNetwork(this.hostname, this.portNumber);
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void connectServer() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
connectionFuture = this.network.getApp().getExecutor().submit(this::initNetwork);
|
||||||
|
} catch (NumberFormatException var2) {
|
||||||
|
throw new NumberFormatException("Port must be a number");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startServer() {
|
||||||
|
(new Thread(() -> {
|
||||||
|
try {
|
||||||
|
MdgaServer mdgaServer = new MdgaServer(portNumber);
|
||||||
|
mdgaServer.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
})).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(float delta) {
|
||||||
|
if (this.connectionFuture != null && this.connectionFuture.isDone()) {
|
||||||
|
try {
|
||||||
|
this.connectionFuture.get();
|
||||||
|
} catch (ExecutionException ignored) {
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
import com.jme3.network.serializing.Serializer;
|
import com.jme3.network.serializing.Serializer;
|
||||||
import pp.mdga.game.Game;
|
import pp.mdga.game.Game;
|
||||||
import pp.mdga.game.Player;
|
import pp.mdga.game.Player;
|
||||||
|
import pp.mdga.game.Statistic;
|
||||||
import pp.mdga.message.client.*;
|
import pp.mdga.message.client.*;
|
||||||
import pp.mdga.message.server.*;
|
import pp.mdga.message.server.*;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
@@ -13,8 +14,8 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.System.Logger;
|
import java.lang.System.Logger;
|
||||||
import java.lang.System.Logger.Level;
|
import java.lang.System.Logger.Level;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.logging.LogManager;
|
import java.util.logging.LogManager;
|
||||||
@@ -51,7 +52,6 @@ public MdgaServer(int port) {
|
|||||||
LOGGER.log(Level.INFO, "Creating MdgaServer"); //NON-NLS
|
LOGGER.log(Level.INFO, "Creating MdgaServer"); //NON-NLS
|
||||||
logic = new ServerGameLogic(this, new Game());
|
logic = new ServerGameLogic(this, new Game());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +89,7 @@ private void processNextMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeSerializables() {
|
private void initializeSerializables() {
|
||||||
|
Serializer.registerClass(UUID.class, new UUIDSerializer());
|
||||||
Serializer.registerClass(AnimationEndMessage.class);
|
Serializer.registerClass(AnimationEndMessage.class);
|
||||||
Serializer.registerClass(ClientStartGameMessage.class);
|
Serializer.registerClass(ClientStartGameMessage.class);
|
||||||
Serializer.registerClass(DeselectTSKMessage.class);
|
Serializer.registerClass(DeselectTSKMessage.class);
|
||||||
@@ -106,7 +107,6 @@ private void initializeSerializables() {
|
|||||||
Serializer.registerClass(SelectCardMessage.class);
|
Serializer.registerClass(SelectCardMessage.class);
|
||||||
Serializer.registerClass(SelectedPiecesMessage.class);
|
Serializer.registerClass(SelectedPiecesMessage.class);
|
||||||
Serializer.registerClass(SelectTSKMessage.class);
|
Serializer.registerClass(SelectTSKMessage.class);
|
||||||
|
|
||||||
Serializer.registerClass(ActivePlayerMessage.class);
|
Serializer.registerClass(ActivePlayerMessage.class);
|
||||||
Serializer.registerClass(AnyPieceMessage.class);
|
Serializer.registerClass(AnyPieceMessage.class);
|
||||||
Serializer.registerClass(BriefingMessage.class);
|
Serializer.registerClass(BriefingMessage.class);
|
||||||
@@ -134,12 +134,15 @@ private void initializeSerializables() {
|
|||||||
Serializer.registerClass(UpdateReadyMessage.class);
|
Serializer.registerClass(UpdateReadyMessage.class);
|
||||||
Serializer.registerClass(UpdateTSKMessage.class);
|
Serializer.registerClass(UpdateTSKMessage.class);
|
||||||
Serializer.registerClass(WaitPieceMessage.class);
|
Serializer.registerClass(WaitPieceMessage.class);
|
||||||
|
Serializer.registerClass(Player.class);
|
||||||
|
Serializer.registerClass(Statistic.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
myServer.addMessageListener(this, AnimationEndMessage.class);
|
myServer.addMessageListener(this, AnimationEndMessage.class);
|
||||||
myServer.addMessageListener(this, ClientStartGameMessage.class);
|
myServer.addMessageListener(this, ClientStartGameMessage.class);
|
||||||
myServer.addMessageListener(this, DeselectTSKMessage.class);
|
myServer.addMessageListener(this, DeselectTSKMessage.class);
|
||||||
|
myServer.addMessageListener(this, DisconnectedMessage.class);
|
||||||
myServer.addMessageListener(this, ForceContinueGameMessage.class);
|
myServer.addMessageListener(this, ForceContinueGameMessage.class);
|
||||||
myServer.addMessageListener(this, StartGameMessage.class);
|
myServer.addMessageListener(this, StartGameMessage.class);
|
||||||
myServer.addMessageListener(this, JoinedLobbyMessage.class);
|
myServer.addMessageListener(this, JoinedLobbyMessage.class);
|
||||||
@@ -187,7 +190,7 @@ private void messageReceived(HostedConnection source, ClientMessage message) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.DEBUG, "new connection {0}", hostedConnection); //NON-NLS
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package pp.mdga.client.server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializer;
|
||||||
|
|
||||||
|
public class UUIDSerializer extends Serializer
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException
|
||||||
|
{
|
||||||
|
byte[] uuid = new byte[36];
|
||||||
|
data.get(uuid);
|
||||||
|
|
||||||
|
return (T) UUID.fromString(new String(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeObject(ByteBuffer buffer, Object object) throws IOException
|
||||||
|
{
|
||||||
|
UUID uuid = (UUID) object;
|
||||||
|
buffer.put(uuid.toString().getBytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
import pp.mdga.client.dialog.JoinDialog;
|
import pp.mdga.client.dialog.JoinDialog;
|
||||||
import pp.mdga.client.dialog.StartDialog;
|
import pp.mdga.client.dialog.StartDialog;
|
||||||
|
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class MainView extends MdgaView {
|
public class MainView extends MdgaView {
|
||||||
private enum SubState {
|
private enum SubState {
|
||||||
HOST,
|
HOST,
|
||||||
@@ -99,12 +102,25 @@ private void tryHost() {
|
|||||||
|
|
||||||
if(port >= 1 && port <= 65535) {
|
if(port >= 1 && port <= 65535) {
|
||||||
app.getModelSynchronize().setName(startDialog.getName());
|
app.getModelSynchronize().setName(startDialog.getName());
|
||||||
|
hostDialog.setHostname(Inet4Address.getLocalHost().getHostAddress());
|
||||||
|
hostDialog.hostServer();
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
hostDialog.connectServerAsClient();
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
app.getModelSynchronize().setHost(port);
|
app.getModelSynchronize().setHost(port);
|
||||||
//app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT);
|
//app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
//nothing
|
//nothing
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
hostDialog.resetPort();
|
hostDialog.resetPort();
|
||||||
@@ -127,6 +143,7 @@ private void tryJoin() {
|
|||||||
if (isValidIpAddress(ip)) {
|
if (isValidIpAddress(ip)) {
|
||||||
app.getModelSynchronize().setName(startDialog.getName());
|
app.getModelSynchronize().setName(startDialog.getName());
|
||||||
app.getModelSynchronize().setJoin(ip, port);
|
app.getModelSynchronize().setJoin(ip, port);
|
||||||
|
joinDialog.connectToServer();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ public class ClientGameLogic implements ServerInterpreter {
|
|||||||
private final InterruptState interruptState = new InterruptState(null, this);
|
private final InterruptState interruptState = new InterruptState(null, this);
|
||||||
private final SettingsState settingsState = new SettingsState(null, this);
|
private final SettingsState settingsState = new SettingsState(null, this);
|
||||||
|
|
||||||
public ClientGameLogic(Game game, ClientSender clientSender) {
|
public ClientGameLogic(ClientSender clientSender) {
|
||||||
this.game = game;
|
this.game = new Game();
|
||||||
this.clientSender = clientSender;
|
this.clientSender = clientSender;
|
||||||
|
dialogsState.enter();
|
||||||
state = dialogsState;
|
state = dialogsState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +245,11 @@ public void selectName(String name){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void selectReady(boolean ready){
|
public void selectReady(boolean ready){
|
||||||
state.selectReady(ready);
|
if(ready){
|
||||||
|
state.selectReady();
|
||||||
|
} else {
|
||||||
|
state.selectUnready();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectHost(String name){
|
public void selectHost(String name){
|
||||||
@@ -304,7 +309,11 @@ public SettingsState getSettings(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Notification getNotification(){
|
public Notification getNotification(){
|
||||||
|
if(!notifications.isEmpty()){
|
||||||
return notifications.remove(0);
|
return notifications.remove(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNotification(Notification notification){
|
public void addNotification(Notification notification){
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ public void setName(String name) {
|
|||||||
LOGGER.log(Level.DEBUG, "Setting name not allowed.");
|
LOGGER.log(Level.DEBUG, "Setting name not allowed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectReady(boolean ready) {
|
public void selectReady() {
|
||||||
LOGGER.log(Level.DEBUG, "Selecting ready not allowed.");
|
LOGGER.log(Level.DEBUG, "Selecting ready not allowed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public void enter(){
|
|||||||
|
|
||||||
public void setState(DialogStates newState){
|
public void setState(DialogStates newState){
|
||||||
currentState.exit();
|
currentState.exit();
|
||||||
currentState.enter();
|
newState.enter();
|
||||||
currentState = newState;
|
currentState = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +75,11 @@ public void selectLeave(){
|
|||||||
currentState.selectLeave();
|
currentState.selectLeave();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name){
|
||||||
|
currentState.setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectTSK(Color color){
|
public void selectTSK(Color color){
|
||||||
currentState.selectTSK(color);
|
currentState.selectTSK(color);
|
||||||
@@ -86,8 +91,8 @@ public void deselectTSK(Color color){
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectReady(boolean ready){
|
public void selectReady(){
|
||||||
currentState.selectReady(ready);
|
currentState.selectReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package pp.mdga.client;
|
||||||
|
|
||||||
|
public interface ServerConnection extends ClientSender {
|
||||||
|
boolean isConnected();
|
||||||
|
|
||||||
|
void connect();
|
||||||
|
|
||||||
|
void disconnect();
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
import pp.mdga.message.server.ServerStartGameMessage;
|
import pp.mdga.message.server.ServerStartGameMessage;
|
||||||
import pp.mdga.message.server.UpdateReadyMessage;
|
import pp.mdga.message.server.UpdateReadyMessage;
|
||||||
import pp.mdga.message.server.UpdateTSKMessage;
|
import pp.mdga.message.server.UpdateTSKMessage;
|
||||||
|
import pp.mdga.notification.LobbyReadyNotification;
|
||||||
import pp.mdga.notification.TskSelectNotification;
|
import pp.mdga.notification.TskSelectNotification;
|
||||||
import pp.mdga.notification.TskUnselectNotification;
|
import pp.mdga.notification.TskUnselectNotification;
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ public void deselectTSK(Color color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectReady(boolean ready) {
|
public void selectReady() {
|
||||||
logic.send(new LobbyReadyMessage());
|
logic.send(new LobbyReadyMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ public void received(ServerStartGameMessage msg){
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(LobbyPlayerJoinedMessage msg){
|
public void received(LobbyPlayerJoinedMessage msg){
|
||||||
|
logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||||
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +96,7 @@ public void received(LobbyPlayerLeaveMessage msg){
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(UpdateReadyMessage msg){
|
public void received(UpdateReadyMessage msg){
|
||||||
|
logic.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady()));
|
||||||
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
|
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import pp.mdga.client.ClientGameLogic;
|
import pp.mdga.client.ClientGameLogic;
|
||||||
import pp.mdga.client.ClientState;
|
import pp.mdga.client.ClientState;
|
||||||
import pp.mdga.client.DialogsState;
|
import pp.mdga.client.DialogsState;
|
||||||
|
import pp.mdga.notification.LobbyDialogNotification;
|
||||||
|
|
||||||
public class NetworkDialogState extends DialogStates {
|
public class NetworkDialogState extends DialogStates {
|
||||||
|
|
||||||
@@ -55,9 +56,7 @@ public void selectLeave() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void selectJoin(String IP) {
|
public void selectJoin(String IP) {
|
||||||
if(checkIP(IP)){
|
|
||||||
parent.setState(parent.getLobby());
|
parent.setState(parent.getLobby());
|
||||||
}
|
logic.addNotification(new LobbyDialogNotification());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ public void selectHost(String name) {
|
|||||||
logic.setHost(true);
|
logic.setHost(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
parent.setState(parent.getNetworkDialog());
|
||||||
|
parent.setOwnPlayerName(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectLeave() {
|
public void selectLeave() {
|
||||||
parent.exit();
|
parent.exit();
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package pp.mdga.game;
|
package pp.mdga.game;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be used to handle general PlayerData
|
* This class will be used to handle general PlayerData
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class Player {
|
public class Player {
|
||||||
/**
|
/**
|
||||||
* The name of the player.
|
* The name of the player.
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package pp.mdga.game;
|
package pp.mdga.game;
|
||||||
|
|
||||||
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be used to store Statistics during the Game;
|
* This class will be used to store Statistics during the Game;
|
||||||
*/
|
*/
|
||||||
|
@Serializable
|
||||||
public class Statistic {
|
public class Statistic {
|
||||||
/**
|
/**
|
||||||
* The number of cards played.
|
* The number of cards played.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public StartGameMessage(boolean forceStartGame){
|
|||||||
/**
|
/**
|
||||||
* Constructs a new ForceStartGame message.
|
* Constructs a new ForceStartGame message.
|
||||||
*/
|
*/
|
||||||
public StartGameMessage() {
|
private StartGameMessage() {
|
||||||
super();
|
super();
|
||||||
forceStartGame = false;
|
forceStartGame = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package pp.mdga.notification;
|
||||||
|
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
|
||||||
|
public class LobbyReadyNotification extends Notification{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color of the player.
|
||||||
|
*/
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the player is ready.
|
||||||
|
*/
|
||||||
|
private boolean ready;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public LobbyReadyNotification(Color color, boolean ready) {
|
||||||
|
this.color = color;
|
||||||
|
this.ready = ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to get the color of the player
|
||||||
|
*
|
||||||
|
* @return the color of the player
|
||||||
|
*/
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to get the ready state of the player
|
||||||
|
*
|
||||||
|
* @return the ready state of the player
|
||||||
|
*/
|
||||||
|
public boolean isReady() {
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user