mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Terminated the game server socket when click exit lobby button
- the whole server thread should be terminated instead. To be fixed in the future. #story[1047] #issue[28]
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.gameServer.GameServerThread;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
|
||||
@@ -32,6 +33,7 @@ public class LobbyController {
|
||||
@FXML
|
||||
private TableColumn readyTableColumn;
|
||||
|
||||
private GameServerThread gameServerThread;
|
||||
|
||||
private void setContentPane(String jfxUrl) {
|
||||
try {
|
||||
@@ -54,7 +56,8 @@ public class LobbyController {
|
||||
// TODO: 10/07/17 wmu16 - Finish function!
|
||||
setContentPane("/views/StartScreenView.fxml");
|
||||
System.out.println("Leaving lobby!");
|
||||
|
||||
GameState.setCurrentStage(GameStages.CANCELLED);
|
||||
gameServerThread.terminateGame();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,4 +65,8 @@ public class LobbyController {
|
||||
public void readyButtonPressed() {
|
||||
GameState.setCurrentStage(GameStages.RACING);
|
||||
}
|
||||
|
||||
protected void setGameServerThread(GameServerThread gameServerThread) {
|
||||
this.gameServerThread = gameServerThread;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package seng302.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
@@ -25,20 +26,27 @@ public class StartScreenController {
|
||||
@FXML
|
||||
private GridPane startScreen2;
|
||||
|
||||
|
||||
private void setContentPane(String jfxUrl) {
|
||||
/**
|
||||
* Loads the fxml content into the parent pane
|
||||
* @param jfxUrl
|
||||
* @return the controller of the fxml
|
||||
*/
|
||||
private Object setContentPane(String jfxUrl) {
|
||||
try {
|
||||
AnchorPane contentPane = (AnchorPane) startScreen2.getParent();
|
||||
contentPane.getChildren().removeAll();
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
contentPane.getChildren()
|
||||
.addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(jfxUrl));
|
||||
contentPane.getChildren().addAll((Pane) fxmlLoader.load());
|
||||
|
||||
return fxmlLoader.getController();
|
||||
} catch (javafx.fxml.LoadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,9 +61,13 @@ public class StartScreenController {
|
||||
try {
|
||||
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
new GameState(ipAddress);
|
||||
new GameServerThread("Game Server");
|
||||
GameServerThread gameServerThread = new GameServerThread("Game Server");
|
||||
System.out.println("Server thread started");
|
||||
setContentPane("/views/LobbyView.fxml");
|
||||
|
||||
// get the lobby controller so that we can pass the game server thread to it
|
||||
LobbyController lobbyController = (LobbyController) setContentPane("/views/LobbyView.fxml");
|
||||
lobbyController.setGameServerThread(gameServerThread);
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
System.err.println("COULD NOT FIND YOUR IP ADDRESS!");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -256,8 +256,9 @@ public class GameServerThread implements Runnable, Observer, ClientConnectionDel
|
||||
}
|
||||
|
||||
acceptConnection();
|
||||
acceptConnection();
|
||||
// acceptConnection();
|
||||
// acceptConnection();
|
||||
System.out.println("well, hit here now");
|
||||
|
||||
for (Player player : GameState.getPlayers()) {
|
||||
System.out.println(player);
|
||||
@@ -399,4 +400,13 @@ public class GameServerThread implements Runnable, Observer, ClientConnectionDel
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
public void terminateGame() {
|
||||
try {
|
||||
//TODO: for now, I just close the socket, but i think we should terminate the whole thread instead. -hyi25 13 July
|
||||
server.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ public enum GameStages {
|
||||
LOBBYING(0),
|
||||
PRE_RACE(1),
|
||||
RACING(2),
|
||||
FINISHED(3);
|
||||
FINISHED(3),
|
||||
CANCELLED(4);
|
||||
|
||||
private long code;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user