Merge remote-tracking branch 'remotes/origin/temp77' into story77

# Conflicts:
#	racevisionGame/src/main/java/visualiser/Controllers/InGameLobbyController.java
#	racevisionGame/src/main/resources/visualiser/scenes/gameLobby.fxml
#	racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml
main
hba56 8 years ago
parent aafc0dc9db
commit 00780e17e9

@ -9,7 +9,11 @@ import javafx.scene.image.ImageView;
import mock.app.Event; import mock.app.Event;
import mock.exceptions.EventConstructionException; import mock.exceptions.EventConstructionException;
import visualiser.app.App; import visualiser.app.App;
import visualiser.app.MatchBrowserSingleton;
import visualiser.network.MatchBrowserInterface;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -24,11 +28,17 @@ public class HostGameController extends Controller {
private @FXML ImageView mapImage; private @FXML ImageView mapImage;
private ArrayList<Image> listOfMaps; private ArrayList<Image> listOfMaps;
private int currentMapIndex = 0; private int currentMapIndex = 0;
private DatagramSocket udpSocket;
private MatchBrowserInterface matchBrowserInterface;
public void initialize() { public void initialize() {
loadMaps(); loadMaps();
this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket();
this.matchBrowserInterface = MatchBrowserSingleton.getInstance().getMatchBrowserInterface();
} }
/** /**
* Loads in the list of playable maps to be selected from. * Loads in the list of playable maps to be selected from.
*/ */
@ -55,6 +65,8 @@ public class HostGameController extends Controller {
App.game = new Event(false, currentMapIndex); App.game = new Event(false, currentMapIndex);
App.gameType = currentMapIndex; App.gameType = currentMapIndex;
connectSocket("localhost", 4942); connectSocket("localhost", 4942);
alertMatchBrowser();
} catch (EventConstructionException e) { } catch (EventConstructionException e) {
Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e); Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e);
throw new RuntimeException(e); throw new RuntimeException(e);
@ -63,6 +75,17 @@ public class HostGameController extends Controller {
} }
} }
/**
* Sends info to the match browser so clients can see it
*/
public void alertMatchBrowser(){
try{
matchBrowserInterface.startSendingHostData(App.game.getHostedGameData(), udpSocket);
}catch (IOException e){
System.err.println("failed to send out hosted game info");
}
}
/** /**
* Connect to a socket * Connect to a socket
* @param address address of the server * @param address address of the server

@ -9,6 +9,7 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import network.Messages.HostGame; import network.Messages.HostGame;
import visualiser.app.MatchBrowserSingleton;
import visualiser.model.RaceConnection; import visualiser.model.RaceConnection;
import visualiser.network.MatchBrowserClientRunnable; import visualiser.network.MatchBrowserClientRunnable;
import visualiser.network.MatchBrowserInterface; import visualiser.network.MatchBrowserInterface;
@ -40,9 +41,9 @@ public class LobbyController extends Controller {
//the socket for match browser //the socket for match browser
private DatagramSocket udpSocket; private DatagramSocket udpSocket;
private MatchBrowserLobbyInterface matchBrowserLobbyInterface; private MatchBrowserLobbyInterface matchBrowserLobbyInterface;
public void initialize() { public void initialize() {
// set up the connection table // set up the connection table
connections = FXCollections.observableArrayList(); connections = FXCollections.observableArrayList();
@ -62,6 +63,9 @@ public class LobbyController extends Controller {
} }
}); });
joinGameBtn.setDisable(true); joinGameBtn.setDisable(true);
this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket();
receiveMatchData();
} }
/** /**
@ -113,8 +117,7 @@ public class LobbyController extends Controller {
} }
} }
public void setupSocket(DatagramSocket udpSocket){ public void receiveMatchData(){
this.udpSocket = udpSocket;
matchBrowserLobbyInterface = new MatchBrowserLobbyInterface(); matchBrowserLobbyInterface = new MatchBrowserLobbyInterface();
try { try {
matchBrowserLobbyInterface.startReceivingHostData(new DatagramSocket(4941)); matchBrowserLobbyInterface.startReceivingHostData(new DatagramSocket(4941));

@ -11,6 +11,8 @@ import mock.exceptions.EventConstructionException;
import visualiser.app.App; import visualiser.app.App;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket;
/** /**
* Controller for the opening title window. * Controller for the opening title window.

@ -26,6 +26,7 @@ import javafx.stage.StageStyle;
import javafx.util.Duration; import javafx.util.Duration;
import mock.app.Event; import mock.app.Event;
public class App extends Application { public class App extends Application {
private static Stage stage; private static Stage stage;
public static Event game; public static Event game;

@ -1,7 +1,37 @@
package visualiser.app; package visualiser.app;
/** import visualiser.network.MatchBrowserInterface;
* Created by hba56 on 13/09/17.
*/ import java.io.IOException;
import java.net.DatagramSocket;
public class MatchBrowserSingleton { public class MatchBrowserSingleton {
private DatagramSocket udpSocket;
private MatchBrowserInterface matchBrowserInterface;
private static MatchBrowserSingleton instance = null;
public MatchBrowserSingleton() {
this.matchBrowserInterface = new MatchBrowserInterface();
try{
this.udpSocket = matchBrowserInterface.setupMatchBrowserConnection();
}catch (IOException e){
System.err.println("Error in setting up connection with match browser");
}
}
public static MatchBrowserSingleton getInstance() {
if (instance == null){
instance = new MatchBrowserSingleton();
}
return instance;
}
public DatagramSocket getUdpSocket() {
return udpSocket;
}
public MatchBrowserInterface getMatchBrowserInterface() {
return matchBrowserInterface;
}
} }

@ -29,7 +29,7 @@ public class MatchBrowserInterface {
public MatchBrowserInterface() { public MatchBrowserInterface() {
//TODO change to ip of cloud server hosting this //TODO change to ip of cloud server hosting this
try { try {
this.IPAddress = InetAddress.getByName("132.181.13.223"); this.IPAddress = InetAddress.getLocalHost();//InetAddress.getByName("132.181.13.223");
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save